KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > omg > lifl > eclipse > plugin > utils > WorkBenchHelper


1 /*====================================================================
2
3 OpenCCM: The Open CORBA Component Model Platform
4 Copyright (C) 2000-2003 USTL - LIFL - GOAL
5 Contact: openccm-team@objectweb.org
6
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or any later version.
11
12 This library is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 Lesser General Public License for more details.
16
17 You should have received a copy of the GNU Lesser General Public
18 License along with this library; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 USA
21
22 Initial developer(s): Jerome Offroy.
23 Contributor(s): ______________________________________.
24
25 ====================================================================*/

26 /*
27  * Created on 23 juin 2003 by jerome OFFROY (offroy@lifl.fr)
28  *
29  */

30 package org.omg.lifl.eclipse.plugin.utils;
31
32 import org.eclipse.core.resources.IResource;
33 import org.eclipse.core.runtime.IAdaptable;
34 import org.eclipse.jface.dialogs.MessageDialog;
35 import org.eclipse.jface.viewers.ISelection;
36 import org.eclipse.jface.viewers.IStructuredSelection;
37 import org.eclipse.swt.widgets.Shell;
38 import org.omg.lifl.eclipse.plugin.project.OpenCCM.MainPlugin;
39
40 /**
41  * @author offroy
42  *
43  */

44 public class WorkBenchHelper {
45     public static void log() {
46         Shell shell = new Shell();
47     
48         MessageDialog.openInformation(
49             shell,
50             "PopUpMenu Plug-in",
51             "Launch Shell was executed.\nOn ressource : \n"
52                 + "filename = "
53                 + WorkBenchHelper.getSelectedRessourceFileName()
54                 + "\n"
55                 + "full filename = "
56                 + WorkBenchHelper.getSelectedRessourceFullFileName()
57                 + "\n"
58                 + "path = "
59                 + WorkBenchHelper.getSelectedRessourcePath()
60                 + "\n"
61                 + "full path = "
62                 + WorkBenchHelper.getSelectedRessourceFullPath()
63                 + "\n"
64                 + "extension = "
65                 + WorkBenchHelper.getSelectedRessourceExtension()
66                 + "\n"
67                 );
68     }
69
70     protected static IResource getRessource() {
71         Object JavaDoc selection = null;
72         ISelection currentSelection =
73                 MainPlugin
74                 .getDefault()
75                 .getWorkbench()
76                 .getActiveWorkbenchWindow()
77                 .getSelectionService()
78                 .getSelection();
79         if ((currentSelection != null)
80             && (currentSelection instanceof IStructuredSelection))
81             selection =
82                 ((IStructuredSelection) currentSelection).getFirstElement();
83         IResource resource = null;
84         if (selection instanceof IAdaptable)
85             resource =
86                 (IResource) ((IAdaptable) selection).getAdapter(
87                     IResource.class);
88         return resource;
89     }
90
91     /**
92      * @return a String representing the selected ressource 's
93      * in the current view of the Eclipse WorkBench
94      * filename
95      */

96     public static String JavaDoc getSelectedRessourceFileName() {
97         return getRessource().getFullPath().lastSegment();
98     }
99
100     /**
101      * @return a String representing the selected ressource
102      * in the current view of the Eclipse WorkBench
103      * full filename in the File System
104      */

105     public static String JavaDoc getSelectedRessourceFullFileName() {
106         return getRessource().getLocation().toOSString();
107     }
108
109     /**
110      * @return a String representing the selected ressource
111      * in the current view of the Eclipse WorkBench
112      * path relative to Workspace
113      */

114     public static String JavaDoc getSelectedRessourcePath() {
115         return getRessource().getFullPath().toOSString();
116     }
117
118     /**
119      * @return a String representing the selected ressource
120      * in the current view of the Eclipse WorkBench
121      * full path in the File System
122      */

123     public static String JavaDoc getSelectedRessourceFullPath() {
124         return getRessource().getLocation().removeLastSegments(1).toOSString();
125     }
126
127     /**
128      * @return a String representing the selected ressource
129      * in the current view of the Eclipse WorkBench
130      * extension
131      */

132     public static String JavaDoc getSelectedRessourceExtension() {
133         return getRessource().getFileExtension();
134     }
135
136     /**
137      * @return a String representing the selected ressource
138      * in the current view of the Eclipse WorkBench
139      * project name
140      */

141     public static String JavaDoc getSelectedRessourceProjectName() {
142         return getRessource().getProject().getName();
143     }
144     
145     
146
147 }
148
Popular Tags