Search in sources :

Example 11 with INameable

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

the class ExportAsImageAction method run.

@Override
public void run() {
    String name = null;
    Object model = fGraphViewer.getInput();
    if (model instanceof INameable) {
        name = ((INameable) model).getName();
    }
    WizardDialog dialog = new ExtendedWizardDialog(fGraphViewer.getControl().getShell(), new ExportAsImageWizard(fGraphViewer.getGraphControl().getContents(), name), // $NON-NLS-1$
    "ExportZestViewAsImage") {

        @Override
        protected void createButtonsForButtonBar(Composite parent) {
            // Change "Finish" to "Save"
            super.createButtonsForButtonBar(parent);
            Button b = getButton(IDialogConstants.FINISH_ID);
            b.setText(Messages.ExportAsImageAction_3);
        }
    };
    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)

Example 12 with INameable

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

the class DiagramEditorFindReplaceProvider method replace.

@Override
public boolean replace(String toFind, String toReplaceWith) {
    // Replace All
    if (isAll()) {
        List<EditPart> editParts = getAllMatchingEditParts(toFind);
        if (!editParts.isEmpty()) {
            List<String> newNames = new ArrayList<String>();
            for (EditPart editPart : editParts) {
                String newName = getNewName(((INameable) editPart.getModel()).getName(), toFind, toReplaceWith);
                newNames.add(newName);
            }
            doRenameCommands(editParts, newNames);
            fGraphicalViewer.setSelection(new StructuredSelection(editParts));
            fGraphicalViewer.reveal(editParts.get(0));
        }
        return !editParts.isEmpty();
    } else // Replace Next/Previous
    {
        // Replace on selected EditParts
        if (replaceSelection) {
            List<EditPart> selected = getSelectedEditParts();
            if (!selected.isEmpty()) {
                List<EditPart> editParts = new ArrayList<EditPart>();
                List<String> newNames = new ArrayList<String>();
                for (EditPart editPart : selected) {
                    if (matches(editPart, toFind)) {
                        editParts.add(editPart);
                        String newName = getNewName(((INameable) editPart.getModel()).getName(), toFind, toReplaceWith);
                        newNames.add(newName);
                    }
                }
                if (!editParts.isEmpty()) {
                    doRenameCommands(editParts, newNames);
                    return true;
                }
            }
        } else // Replace on next single selection
        {
            EditPart editPart = getFirstSelectedEditPart();
            if (matches(editPart, toFind)) {
                doRenameCommand(editPart, getNewName(((INameable) editPart.getModel()).getName(), toFind, toReplaceWith));
                return true;
            }
        }
        // Else move forward
        return find(toFind);
    }
}
Also used : INameable(com.archimatetool.model.INameable) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) EditPart(org.eclipse.gef.EditPart) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 13 with INameable

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

the class DiagramEditorFindReplaceProvider method doRenameCommand.

void doRenameCommand(EditPart editPart, String newName) {
    INameable object = (INameable) editPart.getModel();
    CommandStack stack = (CommandStack) ((IAdapter) object).getAdapter(CommandStack.class);
    if (stack != null) {
        stack.execute(new EObjectFeatureCommand(NLS.bind(Messages.DiagramEditorFindReplaceProvider_0, object.getName()), object, IArchimatePackage.Literals.NAMEABLE__NAME, newName));
    }
}
Also used : CommandStack(org.eclipse.gef.commands.CommandStack) EObjectFeatureCommand(com.archimatetool.editor.model.commands.EObjectFeatureCommand) INameable(com.archimatetool.model.INameable)

Example 14 with INameable

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

the class FieldDataFactory method getFieldValue.

public static Object getFieldValue(Object dataElement, String fieldName) {
    if ("this".equals(fieldName)) {
        // $NON-NLS-1$
        return dataElement;
    }
    if ("id".equals(fieldName) && dataElement instanceof IIdentifier) {
        // $NON-NLS-1$
        return ((IIdentifier) dataElement).getId();
    }
    if ("name".equals(fieldName) && dataElement instanceof INameable) {
        // $NON-NLS-1$
        String name = ((INameable) dataElement).getName();
        if (name == null || "".equals(name)) {
            // $NON-NLS-1$
            name = ArchiLabelProvider.INSTANCE.getDefaultName(((EObject) dataElement).eClass());
        }
        return name;
    }
    if ("type".equals(fieldName) && dataElement instanceof EObject) {
        // $NON-NLS-1$
        return ArchiLabelProvider.INSTANCE.getDefaultName(((EObject) dataElement).eClass());
    }
    if ("documentation".equals(fieldName) && dataElement instanceof IDocumentable) {
        // $NON-NLS-1$
        String s = ((IDocumentable) dataElement).getDocumentation();
        return StringUtils.isSet(s) ? s : null;
    }
    if ("purpose".equals(fieldName) && dataElement instanceof IArchimateModel) {
        // $NON-NLS-1$
        String s = ((IArchimateModel) dataElement).getPurpose();
        return StringUtils.isSet(s) ? s : null;
    }
    if ("relation_source".equals(fieldName) && dataElement instanceof IArchimateRelationship) {
        // $NON-NLS-1$
        IArchimateRelationship relation = (IArchimateRelationship) dataElement;
        IArchimateConcept source = relation.getSource();
        String s = source.getName();
        return StringUtils.isSet(s) ? s : null;
    }
    if ("relation_target".equals(fieldName) && dataElement instanceof IArchimateRelationship) {
        // $NON-NLS-1$
        IArchimateRelationship relation = (IArchimateRelationship) dataElement;
        IArchimateConcept target = relation.getTarget();
        String s = target.getName();
        return StringUtils.isSet(s) ? s : null;
    }
    return null;
}
Also used : IDocumentable(com.archimatetool.model.IDocumentable) IIdentifier(com.archimatetool.model.IIdentifier) INameable(com.archimatetool.model.INameable) EObject(org.eclipse.emf.ecore.EObject) IArchimateConcept(com.archimatetool.model.IArchimateConcept) IArchimateRelationship(com.archimatetool.model.IArchimateRelationship) IArchimateModel(com.archimatetool.model.IArchimateModel)

Example 15 with INameable

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

the class TreeModelViewerFindReplaceProviderTests method testFindNextElement_Forward_NotCaseSensitive_2.

@Test
public void testFindNextElement_Forward_NotCaseSensitive_2() {
    provider.setParameter(IFindReplaceProvider.PARAM_FORWARD, true);
    provider.setParameter(IFindReplaceProvider.PARAM_CASE_SENSITIVE, false);
    provider.setParameter(IFindReplaceProvider.PARAM_ALL_MODELS, true);
    String searchString = "director";
    INameable element = provider.findNextElement(null, searchString);
    assertEquals("Director of Finance", element.getName());
    element = provider.findNextElement(element, searchString);
    assertEquals("Director of Operations", element.getName());
    element = provider.findNextElement(element, searchString);
    assertEquals("Director of Sales", 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