KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > derby > ui > util > SelectionUtil


1 /*
2
3     Derby - Class org.apache.derby.ui.util.SelectionUtil
4     
5     Licensed to the Apache Software Foundation (ASF) under one or more
6     contributor license agreements. See the NOTICE file distributed with
7     this work for additional information regarding copyright ownership.
8     The ASF licenses this file to you under the Apache License, Version 2.0
9     (the "License"); you may not use this file except in compliance with
10     the License. You may obtain a copy of the License at
11     
12        http://www.apache.org/licenses/LICENSE-2.0
13     
14     Unless required by applicable law or agreed to in writing, software
15     distributed under the License is distributed on an "AS IS" BASIS,
16     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17     See the License for the specific language governing permissions and
18     limitations under the License.
19
20 */

21
22 package org.apache.derby.ui.util;
23
24 import org.eclipse.core.resources.IProject;
25 import org.eclipse.core.runtime.CoreException;
26 import org.eclipse.core.runtime.IStatus;
27 import org.eclipse.jdt.core.IJavaProject;
28 import org.eclipse.jface.viewers.ISelection;
29 import org.eclipse.jface.viewers.IStructuredSelection;
30
31
32 public class SelectionUtil {
33     public static IProject findSelectedProject(ISelection selection) {
34         IProject currentProject = null;
35         if (selection != null) {
36             if (selection instanceof IStructuredSelection) {
37                 IStructuredSelection ss = (IStructuredSelection)selection;
38                 Object JavaDoc obj = ss.getFirstElement();
39                 if (obj instanceof IProject) {
40                     currentProject = (IProject)obj;
41                 }
42             }
43         }
44         return currentProject;
45     }
46     
47      public static IJavaProject findSelectedJavaProject(ISelection selection) {
48         IJavaProject currentProject = null;
49         if (selection != null) {
50             if (selection instanceof IStructuredSelection) {
51                 IStructuredSelection ss = (IStructuredSelection)selection;
52                 Object JavaDoc obj = ss.getFirstElement();
53                 if (obj instanceof IJavaProject) {
54                     currentProject = (IJavaProject)obj;
55                 }
56             }
57         }
58         return currentProject;
59     }
60     
61     public static String JavaDoc getStatusMessages(Exception JavaDoc e) {
62         String JavaDoc msg = e.getMessage();
63         if (e instanceof CoreException) {
64             CoreException ce = (CoreException)e;
65             IStatus status = ce.getStatus();
66             IStatus[] children = status.getChildren();
67             for (int i = 0; i < children.length; i++)
68                 msg += "\n" + children[i].getMessage();
69             System.err.println(msg);
70             ce.printStackTrace(System.err);
71         }
72         return msg;
73     }
74 }
75
Popular Tags