Search in sources :

Example 1 with EObjectFeatureCommand

use of com.archimatetool.editor.model.commands.EObjectFeatureCommand in project archi by archimatetool.

the class DiagramModelImageSection method setImage.

protected void setImage(Object selected) {
    String path = null;
    try {
        // User selected a file
        if (selected instanceof File) {
            File file = (File) selected;
            if (!file.exists() || !file.canRead()) {
                return;
            }
            IArchiveManager archiveManager = (IArchiveManager) ((IAdapter) getFirstSelectedObject()).getAdapter(IArchiveManager.class);
            path = archiveManager.addImageFromFile(file);
        } else // User selected a Gallery image path
        if (selected instanceof String) {
            path = (String) selected;
        } else // User selected nothing
        {
            return;
        }
    } catch (IOException ex) {
        ex.printStackTrace();
        MessageDialog.openError(getPart().getSite().getShell(), Messages.DiagramModelImageSection_5, Messages.DiagramModelImageSection_6);
        return;
    }
    CompoundCommand result = new CompoundCommand();
    for (EObject dmo : getEObjects()) {
        if (isAlive(dmo)) {
            Command cmd = new EObjectFeatureCommand(Messages.DiagramModelImageSection_7, dmo, IArchimatePackage.Literals.DIAGRAM_MODEL_IMAGE_PROVIDER__IMAGE_PATH, path);
            if (cmd.canExecute()) {
                result.add(cmd);
            }
        }
    }
    executeCommand(result.unwrap());
}
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) EObject(org.eclipse.emf.ecore.EObject) IOException(java.io.IOException) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) File(java.io.File) CompoundCommand(org.eclipse.gef.commands.CompoundCommand)

Example 2 with EObjectFeatureCommand

use of com.archimatetool.editor.model.commands.EObjectFeatureCommand in project archi by archimatetool.

the class DiagramEditorFindReplaceProvider method doRenameCommands.

void doRenameCommands(List<EditPart> editParts, List<String> newNames) {
    // Must match sizes
    if (editParts.size() != newNames.size() || editParts.isEmpty()) {
        return;
    }
    CompoundCommand compoundCommand = new NonNotifyingCompoundCommand(Messages.DiagramEditorFindReplaceProvider_1);
    for (int i = 0; i < editParts.size(); i++) {
        INameable object = (INameable) editParts.get(i).getModel();
        String newName = newNames.get(i);
        compoundCommand.add(new EObjectFeatureCommand(NLS.bind(Messages.DiagramEditorFindReplaceProvider_0, object.getName()), object, IArchimatePackage.Literals.NAMEABLE__NAME, newName));
    }
    CommandStack stack = (CommandStack) ((IAdapter) editParts.get(0).getModel()).getAdapter(CommandStack.class);
    if (stack != null) {
        stack.execute(compoundCommand.unwrap());
    }
}
Also used : NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand) CommandStack(org.eclipse.gef.commands.CommandStack) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) INameable(com.archimatetool.model.INameable) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) NonNotifyingCompoundCommand(com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand)

Example 3 with EObjectFeatureCommand

use of com.archimatetool.editor.model.commands.EObjectFeatureCommand in project archi by archimatetool.

the class FormatPainterTool method createCommand.

