01: /*
02:
03: Derby - Class org.apache.derby.ui.util.SelectionUtil
04:
05: Licensed to the Apache Software Foundation (ASF) under one or more
06: contributor license agreements. See the NOTICE file distributed with
07: this work for additional information regarding copyright ownership.
08: The ASF licenses this file to you under the Apache License, Version 2.0
09: (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: public class SelectionUtil {
32: public static IProject findSelectedProject(ISelection selection) {
33: IProject currentProject = null;
34: if (selection != null) {
35: if (selection instanceof IStructuredSelection) {
36: IStructuredSelection ss = (IStructuredSelection) selection;
37: Object obj = ss.getFirstElement();
38: if (obj instanceof IProject) {
39: currentProject = (IProject) obj;
40: }
41: }
42: }
43: return currentProject;
44: }
45:
46: public static IJavaProject findSelectedJavaProject(
47: ISelection selection) {
48: IJavaProject currentProject = null;
49: if (selection != null) {
50: if (selection instanceof IStructuredSelection) {
51: IStructuredSelection ss = (IStructuredSelection) selection;
52: Object obj = ss.getFirstElement();
53: if (obj instanceof IJavaProject) {
54: currentProject = (IJavaProject) obj;
55: }
56: }
57: }
58: return currentProject;
59: }
60:
61: public static String getStatusMessages(Exception e) {
62: String 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: }
|