Search in sources :

Example 71 with CommandStack

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

the class LoadModelFromFileProvider method loadModel.

static IArchimateModel loadModel(File file) throws IOException {
    if (file == null || !file.exists()) {
        return null;
    }
    // Ascertain if this is an archive file
    boolean useArchiveFormat = IArchiveManager.FACTORY.isArchiveFile(file);
    // Create the Resource
    Resource resource = ArchimateResourceFactory.createNewResource(useArchiveFormat ? IArchiveManager.FACTORY.createArchiveModelURI(file) : URI.createFileURI(file.getAbsolutePath()));
    // Check model compatibility
    ModelCompatibility modelCompatibility = new ModelCompatibility(resource);
    // Load model
    resource.load(null);
    IArchimateModel model = (IArchimateModel) resource.getContents().get(0);
    // And then fix any backward compatibility issues
    try {
        modelCompatibility.fixCompatibility();
    } catch (CompatibilityHandlerException ex) {
    }
    model.setFile(file);
    model.setDefaults();
    // Add an Archive Manager and load images
    IArchiveManager archiveManager = IArchiveManager.FACTORY.createArchiveManager(model);
    model.setAdapter(IArchiveManager.class, archiveManager);
    archiveManager.loadImages();
    // Add a Command Stack
    CommandStack cmdStack = new CommandStack();
    model.setAdapter(CommandStack.class, cmdStack);
    return model;
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ModelCompatibility(com.archimatetool.editor.model.compatibility.ModelCompatibility) Resource(org.eclipse.emf.ecore.resource.Resource) CompatibilityHandlerException(com.archimatetool.editor.model.compatibility.CompatibilityHandlerException) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 72 with CommandStack

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

the class NewFolderAction method run.

@Override
public void run() {
    Object selected = getSelection().getFirstElement();
    if (selected instanceof IFolder) {
        IFolder parent = (IFolder) selected;
        // Create a new Folder, set its name
        IFolder folder = IArchimateFactory.eINSTANCE.createFolder();
        folder.setName(Messages.NewFolderAction_1);
        folder.setType(FolderType.USER);
        // Execute Command
        Command cmd = new NewFolderCommand(parent, folder);
        CommandStack commandStack = (CommandStack) parent.getAdapter(CommandStack.class);
        commandStack.execute(cmd);
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) NewFolderCommand(com.archimatetool.editor.views.tree.commands.NewFolderCommand) Command(org.eclipse.gef.commands.Command) NewFolderCommand(com.archimatetool.editor.views.tree.commands.NewFolderCommand) IFolder(com.archimatetool.model.IFolder)

Example 73 with CommandStack

use of org.eclipse.gef.commands.CommandStack in project whole by wholeplatform.

the class TreeDirectEditManager method commit.

protected void commit(String value) {
    CommandStack stack = entityPart.getViewer().getEditDomain().getCommandStack();
    stack.execute(entityPart.getCommand(getDirectEditRequest(value)));
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack)

Example 74 with CommandStack

use of org.eclipse.gef.commands.CommandStack in project whole by wholeplatform.

the class CutHandler method execute.

@Override
@Execute
public void execute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
    if (bm.wIsSet("viewer") && ClipboardUtils.hasTextSeletion((IEntityPartViewer) bm.wGetValue("viewer"))) {
        HandlersBehavior.copy(bm);
        IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
        IEntity focusEntity = bm.wGet("focusEntity");
        ITextualEntityPart focusPart = (ITextualEntityPart) viewer.getEditPartRegistry().get(focusEntity);
        Command command = focusPart.getCommand(TextualRequest.createDeleteRequest());
        command.setLabel(getLabel(bm) + " text");
        CommandStack commandStack = viewer.getEditDomain().getCommandStack();
        commandStack.execute(command);
        return;
    }
    super.execute(bm);
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ITextualEntityPart(org.whole.lang.ui.editparts.ITextualEntityPart) IEntity(org.whole.lang.model.IEntity) Command(org.eclipse.gef.commands.Command) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

Example 75 with CommandStack

use of org.eclipse.gef.commands.CommandStack in project whole by wholeplatform.

the class ModelTransactionHandler method execute.

@Execute
public void execute(@Optional @Named(IServiceConstants.ACTIVE_SELECTION) IBindingManager bm) {
    IEntityPartViewer viewer = (IEntityPartViewer) bm.wGetValue("viewer");
    EntityEditDomainJob.asyncExec(getLabel(bm), viewer.getEditDomain(), (monitor) -> {
        CommandStack commandStack = viewer.getEditDomain().getCommandStack();
        ModelTransactionCommand mtc = new ModelTransactionCommand(bm.wGet("focusEntity"));
        ITransactionScope ts = BindingManagerFactory.instance.createTransactionScope();
        try {
            bm.wEnterScope(ts);
            mtc.setLabel(getLabel(bm));
            mtc.begin();
            run(bm);
            mtc.commit();
            if (mtc.canUndo())
                commandStack.execute(mtc);
        } catch (RollbackException e) {
        // rollback done
        } catch (RuntimeException e) {
            mtc.rollbackIfNeeded();
            throw e;
        } finally {
            ts.rollback();
            bm.wExitScope();
        }
    });
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) ModelTransactionCommand(org.whole.lang.ui.commands.ModelTransactionCommand) ITransactionScope(org.whole.lang.bindings.ITransactionScope) RollbackException(org.whole.lang.lifecycle.RollbackException) IEntityPartViewer(org.whole.lang.ui.viewers.IEntityPartViewer) CanExecute(org.eclipse.e4.core.di.annotations.CanExecute) Execute(org.eclipse.e4.core.di.annotations.Execute)

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