Search in sources :

Example 1 with INameable

use of com.archimatetool.model.INameable 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 2 with INameable

use of com.archimatetool.model.INameable in project archi by archimatetool.

the class ExportAsImageAction method run.

@Override
public void run() {
    LayerManager layerManager = (LayerManager) fGraphicalViewer.getEditPartRegistry().get(LayerManager.ID);
    IFigure rootFigure = layerManager.getLayer(LayerConstants.PRINTABLE_LAYERS);
    String name = null;
    Object model = fGraphicalViewer.getContents().getModel();
    if (model instanceof INameable) {
        name = ((INameable) model).getName();
    }
    WizardDialog dialog = new ExtendedWizardDialog(fGraphicalViewer.getControl().getShell(), new ExportAsImageWizard(rootFigure, name), // $NON-NLS-1$
    "ExportAsImageWizard") {

        @Override
        protected void createButtonsForButtonBar(Composite parent) {
            // Change "Finish" to "Save"
            super.createButtonsForButtonBar(parent);
            Button b = getButton(IDialogConstants.FINISH_ID);
            b.setText(Messages.ExportAsImageAction_1);
        }
    };
    dialog.open();
}
Also used : ExtendedWizardDialog(com.archimatetool.editor.ui.components.ExtendedWizardDialog) ExportAsImageWizard(com.archimatetool.editor.diagram.wizard.ExportAsImageWizard) Composite(org.eclipse.swt.widgets.Composite) Button(org.eclipse.swt.widgets.Button) INameable(com.archimatetool.model.INameable) WizardDialog(org.eclipse.jface.wizard.WizardDialog) ExtendedWizardDialog(com.archimatetool.editor.ui.components.ExtendedWizardDialog) LayerManager(org.eclipse.gef.editparts.LayerManager) IFigure(org.eclipse.draw2d.IFigure)

Example 3 with INameable

use of com.archimatetool.model.INameable 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 4 with INameable

use of com.archimatetool.model.INameable in project archi by archimatetool.

the class ArchiLabelProviderTests method testGetLabel.

@Test
public void testGetLabel() {
    // Null object
    assertEquals("", ArchiLabelProvider.INSTANCE.getLabel(null));
    // Any object
    assertEquals("", ArchiLabelProvider.INSTANCE.getLabel(""));
    // Nameable
    INameable nameable = IArchimateFactory.eINSTANCE.createBusinessActor();
    nameable.setName("Hello");
    assertEquals("Hello", ArchiLabelProvider.INSTANCE.getLabel(nameable));
    // View
    IArchimateDiagramModel dm = IArchimateFactory.eINSTANCE.createArchimateDiagramModel();
    assertEquals("View", ArchiLabelProvider.INSTANCE.getLabel(dm));
    // Sketch
    ISketchModel sm = IArchimateFactory.eINSTANCE.createSketchModel();
    assertEquals("Sketch", ArchiLabelProvider.INSTANCE.getLabel(sm));
    // Image
    IDiagramModelImage di = IArchimateFactory.eINSTANCE.createDiagramModelImage();
    assertEquals("Image", ArchiLabelProvider.INSTANCE.getLabel(di));
}
Also used : INameable(com.archimatetool.model.INameable) IDiagramModelImage(com.archimatetool.model.IDiagramModelImage) ISketchModel(com.archimatetool.model.ISketchModel) IArchimateDiagramModel(com.archimatetool.model.IArchimateDiagramModel) Test(org.junit.Test)

Example 5 with INameable

use of com.archimatetool.model.INameable in project archi by archimatetool.

the class TreeModelViewerFindReplaceProviderTests method testFindNextElement_Forward_CaseSensitive.

@Test
public void testFindNextElement_Forward_CaseSensitive() {
    provider.setParameter(IFindReplaceProvider.PARAM_FORWARD, true);
    provider.setParameter(IFindReplaceProvider.PARAM_CASE_SENSITIVE, true);
    provider.setParameter(IFindReplaceProvider.PARAM_ALL_MODELS, true);
    // Relations as well
    provider.setParameter(IFindReplaceProvider.PARAM_INCLUDE_RELATIONS, true);
    String searchString = "Find";
    INameable element = provider.findNextElement(null, searchString);
    assertEquals("FindMe 0", element.getName());
    for (int i = 1; i < 11; i++) {
        element = provider.findNextElement(element, searchString);
        assertEquals("FindMe " + i, element.getName());
    }
    // No more
    assertNull(provider.findNextElement(element, searchString));
}
Also used : INameable(com.archimatetool.model.INameable) Test(org.junit.Test)

Aggregations

INameable (com.archimatetool.model.INameable)19 Test (org.junit.Test)7 EObjectFeatureCommand (com.archimatetool.editor.model.commands.EObjectFeatureCommand)3 CommandStack (org.eclipse.gef.commands.CommandStack)3 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)3 ExportAsImageWizard (com.archimatetool.editor.diagram.wizard.ExportAsImageWizard)2 NonNotifyingCompoundCommand (com.archimatetool.editor.model.commands.NonNotifyingCompoundCommand)2 ExtendedWizardDialog (com.archimatetool.editor.ui.components.ExtendedWizardDialog)2 IArchimateModelObject (com.archimatetool.model.IArchimateModelObject)2 IDocumentable (com.archimatetool.model.IDocumentable)2 IIdentifier (com.archimatetool.model.IIdentifier)2 ArrayList (java.util.ArrayList)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 WizardDialog (org.eclipse.jface.wizard.WizardDialog)2 Button (org.eclipse.swt.widgets.Button)2 Composite (org.eclipse.swt.widgets.Composite)2 IArchimateConcept (com.archimatetool.model.IArchimateConcept)1 IArchimateDiagramModel (com.archimatetool.model.IArchimateDiagramModel)1 IArchimateModel (com.archimatetool.model.IArchimateModel)1