Search in sources :

Example 96 with CommandStack

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

the class AbstractECorePropertySection method executeCommand.

/**
 * Execuate a command on the selected objects' CommandStack
 * @param cmd
 */
protected void executeCommand(Command command) {
    fIsExecutingCommand = true;
    EObject eObject = getFirstSelectedObject();
    if (eObject != null && eObject instanceof IAdapter) {
        CommandStack commandStack = (CommandStack) ((IAdapter) eObject).getAdapter(CommandStack.class);
        if (commandStack != null) {
            commandStack.execute(command);
        }
    }
    fIsExecutingCommand = false;
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) EObject(org.eclipse.emf.ecore.EObject) IAdapter(com.archimatetool.model.IAdapter)

Example 97 with CommandStack

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

the class DirectEditManager method commit.

/**
 * Commits the current value of the cell editor by getting a {@link Command}
 * from the source edit part and executing it via the {@link CommandStack}.
 * Finally, {@link #bringDown()} is called to perform and necessary cleanup.
 */
protected void commit() {
    if (committing)
        return;
    committing = true;
    try {
        eraseFeedback();
        if (isDirty()) {
            CommandStack stack = getEditPart().getViewer().getEditDomain().getCommandStack();
            stack.execute(getEditPart().getCommand(getDirectEditRequest()));
        }
    } finally {
        bringDown();
        committing = false;
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack)

Example 98 with CommandStack

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

the class CSVImporterTests method testDoImport.

@Test
public void testDoImport() throws Exception {
    importer.doImport(elements1File);
    testDoImportPart1();
    // Now undo it
    CommandStack stack = (CommandStack) model.getAdapter(CommandStack.class);
    stack.undo();
    assertEquals("", model.getName());
    assertEquals("", model.getPurpose());
    assertEquals(0, model.getProperties().size());
    assertEquals(0, model.getFolder(FolderType.BUSINESS).getElements().size());
    assertEquals(0, model.getFolder(FolderType.RELATIONS).getElements().size());
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) Test(org.junit.Test)

Example 99 with CommandStack

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

the class CreateEmptyModelProvider method createEmptyModel.

private IArchimateModel createEmptyModel() {
    IArchimateModel model = IArchimateFactory.eINSTANCE.createArchimateModel();
    model.setDefaults();
    // Add an Archive Manager
    IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(model);
    model.setAdapter(IArchiveManager.class, archiveManager);
    // Add a Command Stack
    CommandStack cmdStack = new CommandStack();
    model.setAdapter(CommandStack.class, cmdStack);
    logMessage(Messages.CreateEmptyModelProvider_7);
    return model;
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 100 with CommandStack

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

the class ProfilesManagerDialog method okPressed.

/**
 * OK was pressed, so see what was added, changed or deleted and execute the Commands
 */
@Override
protected void okPressed() {
    super.okPressed();
    CompoundCommand compoundCmd = new CompoundCommand(Messages.ProfilesManagerDialog_16);
    // Iterate thru our temp list of Profiles
    for (IProfile profile : fProfilesTemp.values()) {
        // Is this a copy of the original?
        if (fProfilesModel.containsKey(profile.getId())) {
            IProfile profileOriginal = fProfilesModel.get(profile.getId());
            // The Profile has been edited
            if (!EcoreUtil.equals(profileOriginal, profile)) {
                List<IProfiles> usages = fProfilesUsage.get(profileOriginal.getId());
                compoundCmd.add(new ChangeProfileCommand(profileOriginal, profile, usages));
            }
        } else // A new Profile was added
        {
            compoundCmd.add(new AddListMemberCommand<IProfile>(fArchimateModel.getProfiles(), profile));
        }
    }
    // Iterate thru model's Profiles and compare with our temp list to see if any Profiles were deleted
    for (IProfile profile : fArchimateModel.getProfiles()) {
        if (!fProfilesTemp.containsKey(profile.getId())) {
            List<IProfiles> usages = fProfilesUsage.get(profile.getId());
            compoundCmd.add(new DeleteProfileCommand(profile, usages));
        }
    }
    // Execute the Commands
    CommandStack stack = (CommandStack) fArchimateModel.getAdapter(CommandStack.class);
    stack.execute(compoundCmd);
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) IProfiles(com.archimatetool.model.IProfiles) IProfile(com.archimatetool.model.IProfile) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Aggregations

CommandStack (org.eclipse.gef.commands.CommandStack)105 Command (org.eclipse.gef.commands.Command)32 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)14 IArchiveManager (com.archimatetool.editor.model.IArchiveManager)13 AbstractMultiPageTalendEditor (org.talend.designer.core.ui.AbstractMultiPageTalendEditor)13 IArchimateModel (com.archimatetool.model.IArchimateModel)12 ModelTransactionCommand (org.whole.lang.ui.commands.ModelTransactionCommand)12 IEntityPartViewer (org.whole.lang.ui.viewers.IEntityPartViewer)12 NonNotifyingCompoundCommand (com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand)10 EditPart (org.eclipse.gef.EditPart)10 INode (org.talend.core.model.process.INode)10 Node (org.talend.designer.core.ui.editor.nodes.Node)9 IEntity (org.whole.lang.model.IEntity)9 ArrayList (java.util.ArrayList)8 Test (org.junit.Test)8 PersistenceException (org.talend.commons.exception.PersistenceException)8 EObjectFeatureCommand (com.archimatetool.editor.model.commands.EObjectFeatureCommand)7 IFolder (com.archimatetool.model.IFolder)6 IOException (java.io.IOException)6 IEditorPart (org.eclipse.ui.IEditorPart)6