Search in sources :

Example 16 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.

the class DuplicateCommandHandler method createCommands.

private void createCommands() {
    for (Object object : fElementsToDuplicate) {
        CompoundCommand compoundCommand = getCompoundCommand((IAdapter) object);
        if (compoundCommand == null) {
            // sanity check
            // $NON-NLS-1$
            System.err.println("Could not get CompoundCommand in " + getClass());
            continue;
        }
        if (object instanceof IDiagramModel) {
            Command cmd = new DuplicateDiagramModelCommand((IDiagramModel) object);
            compoundCommand.add(cmd);
        } else if (object instanceof IArchimateElement) {
            Command cmd = new DuplicateElementCommand((IArchimateElement) object);
            compoundCommand.add(cmd);
        }
    }
}
Also used : IDiagramModel(com.archimatetool.model.IDiagramModel) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) Command(org.eclipse.gef.commands.Command) IArchimateElement(com.archimatetool.model.IArchimateElement) EObject(org.eclipse.emf.ecore.EObject) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand)

Example 17 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.

the class RenameCommandHandler method doRenameCommands.

/**
 * Rename elements to matching newNames by issuing a CompundCommand(s) on the CommandStack(s)
 * @param elements
 * @param newNames
 */
public static void doRenameCommands(List<INameable> elements, List<String> newNames) {
    // Must match sizes
    if (elements.size() != newNames.size() || elements.isEmpty()) {
        return;
    }
    /*
         * If renaming elements from more than one model in the tree we need to use the
         * Command Stack allocated to each model. And then allocate one CompoundCommand per Command Stack.
         */
    Hashtable<CommandStack, CompoundCommand> commandMap = new Hashtable<CommandStack, CompoundCommand>();
    for (int i = 0; i < elements.size(); i++) {
        INameable element = elements.get(i);
        String newName = newNames.get(i);
        CompoundCommand compoundCommand = getCompoundCommand((IAdapter) element, commandMap);
        if (compoundCommand != null) {
            Command cmd = new // $NON-NLS-1$
            EObjectFeatureCommand(// $NON-NLS-1$
            Messages.RenameCommandHandler_0 + " " + element.getName(), // $NON-NLS-1$
            element, IArchimatePackage.Literals.NAMEABLE__NAME, newName);
            compoundCommand.add(cmd);
        } else {
            // $NON-NLS-1$
            System.err.println("Could not get CompoundCommand in doRenameCommands");
        }
    }
    // Execute the Commands on the CommandStack(s) - there could be more than one if more than one model open in the Tree
    for (Entry<CommandStack, CompoundCommand> entry : commandMap.entrySet()) {
        entry.getKey().execute(entry.getValue().unwrap());
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) Command(org.eclipse.gef.commands.Command) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) Hashtable(java.util.Hashtable) INameable(com.archimatetool.model.INameable) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand)

Example 18 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.

the class HintContentSection method createControls.

@Override
protected void createControls(Composite parent) {
    createLabel(parent, Messages.HintContentSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.CENTER);
    Text text = createSingleTextControl(parent, SWT.NONE);
    fTextTitleControl = new PropertySectionTextControl(text, ICanvasPackage.Literals.HINT_PROVIDER__HINT_TITLE) {

        @Override
        protected void textChanged(String oldText, String newText) {
            CompoundCommand result = new CompoundCommand();
            for (EObject provider : getEObjects()) {
                if (isAlive(provider)) {
                    Command cmd = new EObjectFeatureCommand(Messages.HintContentSection_1, provider, ICanvasPackage.Literals.HINT_PROVIDER__HINT_TITLE, newText);
                    if (cmd.canExecute()) {
                        result.add(cmd);
                    }
                }
            }
            executeCommand(result.unwrap());
        }
    };
    fTextTitleControl.setHint(Messages.HintContentSection_2);
    createLabel(parent, Messages.HintContentSection_3, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.NONE);
    StyledTextControl styledTextControl = createStyledTextControl(parent, SWT.NONE);
    fTextContentControl = new PropertySectionTextControl(styledTextControl.getControl(), ICanvasPackage.Literals.HINT_PROVIDER__HINT_CONTENT) {

        @Override
        protected void textChanged(String oldText, String newText) {
            CompoundCommand result = new CompoundCommand();
            for (EObject provider : getEObjects()) {
                if (isAlive(provider)) {
                    Command cmd = new EObjectFeatureCommand(Messages.HintContentSection_4, provider, ICanvasPackage.Literals.HINT_PROVIDER__HINT_CONTENT, newText);
                    if (cmd.canExecute()) {
                        result.add(cmd);
                    }
                }
            }
            executeCommand(result.unwrap());
        }
    };
    fTextContentControl.setHint(Messages.HintContentSection_5);
    // Help
    PlatformUI.getWorkbench().getHelpSystem().setHelp(fTextContentControl.getTextControl(), HELP_ID);
}
Also used : CompoundCommand(org.eclipse.gef.commands.CompoundCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) Command(org.eclipse.gef.commands.Command) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) StyledTextControl(com.archimatetool.editor.ui.components.StyledTextControl) EObject(org.eclipse.emf.ecore.EObject) Text(org.eclipse.swt.widgets.Text) PropertySectionTextControl(com.archimatetool.editor.propertysections.PropertySectionTextControl) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 19 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.