protected CompoundCommand createCommand(PaintFormat pf, IDiagramModelComponent targetComponent) {
    CompoundCommand result = new CompoundCommand(Messages.FormatPainterTool_0);
    // IFontAttribute
    if (pf.getSourceComponent() instanceof IFontAttribute && targetComponent instanceof IFontAttribute) {
        IFontAttribute source = (IFontAttribute) pf.getSourceComponent();
        IFontAttribute target = (IFontAttribute) targetComponent;
        Command cmd = new FontStyleCommand(target, source.getFont());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        cmd = new FontColorCommand(target, source.getFontColor());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // ILineObject
    if (pf.getSourceComponent() instanceof ILineObject && targetComponent instanceof ILineObject) {
        ILineObject source = (ILineObject) pf.getSourceComponent();
        ILineObject target = (ILineObject) targetComponent;
        Command cmd = new LineColorCommand(target, source.getLineColor());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        cmd = new LineWidthCommand(target, source.getLineWidth());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // IBorderObject
    if (pf.getSourceComponent() instanceof IBorderObject && targetComponent instanceof IBorderObject) {
        IBorderObject source = (IBorderObject) pf.getSourceComponent();
        IBorderObject target = (IBorderObject) targetComponent;
        Command cmd = new BorderColorCommand(target, source.getBorderColor());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // ITextPosition
    if (pf.getSourceComponent() instanceof ITextPosition && targetComponent instanceof ITextPosition) {
        ITextPosition source = (ITextPosition) pf.getSourceComponent();
        ITextPosition target = (ITextPosition) targetComponent;
        Command cmd = new TextPositionCommand(target, source.getTextPosition());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // ITextAlignment
    if (pf.getSourceComponent() instanceof ITextAlignment && targetComponent instanceof ITextAlignment) {
        ITextAlignment source = (ITextAlignment) pf.getSourceComponent();
        ITextAlignment target = (ITextAlignment) targetComponent;
        Command cmd = new TextAlignmentCommand(target, source.getTextAlignment());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // IDiagramModelObject
    if (pf.getSourceComponent() instanceof IDiagramModelObject && targetComponent instanceof IDiagramModelObject) {
        IDiagramModelObject source = (IDiagramModelObject) pf.getSourceComponent();
        IDiagramModelObject target = (IDiagramModelObject) targetComponent;
        // Source fill colour is null which is "default"
        String fillColorString = source.getFillColor();
        if (fillColorString == null) {
            fillColorString = ColorFactory.convertColorToString(ColorFactory.getDefaultFillColor(source));
        }
        Command cmd = new FillColorCommand(target, fillColorString);
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        // Alpha fill opacity
        cmd = new DiagramModelObjectAlphaCommand(target, source.getAlpha());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        // Alpha line opacity
        cmd = new DiagramModelObjectOutlineAlphaCommand(target, source.getLineAlpha());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        // Gradient
        // $NON-NLS-1$
        cmd = new FeatureCommand("", target, IDiagramModelObject.FEATURE_GRADIENT, source.getGradient(), IDiagramModelObject.FEATURE_GRADIENT_DEFAULT);
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        // Icon Visibility, but paste only if the target object has an icon
        IObjectUIProvider provider = ObjectUIFactory.INSTANCE.getProvider(target);
        if (provider instanceof IGraphicalObjectUIProvider && ((IGraphicalObjectUIProvider) provider).hasIcon()) {
            // $NON-NLS-1$
            cmd = new FeatureCommand("", target, IDiagramModelObject.FEATURE_ICON_VISIBLE, source.getIconVisibleState(), IDiagramModelObject.FEATURE_ICON_VISIBLE_DEFAULT);
            if (cmd.canExecute()) {
                result.add(cmd);
            }
        }
    }
    // Archimate objects
    if (pf.getSourceComponent() instanceof IDiagramModelArchimateObject && targetComponent instanceof IDiagramModelArchimateObject) {
        IDiagramModelArchimateObject source = (IDiagramModelArchimateObject) pf.getSourceComponent();
        IDiagramModelArchimateObject target = (IDiagramModelArchimateObject) targetComponent;
        // Image Source
        Command cmd = new // $NON-NLS-1$
        FeatureCommand(// $NON-NLS-1$
        "", // $NON-NLS-1$
        target, // $NON-NLS-1$
        IDiagramModelArchimateObject.FEATURE_IMAGE_SOURCE, source.getImageSource(), IDiagramModelArchimateObject.FEATURE_IMAGE_SOURCE_DEFAULT);
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    // IDiagramModelConnection
    if (pf.getSourceComponent() instanceof IDiagramModelConnection && targetComponent instanceof IDiagramModelConnection) {
        IDiagramModelConnection source = (IDiagramModelConnection) pf.getSourceComponent();
        IDiagramModelConnection target = (IDiagramModelConnection) targetComponent;
        // Connection text position
        Command cmd = new ConnectionTextPositionCommand(target, source.getTextPosition());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        // If a non-Archimate connection, connection line type
        if (!(target instanceof IDiagramModelArchimateConnection)) {
            cmd = new ConnectionLineTypeCommand(target, source.getType());
            if (cmd.canExecute()) {
                result.add(cmd);
            }
        }
    }
    // IIconic
    if (pf.getSourceComponent() instanceof IIconic && targetComponent instanceof IIconic) {
        IIconic source = (IIconic) pf.getSourceComponent();
        IIconic target = (IIconic) targetComponent;
        // If we have an image path and the source and target models are different, copy the image bytes
        String imagePath = source.getImagePath();
        if (imagePath != null && source.getArchimateModel() != target.getArchimateModel()) {
            IArchiveManager sourceArchiveManager = (IArchiveManager) source.getAdapter(IArchiveManager.class);
            IArchiveManager targetArchiveManager = (IArchiveManager) target.getAdapter(IArchiveManager.class);
            try {
                imagePath = targetArchiveManager.copyImageBytes(sourceArchiveManager, imagePath);
            } catch (IOException ex) {
                ex.printStackTrace();
                // $NON-NLS-1$
                Logger.logError("Could not copy image bytes when copying and pasting objects.", ex);
            }
        }
        // $NON-NLS-1$
        Command cmd = new EObjectFeatureCommand("", target, IArchimatePackage.Literals.DIAGRAM_MODEL_IMAGE_PROVIDER__IMAGE_PATH, imagePath);
        if (cmd.canExecute()) {
            result.add(cmd);
        }
        // Image position
        // $NON-NLS-1$
        cmd = new EObjectFeatureCommand("", target, IArchimatePackage.Literals.ICONIC__IMAGE_POSITION, source.getImagePosition());
        if (cmd.canExecute()) {
            result.add(cmd);
        }
    }
    return result;
}
Also used : FillColorCommand(com.archimatetool.editor.diagram.commands.FillColorCommand) IDiagramModelConnection(com.archimatetool.model.IDiagramModelConnection) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) FontColorCommand(com.archimatetool.editor.diagram.commands.FontColorCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) FeatureCommand(com.archimatetool.editor.model.commands.FeatureCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) IFontAttribute(com.archimatetool.model.IFontAttribute) LineWidthCommand(com.archimatetool.editor.diagram.commands.LineWidthCommand) FontStyleCommand(com.archimatetool.editor.diagram.commands.FontStyleCommand) DiagramModelObjectOutlineAlphaCommand(com.archimatetool.editor.diagram.commands.DiagramModelObjectOutlineAlphaCommand) ConnectionTextPositionCommand(com.archimatetool.editor.diagram.commands.ConnectionTextPositionCommand) TextAlignmentCommand(com.archimatetool.editor.diagram.commands.TextAlignmentCommand) LineColorCommand(com.archimatetool.editor.diagram.commands.LineColorCommand) ITextPosition(com.archimatetool.model.ITextPosition) IIconic(com.archimatetool.model.IIconic) IDiagramModelArchimateConnection(com.archimatetool.model.IDiagramModelArchimateConnection) IOException(java.io.IOException) IArchiveManager(com.archimatetool.editor.model.IArchiveManager) DiagramModelObjectAlphaCommand(com.archimatetool.editor.diagram.commands.DiagramModelObjectAlphaCommand) ILineObject(com.archimatetool.model.ILineObject) BorderColorCommand(com.archimatetool.editor.diagram.commands.BorderColorCommand) IBorderObject(com.archimatetool.model.IBorderObject) ITextAlignment(com.archimatetool.model.ITextAlignment) FontStyleCommand(com.archimatetool.editor.diagram.commands.FontStyleCommand) DiagramModelObjectAlphaCommand(com.archimatetool.editor.diagram.commands.DiagramModelObjectAlphaCommand) ConnectionTextPositionCommand(com.archimatetool.editor.diagram.commands.ConnectionTextPositionCommand) DiagramModelObjectOutlineAlphaCommand(com.archimatetool.editor.diagram.commands.DiagramModelObjectOutlineAlphaCommand) BorderColorCommand(com.archimatetool.editor.diagram.commands.BorderColorCommand) TextPositionCommand(com.archimatetool.editor.diagram.commands.TextPositionCommand) LineWidthCommand(com.archimatetool.editor.diagram.commands.LineWidthCommand) FontColorCommand(com.archimatetool.editor.diagram.commands.FontColorCommand) TextAlignmentCommand(com.archimatetool.editor.diagram.commands.TextAlignmentCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) ConnectionLineTypeCommand(com.archimatetool.editor.diagram.commands.ConnectionLineTypeCommand) FillColorCommand(com.archimatetool.editor.diagram.commands.FillColorCommand) LineColorCommand(com.archimatetool.editor.diagram.commands.LineColorCommand) FeatureCommand(com.archimatetool.editor.model.commands.FeatureCommand) Command(org.eclipse.gef.commands.Command) ConnectionLineTypeCommand(com.archimatetool.editor.diagram.commands.ConnectionLineTypeCommand) IGraphicalObjectUIProvider(com.archimatetool.editor.ui.factory.IGraphicalObjectUIProvider) ConnectionTextPositionCommand(com.archimatetool.editor.diagram.commands.ConnectionTextPositionCommand) TextPositionCommand(com.archimatetool.editor.diagram.commands.TextPositionCommand) IDiagramModelArchimateObject(com.archimatetool.model.IDiagramModelArchimateObject) IObjectUIProvider(com.archimatetool.editor.ui.factory.IObjectUIProvider)

Example 4 with EObjectFeatureCommand

use of com.archimatetool.editor.model.commands.EObjectFeatureCommand in project archi by archimatetool.

the class PartDirectEditTitlePolicy method getDirectEditCommand.

@Override
protected Command getDirectEditCommand(DirectEditRequest request) {
    IDiagramModelObject object = (IDiagramModelObject) getHost().getModel();
    String name = (String) request.getCellEditor().getValue();
    return new EObjectFeatureCommand(NLS.bind(Messages.PartDirectEditTitlePolicy_0, object.getName()), object, IArchimatePackage.Literals.NAMEABLE__NAME, name);
}
Also used : EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) IDiagramModelObject(com.archimatetool.model.IDiagramModelObject)

Example 5 with EObjectFeatureCommand

use of com.archimatetool.editor.model.commands.EObjectFeatureCommand 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)

Aggregations

EObjectFeatureCommand (com.archimatetool.editor.model.commands.EObjectFeatureCommand)27 Command (org.eclipse.gef.commands.Command)22 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)21 EObject (org.eclipse.emf.ecore.EObject)19 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)8 SelectionEvent (org.eclipse.swt.events.SelectionEvent)8 Combo (org.eclipse.swt.widgets.Combo)8 GridData (org.eclipse.swt.layout.GridData)6 StyledTextControl (com.archimatetool.editor.ui.components.StyledTextControl)5 CommandStack (org.eclipse.gef.commands.CommandStack)5 NonNotifyingCompoundCommand (com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand)4 IArchiveManager (com.archimatetool.editor.model.IArchiveManager)3 INameable (com.archimatetool.model.INameable)3 File (java.io.File)3 PropertySectionTextControl (com.archimatetool.editor.propertysections.PropertySectionTextControl)2 IDiagramModelObject (com.archimatetool.model.IDiagramModelObject)2 IOException (java.io.IOException)2 Label (org.eclipse.swt.widgets.Label)2 Text (org.eclipse.swt.widgets.Text)2 BorderColorCommand (com.archimatetool.editor.diagram.commands.BorderColorCommand)1