1 /*
2 WSMO Studio - a Semantic Web Service Editor
3 Copyright (c) 2004-2006, OntoText Lab. / SIRMA Group
4
5 This library is free software; you can redistribute it and/or modify it under
6 the terms of the GNU Lesser General Public License as published by the Free
7 Software Foundation; either version 2.1 of the License, or (at your option)
8 any later version.
9 This library is distributed in the hope that it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 details.
13 You should have received a copy of the GNU Lesser General Public License along
14 with this library; if not, write to the Free Software Foundation, Inc.,
15 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
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 /* if (topEntities.length != 1) {
58 MessageDialog.openError(
59 PlatformUI.getWorkbench()
60 .getActiveWorkbenchWindow().getShell(),
61 "WSML Parse Error",
62 "More than one TopEntity found in the input file!");
63 return;
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) { // ignore unknown entities
72 return;
73 }
74 // open the topEntity editor
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 * $Log: WSMOEditorLauncher.java,v $
121 * Revision 1.20 2006/01/10 12:03:19 alex_simov
122 * on WSML parse failure, the text editor is opened pointing to the error location
123 *
124 * Revision 1.19 2006/01/09 12:51:13 alex_simov
125 * Copyright message in header updated
126 *
127 * Revision 1.18 2005/11/28 16:02:35 alex_simov
128 * imports organized
129 *
130 * Revision 1.17 2005/11/25 14:27:10 alex_simov
131 * runtime code refactoring
132 *
133 * Revision 1.16 2005/11/15 15:51:20 alex_simov
134 * test code fragment removed
135 *
136 * Revision 1.15 2005/11/10 13:46:32 alex_simov
137 * update
138 *
139 * Revision 1.14 2005/11/09 16:17:39 alex_simov
140 * UIModels notification improved
141 *
142 * Revision 1.13 2005/11/02 14:50:57 alex_simov
143 * moving to MVC architecture cont'd
144 *
145 * Revision 1.12 2005/11/02 08:57:02 alex_simov
146 * moving to a better Model-View-Contoller architecture
147 *
148 * Revision 1.11 2005/07/29 15:08:02 alex_simov
149 * added javadoc: class description, footer
150 *
151 *
152 */