1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 /***
19 * <p>Title: WSMO Studio</p>
20 * <p>Description: Semantic Web Service Editor</p>
21 * <p>Copyright: Copyright (c) 2004-2006</p>
22 * <p>Company: OntoText Lab. / SIRMA </p>
23 */
24
25 package org.wsmostudio.ui.editors;
26
27 import org.eclipse.core.resources.*;
28 import org.eclipse.core.runtime.*;
29 import org.eclipse.ui.*;
30 import org.eclipse.ui.ide.*;
31 import org.eclipse.ui.part.FileEditorInput;
32 import org.wsmo.common.TopEntity;
33 import org.wsmostudio.runtime.*;
34 import org.wsmostudio.ui.*;
35 import org.wsmostudio.ui.editors.text.WSMOTextEditor;
36
37 /***
38 * This component serves as a one way bridge from workspace resources (i.e. files)
39 * to WSMO objects. Its main task is to parse the content of a certain file
40 * (using the default WSML parser) and locate and open an appropriate editor
41 * for the result object.
42 *
43 * @author not attributable
44 * @version $Revision: 1.20 $ $Date: 2006/01/10 12:03:19 $
45 */
46
47 public class WSMOEditorLauncher implements IEditorLauncher {
48
49 public void open(IPath file) {
50
51 TopEntity[] topEntities = WSMORuntime.getIOManager().loadContent(file);
52 if (topEntities == null) {
53 showInTextEditor(file);
54 return;
55 }
56
57
58
59
60
61
62
63
64
65
66 WSMORuntime.getRuntime().registerEntity(topEntities[0], file);
67 try {
68 String targetEditorID = WsmoUIPlugin.getDefault()
69 .getExtensionManager()
70 .locateEditorForEntity(topEntities[0]);
71 if (targetEditorID == null) {
72 return;
73 }
74
75 WSMOEditorInput input = new WSMOEditorInput(
76 topEntities[0],
77 Utils.createEditorModel(topEntities[0], targetEditorID));
78 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
79 .openEditor(input, targetEditorID);
80 }
81 catch(PartInitException e) {
82 LogManager.logError(e);
83 }
84 }
85
86 private void showInTextEditor(IPath file) {
87 try {
88 IFile iFile = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(file);
89 WSMOTextEditor wte = (WSMOTextEditor) IDE.openEditor(
90 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
91 new FileEditorInput(iFile),
92 "org.wsmostudio.ui.editors.textEditor", true);
93 try {
94 IMarker[] markers = iFile.findMarkers(
95 "org.wsmostudio.runtime.wsmlmarker",
96 true,
97 1);
98 for (int i = 0; i < markers.length; i++) {
99 if (markers[i].getAttribute(IMarker.LINE_NUMBER, -1) != -1) {
100 IGotoMarker gotoMarker = (IGotoMarker)wte.getAdapter(IGotoMarker.class);
101 if (gotoMarker != null) {
102 gotoMarker.gotoMarker(markers[i]);
103 }
104 break;
105 }
106 }
107 }
108 catch(CoreException coreEx) {
109 LogManager.logError(coreEx);
110 }
111 }
112 catch(PartInitException pie) {
113 LogManager.logError(pie);
114 }
115 }
116
117 }
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152