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;
26  
27  import org.eclipse.core.resources.IProject;
28  import org.eclipse.core.runtime.*;
29  import org.eclipse.jface.action.IAction;
30  import org.eclipse.jface.dialogs.*;
31  import org.eclipse.jface.viewers.*;
32  import org.eclipse.ui.*;
33  import org.wsmostudio.runtime.*;
34  
35  public class ProjectNamespaceAction implements IObjectActionDelegate {
36  
37      public static final QualifiedName PROJECT_NAMESPACE_NAME = new QualifiedName("WS", "project_namespace_name");
38      private IProject selected = null;
39      private IWorkbenchPart uiPart = null;
40      
41      public ProjectNamespaceAction() {
42      }
43  
44      public void setActivePart(IAction action, IWorkbenchPart targetPart) {
45          this.uiPart = targetPart;
46      }
47  
48      public void run(IAction action) {
49          if (false == selected.isAccessible()) {
50              MessageDialog.openError(
51                      this.uiPart.getSite().getShell(), 
52                      "Project Not Accessible", 
53                      "The selected project ("
54                      + this.selected.getName()
55                      +") in either closed or it does not exist!");
56              return;
57          }
58          String projectNS = null;
59          try {
60              projectNS = selected.getPersistentProperty(PROJECT_NAMESPACE_NAME);
61              if (projectNS == null) {
62                  projectNS = "";
63              }
64          }
65          catch(CoreException coreEx) {
66              LogManager.logError(coreEx);
67          }
68          InputDialog iDialog = new InputDialog(this.uiPart.getSite().getShell(),
69                  "Project Default Namespace",
70                  "Namespace URI : ",
71                  projectNS,
72                  new IInputValidator() {
73                      public String isValid(String input) {
74                          if (input.trim().length() == 0) {
75                              return null;
76                          }
77                          try {
78                              WSMORuntime.getRuntime().getWsmoFactory().createIRI(input);
79                          }
80                          catch(Throwable ex) {
81                              return ex.getMessage();
82                          }
83                          return null;
84                      }
85          });
86          if (iDialog.open() != Dialog.OK) {
87              return;
88          }
89          String newNS = iDialog.getValue();
90          if (newNS.equals(projectNS)) {
91              return;
92          }
93          try {
94              selected.setPersistentProperty(PROJECT_NAMESPACE_NAME, newNS);
95          }
96          catch(CoreException coreEx) {
97              LogManager.logError(coreEx);
98          }
99      }
100 
101     public void selectionChanged(IAction action, ISelection selection) {
102         
103         if (selection.isEmpty() 
104                 || false == selection instanceof IStructuredSelection) {
105             this.selected = null;
106             return;
107         }
108         IStructuredSelection sSel = (IStructuredSelection)selection;
109         if (sSel.size() != 1
110                 || false == sSel.getFirstElement() instanceof IProject) {
111             this.selected = null;
112         }
113         this.selected = (IProject)sSel.getFirstElement();
114     }
115 
116 }
117 
118 /*
119  * $Log$
120  * Revision 1.1  2006/02/07 11:40:22  alex_simov
121  * rfe[1423241]: WSMO projects have a default namespace property which
122  * facilitates new entities creation
123  *
124  */