the class NotesSection method createControls.

@Override
protected void createControls(Composite parent) {
    createLabel(parent, Messages.NotesSection_0, ITabbedLayoutConstants.STANDARD_LABEL_WIDTH, SWT.NONE);
    StyledTextControl styledTextControl = createStyledTextControl(parent, SWT.NONE);
    fTextNotesControl = new PropertySectionTextControl(styledTextControl.getControl(), ICanvasPackage.Literals.NOTES_CONTENT__NOTES) {

        @Override
        protected void textChanged(String oldText, String newText) {
            CompoundCommand result = new CompoundCommand();
            for (EObject notesContent : getEObjects()) {
                if (isAlive(notesContent)) {
                    Command cmd = new EObjectFeatureCommand(Messages.NotesSection_1, notesContent, ICanvasPackage.Literals.NOTES_CONTENT__NOTES, newText);
                    if (cmd.canExecute()) {
                        result.add(cmd);
                    }
                }
            }
            executeCommand(result.unwrap());
        }
    };
    fTextNotesControl.setHint(Messages.NotesSection_2);
    // Help
    PlatformUI.getWorkbench().getHelpSystem().setHelp(fTextNotesControl.getTextControl(), HELP_ID);
}
Also used : StyledTextControl(com.archimatetool.editor.ui.components.StyledTextControl) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) Command(org.eclipse.gef.commands.Command) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) EObject(org.eclipse.emf.ecore.EObject) PropertySectionTextControl(com.archimatetool.editor.propertysections.PropertySectionTextControl) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 20 with CompoundCommand

use of org.eclipse.gef.commands.CompoundCommand in project archi by archimatetool.

the class MagicConnectionCreationTool method createElementAndConnection.

/**
 * Create an Element and a connection in one go when user clicks on the canvas or in a non-Archimate Editpart
 */
