View Javadoc

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.views.navigator.actions;
26  
27  
28  
29  import org.eclipse.jface.dialogs.MessageDialog;
30  import org.eclipse.jface.viewers.IStructuredSelection;
31  import org.eclipse.ui.*;
32  import org.wsmo.common.Entity;
33  import org.wsmostudio.runtime.LogManager;
34  import org.wsmostudio.ui.*;
35  import org.wsmostudio.ui.editors.WSMOEditorInput;
36  import org.wsmostudio.ui.editors.model.ObservableModel;
37  import org.wsmostudio.ui.views.navigator.WSMONavigator;
38  
39  /***
40   * An action belonging to the context menu of the <i>WSMO Navigator</i> view.
41   * This action opens the selected object with a suitable editor. It relies on
42   * the <code>org.wsmostudio.ui.editors.extension.ExtensionManager</code> to
43   * determine the most appropriate editor to use.
44   *
45   * @author not attributable
46   * @version $Revision: 1.11 $ $Date: 2006/01/09 12:51:14 $
47   */
48  
49  public class EditAction extends AbstractAction {
50      
51      public EditAction() {
52          super();
53      }
54      
55      public EditAction(WSMONavigator navi) {
56          super();
57          navigator = navi;
58      }
59      
60      public void run() {
61          Object target = 
62              ((IStructuredSelection)navigator.getTree().getSelection()).getFirstElement();
63          
64          if (target instanceof Entity 
65                  && Utils.isAProxy(target)) {
66              MessageDialog.openError(navigator.getSite().getShell(),
67                      "External Object",
68              "The selected object has no local definition and cannot be shown!");
69              return;
70          }
71          
72          String targetEditorID = WsmoUIPlugin.getDefault()
73                                              .getExtensionManager()
74                                              .locateEditorForEntity((Entity)target);
75          
76          if (targetEditorID != null) {
77              try {
78                  ObservableModel model = Utils.createEditorModel(target, 
79                          (ObservableModel)navigator.getWsmoInput().getAdapter(ObservableModel.class),
80                          targetEditorID);
81                  IEditorInput input = new WSMOEditorInput(target, model);
82                  PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
83                          .openEditor(input, targetEditorID);
84              }
85              catch(PartInitException pie) {
86                  LogManager.logError("Error opening editor \n"+pie.getMessage(), pie);
87              }
88          }
89      }
90  }
91  
92  /*
93   * $Log: EditAction.java,v $
94   * Revision 1.11  2006/01/09 12:51:14  alex_simov
95   * Copyright message in header updated
96   *
97   * Revision 1.10  2005/11/28 16:05:40  alex_simov
98   * wsmo4j proxies support improved
99   *
100  * Revision 1.9  2005/11/10 13:43:13  alex_simov
101  * wsmo-editors extension point update
102  *
103  * Revision 1.8  2005/11/09 16:13:22  alex_simov
104  * UIModels notification improved
105  *
106  * Revision 1.7  2005/11/02 08:49:55  alex_simov
107  * navigator actions are now extensions of org.wsmostudio.ui.navigator_content ext-point
108  *
109  * Revision 1.6  2005/08/04 15:04:46  alex_simov
110  * editor <-> subeditor dependency links established
111  *
112  * Revision 1.5  2005/07/29 15:08:03  alex_simov
113  * added javadoc: class description, footer
114  *
115  *
116  */
117