FileDocCategorySizeDatePackage
ElementCreateCommand.javaAPI DocAndroid 1.5 API3647Wed May 06 22:41:10 BST 2009com.android.ide.eclipse.editors.layout.parts

ElementCreateCommand

public class ElementCreateCommand extends org.eclipse.gef.commands.Command
A command that knows how to instantiate a new element based on a given {@link ElementDescriptor}, the parent {@link UiElementEditPart} and an optional target location.

Fields Summary
private final com.android.ide.eclipse.editors.descriptors.ElementDescriptor
mDescriptor
Descriptor of the new element to create
private final UiElementEditPart
mParentPart
The edit part that hosts the new edit part
private final org.eclipse.draw2d.geometry.Point
mTargetPoint
The drop location in parent coordinates
Constructors Summary
public ElementCreateCommand(com.android.ide.eclipse.editors.descriptors.ElementDescriptor descriptor, UiElementEditPart targetPart, org.eclipse.draw2d.geometry.Point targetPoint)
Creates a new {@link ElementCreateCommand}.

param
descriptor Descriptor of the new element to create
param
targetPart The edit part that hosts the new edit part
param
targetPoint The drop location in parent coordinates

                mDescriptor = descriptor;
                mParentPart = targetPart;
                mTargetPoint = targetPoint;
    
Methods Summary
public booleancanExecute()

        return mDescriptor != null &&
            mParentPart != null &&
            mParentPart.getUiNode() != null &&
            mParentPart.getUiNode().getEditor() instanceof LayoutEditor;
    
public voidexecute()

        super.execute();
        UiElementNode uiParent = mParentPart.getUiNode();
        if (uiParent != null) {
            final AndroidEditor editor = uiParent.getEditor();
            if (editor instanceof LayoutEditor) {
                ((LayoutEditor) editor).wrapUndoRecording(
                        String.format("Create %1$s", mDescriptor.getXmlLocalName()),
                        new Runnable() {
                    public void run() {
                        UiEditorActions actions = ((LayoutEditor) editor).getUiEditorActions();
                        if (actions != null) {
                            DropFeedback.addElementToXml(mParentPart, mDescriptor, mTargetPoint,
                                    actions);
                        }
                    }
                });
            }
        }        
    
public voidredo()

        throw new UnsupportedOperationException("redo not supported by this command"); //$NON-NLS-1$
    
public voidundo()

        throw new UnsupportedOperationException("undo not supported by this command"); //$NON-NLS-1$