private boolean createElementAndConnection(IDiagramModelArchimateComponent sourceDiagramModelComponent, Point location) {
    // Grab this now as it will disappear after menu is shown
    EditPartViewer viewer = getCurrentViewer();
    // What did we click on?
    GraphicalEditPart targetEditPart = (GraphicalEditPart) viewer.findObjectAt(getCurrentInput().getMouseLocation());
    // Target parent (default is the diagram itself)
    IDiagramModelContainer parent = sourceDiagramModelComponent.getDiagramModel();
    // If we clicked on a Group EditPart use that as parent
    if (targetEditPart instanceof GroupEditPart) {
        parent = (IDiagramModelContainer) targetEditPart.getModel();
    } else // Or did we click on something else? Then use the parent of that
    if (targetEditPart instanceof AbstractBaseEditPart) {
        targetEditPart = (GraphicalEditPart) targetEditPart.getParent();
        parent = (IDiagramModelContainer) targetEditPart.getModel();
    }
    boolean elementsFirst = Preferences.isMagicConnectorPolarity();
    boolean modKeyPressed = getCurrentInput().isModKeyDown(SWT.MOD1);
    elementsFirst ^= modKeyPressed;
    Menu menu = new Menu(getCurrentViewer().getControl());
    // User will hover over element, then connection
    if (elementsFirst) {
        fSetRelationshipTypeWhenHoveringOnConnectionMenuItem = false;
        addElementActions(menu, sourceDiagramModelComponent);
    } else // User will hover over connection, then element
    {
        fSetRelationshipTypeWhenHoveringOnConnectionMenuItem = true;
        addConnectionActions(menu, sourceDiagramModelComponent);
    }
    menu.setVisible(true);
    // Modal menu
    Display display = menu.getDisplay();
    while (!menu.isDisposed() && menu.isVisible()) {
        if (!display.readAndDispatch()) {
            display.sleep();
        }
    }
    // SWT Menu does not fire Selection Event when Windows touch display is enabled
    if (PlatformUtils.isWindows()) {
        while (display.readAndDispatch()) ;
    }
    if (!menu.isDisposed()) {
        menu.dispose();
    }
    eraseSourceFeedback();
    // No selection
    if (getFactory().getElementType() == null || getFactory().getRelationshipType() == null) {
        getFactory().clear();
        return false;
    }
    // Create Compound Command first
    CompoundCommand cmd = new CreateElementCompoundCommand((FigureCanvas) viewer.getControl(), location.x, location.y);
    // If the EditPart's Figure is a Container, adjust the location to relative co-ords
    if (targetEditPart.getFigure() instanceof IContainerFigure) {
        ((IContainerFigure) targetEditPart.getFigure()).translateMousePointToRelative(location);
    } else // Or compensate for scrolled parent figure
    {
        IFigure contentPane = targetEditPart.getContentPane();
        contentPane.translateToRelative(location);
    }
    CreateNewDiagramObjectCommand cmd1 = new CreateNewDiagramObjectCommand(parent, getFactory().getElementType(), location);
    Command cmd2 = new CreateNewConnectionCommand(sourceDiagramModelComponent, cmd1.getNewObject(), getFactory().getRelationshipType());
    cmd.add(cmd1);
    cmd.add(cmd2);
    executeCommand(cmd);
    // Clear the factory
    getFactory().clear();
    return true;
}
Also used : AbstractBaseEditPart(com.archimatetool.editor.diagram.editparts.AbstractBaseEditPart) EditPartViewer(org.eclipse.gef.EditPartViewer) IDiagramModelContainer(com.archimatetool.model.IDiagramModelContainer) GroupEditPart(com.archimatetool.editor.diagram.editparts.diagram.GroupEditPart) IContainerFigure(com.archimatetool.editor.diagram.figures.IContainerFigure) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) CreateDiagramArchimateConnectionWithDialogCommand(com.archimatetool.editor.diagram.commands.CreateDiagramArchimateConnectionWithDialogCommand) Command(org.eclipse.gef.commands.Command) Menu(org.eclipse.swt.widgets.Menu) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) Display(org.eclipse.swt.widgets.Display) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

CompoundCommand (org.eclipse.gef.commands.CompoundCommand)148 Command (org.eclipse.gef.commands.Command)63 EObject (org.eclipse.emf.ecore.EObject)28 ArrayList (java.util.ArrayList)23 AbstractWidgetModel (org.csstudio.opibuilder.model.AbstractWidgetModel)22 EObjectFeatureCommand (com.archimatetool.editor.model.commands.EObjectFeatureCommand)17 List (java.util.List)16 EditPart (org.eclipse.gef.EditPart)16 IElementParameter (org.talend.core.model.process.IElementParameter)16 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)15 Node (org.talend.designer.core.ui.editor.nodes.Node)15 SetWidgetPropertyCommand (org.csstudio.opibuilder.commands.SetWidgetPropertyCommand)14 Point (org.eclipse.draw2d.geometry.Point)14 Rectangle (org.eclipse.draw2d.geometry.Rectangle)14 INode (org.talend.core.model.process.INode)14 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 RepositoryNode (org.talend.repository.model.RepositoryNode)13 SelectionEvent (org.eclipse.swt.events.SelectionEvent)12 ConnectionItem (org.talend.core.model.properties.ConnectionItem)12 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)11