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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
|
/*
* Created on Aug 16, 2011
*
* PLACE_YOUR_DISTRIBUTION_STATEMENT_RIGHT_HERE
*/
package org.eclipse.osee.framework.core.dsl.ui.integration.internal;
import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.DEFAULT_OPEN;
import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.GENERALIZED_EDIT;
import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.PRODUCE_ATTRIBUTE;
import static org.eclipse.osee.framework.ui.skynet.render.PresentationType.SPECIALIZED_EDIT;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.osee.framework.core.enums.CoreArtifactTypes;
import org.eclipse.osee.framework.core.enums.CoreAttributeTypes;
import org.eclipse.osee.framework.core.exception.OseeCoreException;
import org.eclipse.osee.framework.core.exception.OseeExceptions;
import org.eclipse.osee.framework.core.model.Branch;
import org.eclipse.osee.framework.core.operation.IOperation;
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.skynet.render.DefaultArtifactRenderer;
import org.eclipse.osee.framework.ui.skynet.render.FileSystemRenderer;
import org.eclipse.osee.framework.ui.skynet.render.PresentationType;
import org.eclipse.osee.framework.ui.skynet.render.WholeAttributeUpdateOperation;
import org.eclipse.osee.framework.ui.swt.Displays;
import org.eclipse.swt.program.Program;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
public class OseeDslTypeSheetRenderer extends FileSystemRenderer {
private static final String COMMAND_ID = "org.eclipse.osee.framework.core.dsl.OseeDslTypeSheet.editor.command";
@Override
public String getName() {
return "OseeDsl Editor";
}
@Override
public DefaultArtifactRenderer newInstance() {
return new OseeDslTypeSheetRenderer();
}
@Override
public int getApplicabilityRating(PresentationType presentationType, IArtifact artifact) throws OseeCoreException {
Artifact aArtifact = artifact.getFullArtifact();
if (!presentationType.matches(GENERALIZED_EDIT, PRODUCE_ATTRIBUTE) && !aArtifact.isHistorical()) {
if (aArtifact.isOfType(CoreArtifactTypes.OseeTypeDefinition)) {
return ARTIFACT_TYPE_MATCH;
}
}
return NO_MATCH;
}
@Override
public List<String> getCommandIds(CommandGroup commandGroup) {
ArrayList<String> commandIds = new ArrayList<String>(1);
if (commandGroup.isEdit()) {
commandIds.add(COMMAND_ID);
}
return commandIds;
}
@Override
public boolean supportsCompare() {
return true;
}
@SuppressWarnings("unused")
@Override
public void open(final List<Artifact> artifacts, PresentationType presentationType) throws OseeCoreException {
final PresentationType resultantpresentationType =
presentationType == DEFAULT_OPEN ? SPECIALIZED_EDIT : presentationType;
Displays.ensureInDisplayThread(new Runnable() {
@Override
public void run() {
if (!artifacts.isEmpty()) {
try {
IFile file = renderToFile(artifacts, resultantpresentationType);
if (file != null) {
IWorkbench workbench = PlatformUI.getWorkbench();
IWorkbenchPage page = workbench.getActiveWorkbenchWindow().getActivePage();
IDE.openEditor(page, file);
}
} catch (CoreException ex) {
OseeLog.log(Activator.class, OseeLevel.SEVERE_POPUP, ex);
}
}
}
});
}
@SuppressWarnings("unused")
@Override
public String getAssociatedExtension(Artifact artifact) throws OseeCoreException {
return "osee";
}
@Override
public InputStream getRenderInputStream(PresentationType presentationType, List<Artifact> artifacts) throws OseeCoreException {
Artifact artifact = artifacts.iterator().next();
StringBuilder builder = new StringBuilder();
builder.append(artifact.getSoleAttributeValueAsString(CoreAttributeTypes.UriGeneralStringData, ""));
InputStream inputStream = null;
try {
inputStream = new ByteArrayInputStream(builder.toString().getBytes("UTF-8"));
} catch (UnsupportedEncodingException ex) {
OseeExceptions.wrapAndThrow(ex);
}
return inputStream;
}
@Override
public Program getAssociatedProgram(Artifact artifact) throws OseeCoreException {
throw new OseeCoreException("should not be called");
}
@Override
protected IOperation getUpdateOperation(File file, List<Artifact> artifacts, Branch branch, PresentationType presentationType) {
return new WholeAttributeUpdateOperation(file, artifacts.get(0), CoreAttributeTypes.UriGeneralStringData);
}
}
|