Removed
Link Here
|
1 |
/******************************************************************************** |
2 |
* Copyright (c) 2002, 2008 IBM Corporation and others. All rights reserved. |
3 |
* This program and the accompanying materials are made available under the terms |
4 |
* of the Eclipse Public License v1.0 which accompanies this distribution, and is |
5 |
* available at http://www.eclipse.org/legal/epl-v10.html |
6 |
* |
7 |
* Initial Contributors: |
8 |
* The following IBM employees contributed to the Remote System Explorer |
9 |
* component that contains this file: David McKnight, Kushal Munir, |
10 |
* Michael Berger, David Dykstal, Phil Coulthard, Don Yantzi, Eric Simpson, |
11 |
* Emily Bruner, Mazen Faraj, Adrian Storisteanu, Li Ding, and Kent Hawley. |
12 |
* |
13 |
* Contributors: |
14 |
* Martin Oberhuber (Wind River) - [186773] split ISystemRegistryUI from ISystemRegistry |
15 |
* Tobias Schwarz (Wind River) - [173267] "empty list" should not be displayed |
16 |
* Martin Oberhuber (Wind River) - [190271] Move ISystemViewInputProvider to Core |
17 |
* Martin Oberhuber (Wind River) - [218524][api] Remove deprecated ISystemViewInputProvider#getShell() |
18 |
********************************************************************************/ |
19 |
|
20 |
package org.eclipse.rse.internal.ui.view; |
21 |
import org.eclipse.core.runtime.Platform; |
22 |
import org.eclipse.core.runtime.Preferences; |
23 |
import org.eclipse.jface.viewers.Viewer; |
24 |
import org.eclipse.rse.core.RSECorePlugin; |
25 |
import org.eclipse.rse.core.model.ISystemMessageObject; |
26 |
import org.eclipse.rse.core.model.ISystemRegistry; |
27 |
import org.eclipse.rse.core.model.ISystemViewInputProvider; |
28 |
import org.eclipse.rse.core.model.SystemMessageObject; |
29 |
import org.eclipse.rse.ui.ISystemMessages; |
30 |
import org.eclipse.rse.ui.ISystemPreferencesConstants; |
31 |
import org.eclipse.rse.ui.RSEUIPlugin; |
32 |
import org.eclipse.rse.ui.view.ISystemRemoteElementAdapter; |
33 |
import org.eclipse.rse.ui.view.ISystemViewElementAdapter; |
34 |
import org.eclipse.rse.ui.view.SystemAdapterHelpers; |
35 |
import org.eclipse.swt.widgets.Shell; |
36 |
|
37 |
|
38 |
|
39 |
/** |
40 |
* This is a base class that a provider of root nodes to the remote systems tree viewer part can |
41 |
* use as a parent class. |
42 |
*/ |
43 |
public abstract class SystemAbstractAPIProvider |
44 |
implements ISystemViewInputProvider |
45 |
{ |
46 |
protected Viewer viewer; |
47 |
protected ISystemRegistry sr; |
48 |
|
49 |
protected Object[] emptyList = new Object[0]; |
50 |
protected Object[] msgList = new Object[1]; |
51 |
/** |
52 |
* @deprecated Use {@link #checkForEmptyList(Object[], Object, boolean)} instead. |
53 |
*/ |
54 |
protected SystemMessageObject nullObject = null; |
55 |
protected SystemMessageObject canceledObject = null; |
56 |
protected SystemMessageObject errorObject = null; |
57 |
|
58 |
private Preferences fPrefStore = null; |
59 |
|
60 |
/** |
61 |
* Constructor |
62 |
*/ |
63 |
public SystemAbstractAPIProvider() |
64 |
{ |
65 |
super(); |
66 |
sr = RSECorePlugin.getTheSystemRegistry(); |
67 |
} |
68 |
|
69 |
/** |
70 |
* This is the method required by the IAdaptable interface. |
71 |
* Given an adapter class type, return an object castable to the type, or |
72 |
* null if this is not possible. |
73 |
*/ |
74 |
public Object getAdapter(Class adapterType) |
75 |
{ |
76 |
return Platform.getAdapterManager().getAdapter(this, adapterType); |
77 |
} |
78 |
|
79 |
/* |
80 |
* (non-Javadoc) |
81 |
* @see org.eclipse.rse.ui.view.ISystemViewInputProvider#setViewer(java.lang.Object) |
82 |
*/ |
83 |
public void setViewer(Object viewer) |
84 |
{ |
85 |
this.viewer = (Viewer)viewer; |
86 |
} |
87 |
|
88 |
/* |
89 |
* (non-Javadoc) |
90 |
* @see org.eclipse.rse.ui.view.ISystemViewInputProvider#getViewer() |
91 |
*/ |
92 |
public Object getViewer() |
93 |
{ |
94 |
return viewer; |
95 |
} |
96 |
|
97 |
protected final void initMsgObjects() |
98 |
{ |
99 |
nullObject = new SystemMessageObject(RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_EXPAND_EMPTY),ISystemMessageObject.MSGTYPE_EMPTY, null); |
100 |
canceledObject = new SystemMessageObject(RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_LIST_CANCELED),ISystemMessageObject.MSGTYPE_CANCEL, null); |
101 |
errorObject = new SystemMessageObject(RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_EXPAND_FAILED),ISystemMessageObject.MSGTYPE_ERROR, null); |
102 |
} |
103 |
|
104 |
/** |
105 |
* <i>Callable by subclasses. Do not override</i><br> |
106 |
* In getChildren, return <samp>checkForEmptyList(children, parent, true/false)<.samp> |
107 |
* versus your array directly. This method checks for a null array which is |
108 |
* not allowed and replaces it with an empty array. |
109 |
* If true is passed then it returns the "Empty list" message object if the array is null or empty |
110 |
* |
111 |
* @param children The list of children. |
112 |
* @param parent The parent for the children. |
113 |
* @param returnNullMsg <code>true</code> if an "Empty List" message should be returned. |
114 |
* @return The list of children, a list with the "Empty List" message object or an empty list. |
115 |
*/ |
116 |
protected Object[] checkForEmptyList(Object[] children, Object parent, boolean returnNullMsg) { |
117 |
if ((children == null) || (children.length == 0)) { |
118 |
if (fPrefStore == null) { |
119 |
fPrefStore = RSEUIPlugin.getDefault().getPluginPreferences(); |
120 |
} |
121 |
if (!returnNullMsg |
122 |
|| (fPrefStore != null && !fPrefStore |
123 |
.getBoolean(ISystemPreferencesConstants.SHOW_EMPTY_LISTS))) { |
124 |
return emptyList; |
125 |
} else { |
126 |
return new Object[] { |
127 |
new SystemMessageObject( |
128 |
RSEUIPlugin.getPluginMessage(ISystemMessages.MSG_EXPAND_EMPTY), |
129 |
ISystemMessageObject.MSGTYPE_EMPTY, |
130 |
parent)}; |
131 |
} |
132 |
} |
133 |
return children; |
134 |
} |
135 |
|
136 |
/** |
137 |
* In getChildren, return checkForNull(children, true/false) vs your array directly. |
138 |
* This method checks for a null array which not allow and replaces it with an empty array. |
139 |
* If true is passed then it returns the "Empty list" message object if the array is null or empty |
140 |
* |
141 |
* @deprecated Use {@link #checkForEmptyList(Object[], Object, boolean)} instead. |
142 |
*/ |
143 |
protected Object[] checkForNull(Object[] children, boolean returnNullMsg) |
144 |
{ |
145 |
if ((children == null) || (children.length==0)) |
146 |
{ |
147 |
if (!returnNullMsg) |
148 |
return emptyList; |
149 |
else |
150 |
{ |
151 |
if (nullObject == null) |
152 |
initMsgObjects(); |
153 |
msgList[0] = nullObject; |
154 |
return msgList; |
155 |
} |
156 |
} |
157 |
else |
158 |
return children; |
159 |
} |
160 |
|
161 |
/** |
162 |
* Return the "Operation cancelled by user" msg as an object array so can be used to answer getChildren() |
163 |
*/ |
164 |
protected Object[] getCancelledMessageObject() |
165 |
{ |
166 |
if (canceledObject == null) |
167 |
initMsgObjects(); |
168 |
msgList[0] = canceledObject; |
169 |
return msgList; |
170 |
} |
171 |
|
172 |
/** |
173 |
* Return the "Operation failed" msg as an object array so can be used to answer getChildren() |
174 |
*/ |
175 |
protected Object[] getFailedMessageObject() |
176 |
{ |
177 |
if (errorObject == null) |
178 |
initMsgObjects(); |
179 |
msgList[0] = errorObject; |
180 |
return msgList; |
181 |
} |
182 |
|
183 |
/** |
184 |
* Return true if we are listing connections or not, so we know whether we are interested in |
185 |
* connection-add events |
186 |
*/ |
187 |
public boolean showingConnections() |
188 |
{ |
189 |
return false; |
190 |
} |
191 |
|
192 |
// ------------------ |
193 |
// HELPER METHODS... |
194 |
// ------------------ |
195 |
/** |
196 |
* Returns the implementation of ISystemViewElement for the given |
197 |
* object. Returns null if the adapter is not defined or the |
198 |
* object is not adaptable. |
199 |
*/ |
200 |
protected ISystemViewElementAdapter getViewAdapter(Object o) |
201 |
{ |
202 |
return SystemAdapterHelpers.getViewAdapter(o); |
203 |
} |
204 |
|
205 |
/** |
206 |
* Returns the implementation of ISystemRemoteElement for the given |
207 |
* object. Returns null if this object does not adaptable to this. |
208 |
*/ |
209 |
protected ISystemRemoteElementAdapter getRemoteAdapter(Object o) |
210 |
{ |
211 |
return SystemAdapterHelpers.getRemoteAdapter(o); |
212 |
} |
213 |
} |