1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
|
/*******************************************************************************
* Copyright (c) 2015 Boeing.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Boeing - initial API and implementation
*******************************************************************************/
package org.eclipse.osee.framework.ui.data.model.editor;
import static org.eclipse.osee.framework.core.enums.CoreAttributeTypes.GraphitiDiagram;
import static org.eclipse.osee.framework.core.enums.PresentationType.DEFAULT_OPEN;
import static org.eclipse.osee.framework.core.enums.PresentationType.PREVIEW;
import static org.eclipse.osee.framework.core.enums.PresentationType.RENDER_AS_HUMAN_READABLE_TEXT;
import static org.eclipse.osee.framework.core.enums.PresentationType.SPECIALIZED_EDIT;
import static org.eclipse.osee.framework.ui.data.model.editor.GraphitiImage.GRAPHITI_DIAGRAM;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.common.util.URI;
import org.eclipse.graphiti.ui.editor.DiagramEditorInput;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.PresentationType;
import org.eclipse.osee.framework.jdk.core.type.OseeCoreException;
import org.eclipse.osee.framework.logging.OseeLevel;
import org.eclipse.osee.framework.logging.OseeLog;
import org.eclipse.osee.framework.skynet.core.artifact.Artifact;
import org.eclipse.osee.framework.skynet.core.types.IArtifact;
import org.eclipse.osee.framework.ui.plugin.util.AWorkbench;
import org.eclipse.osee.framework.ui.skynet.MenuCmdDef;
import org.eclipse.osee.framework.ui.skynet.render.DefaultArtifactRenderer;
import org.eclipse.osee.framework.ui.skynet.render.IRenderer;
import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.ui.IWorkbenchPage;
/**
* @author Ryan D. Brooks
*/
public class GraphitiRenderer extends DefaultArtifactRenderer {
@Override
public GraphitiRenderer newInstance() {
return new GraphitiRenderer();
}
@Override
public String getName() {
return "GraphitiRenderer";
}
@Override
public int getApplicabilityRating(PresentationType presentationType, IArtifact artifact, Object... objects) throws OseeCoreException {
int rating = IRenderer.NO_MATCH;
if (artifact.getArtifactType().inheritsFrom(CoreArtifactTypes.ModelDiagram)) {
if (presentationType.matches(RENDER_AS_HUMAN_READABLE_TEXT, PREVIEW, DEFAULT_OPEN, SPECIALIZED_EDIT)) {
rating = IRenderer.PRESENTATION_SUBTYPE_MATCH;
}
}
return rating;
}
@Override
public void addMenuCommandDefinitions(ArrayList<MenuCmdDef> commands, Artifact artifact) {
commands.add(new MenuCmdDef(CommandGroup.EDIT, SPECIALIZED_EDIT, "Diagram Editor", GRAPHITI_DIAGRAM));
}
@Override
public void open(final List<Artifact> artifacts, PresentationType presentationType) throws OseeCoreException {
Displays.ensureInDisplayThread(new Runnable() {
@Override
public void run() {
try {
IWorkbenchPage activePage = AWorkbench.getActivePage();
for (Artifact artifact : artifacts) {
Integer attributeId = artifact.getAttributeIds(GraphitiDiagram).get(0);
URI diagramUri = URI.createURI(String.format("osee://branch/%d/artifact/%s/attribute/%d",
artifact.getBranchId(), artifact.getUuid(), attributeId));
DiagramEditorInput editorInput = new DiagramEditorInput(diagramUri, null);
activePage.openEditor(editorInput, GraphitiDiagramArtifactEditor.EDITOR_ID, true);
}
} catch (Exception ex) {
OseeLog.log(GraphitiRenderer.class, OseeLevel.SEVERE_POPUP, ex);
}
}
});
}
}
|