IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Lesson11 script: started");
//checking if project is opened.
if (IdeProjectManagerAccess.getProjectManager().getActiveProject() == null) {
IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR_MODAL, "No open project");
IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Lesson11 script: finished");
return;
}
//we need an opened diagram to get an element to work with
IdeDiagramManager diagramManager = IdeDiagramManagerAccess.getDiagramManager();
if (diagramManager.getActiveDiagram() == null) {
IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR_MODAL, "No open diagram");
IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Lesson11 script: finished");
return;
}
//the array of selected RwiElements
RwiElement[] selectedRwiElements = context.getRwiElements();
if (selectedRwiElements == null || selectedRwiElements.length == 0) {
IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR_MODAL, "No selection was made.");
IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Lesson11 script: finished");
return;
}
if (selectedRwiElements.length > 1) {
IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR_MODAL, "Please select only one element");
IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Lesson11 script: finished");
return;
}
RwiElement rwiElement = selectedRwiElements[0];
String shapeType = rwiElement.getProperty(RwiProperty.SHAPE_TYPE);
if (!(RwiShapeType.CLASS.equals(shapeType) || RwiShapeType.OPERATION.equals(shapeType) || RwiShapeType.ATTRIBUTE.equals(shapeType))) {
IdeMessageManagerAccess.printMessage(IdeMessageType.ERROR_MODAL,
"Please select either a class/interface or an operation/attribute");
IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Lesson11 script: finished");
return;
}
IdeEditorManager editorManager = IdeEditorManagerAccess.getEditorManager();
editorManager.setPaneVisible(true);
String fileName = rwiElement.getProperty(RwiProperty.FILE); //name of a file with the selected element
IdeEditor editor = editorManager.findEditor(fileName);
if (editor != null) { //file is opened
IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION_MODAL,
"You have selected an element \"" + rwiElement.getProperty(RwiProperty.FULL_NAME) +
"\". Now we will close the editor");
editorManager.closeEditor(editor);
}
IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION_MODAL,
"Now we will open a file containing the selected element (" + rwiElement.getProperty(RwiProperty.FULL_NAME) +
"), and scroll to that element");
openAndDisplayRwiElement(rwiElement);
IdeMessageManagerAccess.printMessage(IdeMessageType.INFORMATION, "Lesson11 script: finished");