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());
}
}
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();
}
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());
}
}
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));
}
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));
}
Aggregations