Skip to content

Commit

Permalink
Bugfix NullPointerException (#59)
Browse files Browse the repository at this point in the history
* Bugfix NullPointerException

* 0.3.1
  • Loading branch information
claudenirmf authored Aug 4, 2020
2 parents 88f4bab + c33a173 commit ca75123
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 48 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>it.unibz.inf.ontouml</groupId>
<artifactId>ontouml-vp-plugin</artifactId>
<version>0.3.0-SNAPSHOT</version>
<version>0.3.1-SNAPSHOT</version>

<name>OntoUML 2 Plugin for Visual Paradigm</name>

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/it/unibz/inf/ontouml/vp/OntoUMLPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
public class OntoUMLPlugin implements VPPlugin {

public static final String PLUGIN_VERSION_RELEASE = "0.3.0";
public static final String PLUGIN_VERSION_RELEASE = "0.3.1";
public static final String PLUGIN_ID = "it.unibz.inf.ontouml.vp";
public static final String PLUGIN_NAME = "OntoUML Plugin";
public static final String PLUGIN_REPO = "https://github.com/OntoUML/ontouml-vp-plugin/";
Expand Down
89 changes: 43 additions & 46 deletions src/main/java/it/unibz/inf/ontouml/vp/utils/ViewUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
import com.google.gson.JsonSyntaxException;
import com.vp.plugin.ApplicationManager;
import com.vp.plugin.DiagramManager;
import com.vp.plugin.ProjectManager;
import com.vp.plugin.ViewManager;
import com.vp.plugin.diagram.IClassDiagramUIModel;
import com.vp.plugin.diagram.IDiagramElement;
import com.vp.plugin.diagram.IDiagramUIModel;
import com.vp.plugin.model.IModelElement;
import com.vp.plugin.model.IProject;

import it.unibz.inf.ontouml.vp.OntoUMLPlugin;
import it.unibz.inf.ontouml.vp.views.HTMLEnabledMessage;
Expand Down Expand Up @@ -484,24 +486,11 @@ public static int errorCountInCurrentDiagram(String responseMessage) {
}

public static boolean isElementInAnyDiagram(String elementId) {
final IDiagramUIModel[] diagramArray = ApplicationManager.instance().getProjectManager().getProject()
.toDiagramArray();

if (diagramArray == null)
return false;

for (IDiagramUIModel diagram : diagramArray) {
if (diagram instanceof IClassDiagramUIModel) {
for (IDiagramElement diagramElement : diagram.toDiagramElementArray()) {
IModelElement modelElement = diagramElement.getMetaModelElement();
if (modelElement.getId() != null && modelElement.getId().equals(elementId)) {
return true;
}
}
}
}

return false;
final IProject project = ApplicationManager.instance().getProjectManager().getProject();
final IModelElement element = project.getModelElementById(elementId);
final IDiagramElement[] diagramElements = element != null ? element.getDiagramElements() : null;

return diagramElements != null && diagramElements.length > 0;
}

public static void openSpecDiagramElement(String elementId) {
Expand All @@ -512,38 +501,45 @@ public static void openSpecDiagramElement(String elementId) {
viewManager.openSpec(element, viewManager.getRootFrame());
}

public static void highlightDiagramElement(String elementId) {
public static void highlightDiagramElement(String modelElementId) {
final ApplicationManager app = ApplicationManager.instance();
final IModelElement element = app.getProjectManager().getProject().getModelElementById(elementId);
final IProject project = app.getProjectManager().getProject();
final IModelElement modelElement = project.getModelElementById(modelElementId);

if(modelElement == null) {
return ;
}

final DiagramManager diagramManager = app.getDiagramManager();
IDiagramElement diagramElement = null;

// Checks if the active diagram contains the element
if (diagramManager.getActiveDiagram() != null) {
final Iterator<?> iter = diagramManager.getActiveDiagram().diagramElementIterator();
while (iter.hasNext()) {
final IDiagramElement current = (IDiagramElement) iter.next();
if (current.getModelElement().equals(element)) {
diagramElement = current;
continue;
}
final IDiagramElement[] diagramElements = modelElement.getDiagramElements();
IDiagramElement activeView = null;
IDiagramElement masterView = null;
IDiagramElement firstView = null;

for (int i=0; diagramElements != null && i < diagramElements.length; i++) {
IDiagramElement diagramElement = diagramElements[i];

if(diagramElement == null) {
continue ;
}
}

// In case the active diagram does not contain it, get the master view or the
// first diagram element for that element
if (diagramElement == null) {
if (element.getMasterView() != null) {
diagramElement = element.getMasterView();
} else {
final IDiagramElement[] diagramElements = element.getDiagramElements();
diagramElement = diagramElements != null ? diagramElements[0] : null;

firstView = firstView == null ? diagramElement : firstView;
activeView = diagramElement.getDiagramUIModel().isOpened() ? diagramElement : activeView;
masterView = diagramElement.isMasterView() ? diagramElement : masterView;

if(activeView != null) {
break ;
}
}

// Highlights the diagram element if it is not null
if (diagramElement != null) {
diagramManager.highlight(diagramElement);

if(activeView != null) {
diagramManager.highlight(activeView);
}
else if(masterView != null) {
diagramManager.highlight(masterView);
}
else if(firstView != null) {
diagramManager.highlight(firstView);
}
}

Expand Down Expand Up @@ -687,8 +683,9 @@ private void doPop(MouseEvent e) {
menu = new ContextMenu();
} else {
menu = new ContextMenu(idModelElement);
if (!ViewUtils.isElementInAnyDiagram(idModelElement))
if (!ViewUtils.isElementInAnyDiagram(idModelElement)) {
menu.disableItem("Take me there!");
}
}

menu.show(e.getComponent(), e.getX(), e.getY());
Expand Down

0 comments on commit ca75123

Please sign in to comment.