|
Added
Link Here
|
| 1 |
package org.eclipse.ui.internal; |
| 2 |
|
| 3 |
import java.util.HashSet; |
| 4 |
import java.util.Set; |
| 5 |
import org.eclipse.core.runtime.IConfigurationElement; |
| 6 |
import org.eclipse.core.runtime.Platform; |
| 7 |
import org.eclipse.core.runtime.dynamichelpers.IExtensionTracker; |
| 8 |
import org.eclipse.ui.IPageLayout; |
| 9 |
import org.eclipse.ui.IViewLayout; |
| 10 |
import org.eclipse.ui.PlatformUI; |
| 11 |
import org.eclipse.ui.internal.e4.compatibility.ModeledPageLayout; |
| 12 |
import org.eclipse.ui.internal.registry.IWorkbenchRegistryConstants; |
| 13 |
import org.eclipse.ui.internal.registry.RegistryReader; |
| 14 |
|
| 15 |
/** |
| 16 |
* A strategy to read perspective extension from the registry. |
| 17 |
* A pespective extension is one of a view, viewAction, perspAction, |
| 18 |
* newWizardAction, or actionSet. |
| 19 |
*/ |
| 20 |
public class PerspectiveExtensionReader extends RegistryReader { |
| 21 |
private String targetID; |
| 22 |
|
| 23 |
private ModeledPageLayout pageLayout; |
| 24 |
|
| 25 |
private Set includeOnlyTags = null; |
| 26 |
|
| 27 |
private static final String VAL_LEFT = "left";//$NON-NLS-1$ |
| 28 |
|
| 29 |
private static final String VAL_RIGHT = "right";//$NON-NLS-1$ |
| 30 |
|
| 31 |
private static final String VAL_TOP = "top";//$NON-NLS-1$ |
| 32 |
|
| 33 |
private static final String VAL_BOTTOM = "bottom";//$NON-NLS-1$ |
| 34 |
|
| 35 |
private static final String VAL_STACK = "stack";//$NON-NLS-1$ |
| 36 |
|
| 37 |
private static final String VAL_FAST = "fast";//$NON-NLS-1$ |
| 38 |
|
| 39 |
private static final String VAL_TRUE = "true";//$NON-NLS-1$ |
| 40 |
|
| 41 |
// VAL_FALSE added by dan_rubel@instantiations.com |
| 42 |
// TODO: this logic is backwards... we should be checking for true, but |
| 43 |
// technically this is API now... |
| 44 |
private static final String VAL_FALSE = "false";//$NON-NLS-1$ |
| 45 |
|
| 46 |
private IExtensionTracker tracker; |
| 47 |
|
| 48 |
/** |
| 49 |
* PerspectiveExtensionReader constructor.. |
| 50 |
*/ |
| 51 |
public PerspectiveExtensionReader() { |
| 52 |
// do nothing |
| 53 |
} |
| 54 |
|
| 55 |
/** |
| 56 |
* Read the view extensions within a registry. |
| 57 |
* |
| 58 |
* @param extensionTracker the tracker |
| 59 |
* @param id the id |
| 60 |
* @param out the layout |
| 61 |
*/ |
| 62 |
public void extendLayout(IExtensionTracker extensionTracker, String id, ModeledPageLayout out) { |
| 63 |
tracker = extensionTracker; |
| 64 |
targetID = id; |
| 65 |
pageLayout = out; |
| 66 |
readRegistry(Platform.getExtensionRegistry(), PlatformUI.PLUGIN_ID, |
| 67 |
IWorkbenchRegistryConstants.PL_PERSPECTIVE_EXTENSIONS); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Returns whether the given tag should be included. |
| 72 |
*/ |
| 73 |
private boolean includeTag(String tag) { |
| 74 |
return includeOnlyTags == null || includeOnlyTags.contains(tag); |
| 75 |
} |
| 76 |
|
| 77 |
/** |
| 78 |
* Process an action set. |
| 79 |
*/ |
| 80 |
private boolean processActionSet(IConfigurationElement element) { |
| 81 |
String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID); |
| 82 |
if (id != null) { |
| 83 |
pageLayout.addActionSet(id); |
| 84 |
} |
| 85 |
return true; |
| 86 |
} |
| 87 |
|
| 88 |
/** |
| 89 |
* Process an extension. |
| 90 |
* Assumption: Extension is for current perspective. |
| 91 |
*/ |
| 92 |
private boolean processExtension(IConfigurationElement element) { |
| 93 |
IConfigurationElement[] children = element.getChildren(); |
| 94 |
for (int nX = 0; nX < children.length; nX++) { |
| 95 |
IConfigurationElement child = children[nX]; |
| 96 |
String type = child.getName(); |
| 97 |
if (includeTag(type)) { |
| 98 |
boolean result = false; |
| 99 |
if (type.equals(IWorkbenchRegistryConstants.TAG_ACTION_SET)) { |
| 100 |
result = processActionSet(child); |
| 101 |
} else if (type.equals(IWorkbenchRegistryConstants.TAG_VIEW)) { |
| 102 |
result = processView(child); |
| 103 |
} else if (type.equals(IWorkbenchRegistryConstants.TAG_VIEW_SHORTCUT)) { |
| 104 |
result = processViewShortcut(child); |
| 105 |
} else if (type.equals(IWorkbenchRegistryConstants.TAG_NEW_WIZARD_SHORTCUT)) { |
| 106 |
result = processWizardShortcut(child); |
| 107 |
} else if (type.equals(IWorkbenchRegistryConstants.TAG_PERSP_SHORTCUT)) { |
| 108 |
result = processPerspectiveShortcut(child); |
| 109 |
} else if (type.equals(IWorkbenchRegistryConstants.TAG_SHOW_IN_PART)) { |
| 110 |
result = processShowInPart(child); |
| 111 |
} else if (type.equals(IWorkbenchRegistryConstants.TAG_HIDDEN_MENU_ITEM)) { |
| 112 |
result = processHiddenMenuItem(child); |
| 113 |
} else if (type.equals(IWorkbenchRegistryConstants.TAG_HIDDEN_TOOLBAR_ITEM)) { |
| 114 |
result = processHiddenToolBarItem(child); |
| 115 |
} |
| 116 |
if (!result) { |
| 117 |
WorkbenchPlugin.log("Unable to process element: " + //$NON-NLS-1$ |
| 118 |
type |
| 119 |
+ " in perspective extension: " + //$NON-NLS-1$ |
| 120 |
element.getDeclaringExtension() |
| 121 |
.getUniqueIdentifier()); |
| 122 |
} |
| 123 |
} |
| 124 |
} |
| 125 |
return true; |
| 126 |
} |
| 127 |
|
| 128 |
/** |
| 129 |
* Process a perspective shortcut |
| 130 |
*/ |
| 131 |
private boolean processPerspectiveShortcut(IConfigurationElement element) { |
| 132 |
String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID); |
| 133 |
if (id != null) { |
| 134 |
pageLayout.addPerspectiveShortcut(id); |
| 135 |
} |
| 136 |
return true; |
| 137 |
} |
| 138 |
|
| 139 |
/** |
| 140 |
* Process a show in element. |
| 141 |
*/ |
| 142 |
private boolean processShowInPart(IConfigurationElement element) { |
| 143 |
String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID); |
| 144 |
if (id != null) { |
| 145 |
pageLayout.addShowInPart(id); |
| 146 |
} |
| 147 |
return true; |
| 148 |
} |
| 149 |
|
| 150 |
/** |
| 151 |
* Process a hidden menu item |
| 152 |
*/ |
| 153 |
private boolean processHiddenMenuItem(IConfigurationElement element) { |
| 154 |
String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID); |
| 155 |
if (id != null) { |
| 156 |
pageLayout.addHiddenMenuItemId(id); |
| 157 |
} |
| 158 |
return true; |
| 159 |
} |
| 160 |
|
| 161 |
/** |
| 162 |
* Process a hidden toolbar item |
| 163 |
*/ |
| 164 |
private boolean processHiddenToolBarItem(IConfigurationElement element) { |
| 165 |
String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID); |
| 166 |
if (id != null) { |
| 167 |
pageLayout.addHiddenToolBarItemId(id); |
| 168 |
} |
| 169 |
return true; |
| 170 |
} |
| 171 |
|
| 172 |
// processView(IConfigurationElement) modified by dan_rubel@instantiations.com |
| 173 |
/** |
| 174 |
* Process a view |
| 175 |
*/ |
| 176 |
private boolean processView(IConfigurationElement element) { |
| 177 |
// Get id, relative, and relationship. |
| 178 |
String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID); |
| 179 |
String relative = element.getAttribute(IWorkbenchRegistryConstants.ATT_RELATIVE); |
| 180 |
String relationship = element.getAttribute(IWorkbenchRegistryConstants.ATT_RELATIONSHIP); |
| 181 |
String ratioString = element.getAttribute(IWorkbenchRegistryConstants.ATT_RATIO); |
| 182 |
boolean visible = !VAL_FALSE.equals(element.getAttribute(IWorkbenchRegistryConstants.ATT_VISIBLE)); |
| 183 |
String closeable = element.getAttribute(IWorkbenchRegistryConstants.ATT_CLOSEABLE); |
| 184 |
String moveable = element.getAttribute(IWorkbenchRegistryConstants.ATT_MOVEABLE); |
| 185 |
String standalone = element.getAttribute(IWorkbenchRegistryConstants.ATT_STANDALONE); |
| 186 |
String showTitle = element.getAttribute(IWorkbenchRegistryConstants.ATT_SHOW_TITLE); |
| 187 |
|
| 188 |
// Default to 'false' |
| 189 |
String minVal = element.getAttribute(IWorkbenchRegistryConstants.ATT_MINIMIZED); |
| 190 |
boolean minimized = minVal != null && VAL_TRUE.equals(minVal); |
| 191 |
|
| 192 |
float ratio; |
| 193 |
|
| 194 |
if (id == null) { |
| 195 |
logMissingAttribute(element, IWorkbenchRegistryConstants.ATT_ID); |
| 196 |
return false; |
| 197 |
} |
| 198 |
if (relationship == null) { |
| 199 |
logMissingAttribute(element, IWorkbenchRegistryConstants.ATT_RELATIONSHIP); |
| 200 |
return false; |
| 201 |
} |
| 202 |
if (!VAL_FAST.equals(relationship) && relative == null) { |
| 203 |
logError( |
| 204 |
element, |
| 205 |
"Attribute '" + IWorkbenchRegistryConstants.ATT_RELATIVE + "' not defined. This attribute is required when " + IWorkbenchRegistryConstants.ATT_RELATIONSHIP + "=\"" + relationship + "\"."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
| 206 |
return false; |
| 207 |
} |
| 208 |
|
| 209 |
// Get the ratio. |
| 210 |
if (ratioString == null) { |
| 211 |
// The ratio has not been specified. |
| 212 |
ratio = IPageLayout.NULL_RATIO; |
| 213 |
} else { |
| 214 |
try { |
| 215 |
ratio = new Float(ratioString).floatValue(); |
| 216 |
} catch (NumberFormatException e) { |
| 217 |
return false; |
| 218 |
} |
| 219 |
// If the ratio is outside the allowable range, mark it as invalid. |
| 220 |
if (ratio < IPageLayout.RATIO_MIN || ratio > IPageLayout.RATIO_MAX) { |
| 221 |
ratio = IPageLayout.INVALID_RATIO; |
| 222 |
} |
| 223 |
} |
| 224 |
|
| 225 |
// Get relationship details. |
| 226 |
boolean stack = false; |
| 227 |
boolean fast = false; |
| 228 |
int intRelation = 0; |
| 229 |
if (relationship.equals(VAL_LEFT)) { |
| 230 |
intRelation = IPageLayout.LEFT; |
| 231 |
} else if (relationship.equals(VAL_RIGHT)) { |
| 232 |
intRelation = IPageLayout.RIGHT; |
| 233 |
} else if (relationship.equals(VAL_TOP)) { |
| 234 |
intRelation = IPageLayout.TOP; |
| 235 |
} else if (relationship.equals(VAL_BOTTOM)) { |
| 236 |
intRelation = IPageLayout.BOTTOM; |
| 237 |
} else if (relationship.equals(VAL_STACK)) { |
| 238 |
stack = true; |
| 239 |
} else if (relationship.equals(VAL_FAST)) { |
| 240 |
fast = true; |
| 241 |
} else { |
| 242 |
return false; |
| 243 |
} |
| 244 |
|
| 245 |
if (visible) { |
| 246 |
// If adding a view (not just a placeholder), remove any existing placeholder. |
| 247 |
// See bug 85948 [Perspectives] Adding register & expressions view by default to debug perspective fails |
| 248 |
pageLayout.removePlaceholder(id); |
| 249 |
} |
| 250 |
|
| 251 |
// If stack .. |
| 252 |
if (stack) { |
| 253 |
if (visible) { |
| 254 |
pageLayout.stackView(id, relative, true); |
| 255 |
} else { |
| 256 |
pageLayout.stackView(id, relative, false); |
| 257 |
} |
| 258 |
} |
| 259 |
|
| 260 |
// If the view is a fast view... |
| 261 |
else if (fast) { |
| 262 |
if (ratio == IPageLayout.NULL_RATIO) { |
| 263 |
// The ratio has not been specified. |
| 264 |
pageLayout.addFastView(id); |
| 265 |
} else { |
| 266 |
pageLayout.addFastView(id, ratio); |
| 267 |
} |
| 268 |
} else { |
| 269 |
|
| 270 |
// The view is a regular view. |
| 271 |
// If the ratio is not specified or is invalid, use the default ratio. |
| 272 |
if (ratio == IPageLayout.NULL_RATIO |
| 273 |
|| ratio == IPageLayout.INVALID_RATIO) { |
| 274 |
ratio = IPageLayout.DEFAULT_VIEW_RATIO; |
| 275 |
} |
| 276 |
|
| 277 |
if (visible) { |
| 278 |
if (VAL_TRUE.equals(standalone)) { |
| 279 |
pageLayout.addStandaloneView(id, !VAL_FALSE |
| 280 |
.equals(showTitle), intRelation, ratio, relative); |
| 281 |
} else { |
| 282 |
pageLayout.addView(id, intRelation, ratio, relative, minimized); |
| 283 |
} |
| 284 |
} else { |
| 285 |
// Fix for 99155, CGross (schtoo@schtoo.com) |
| 286 |
// Adding standalone placeholder for standalone views |
| 287 |
if (VAL_TRUE.equals(standalone)) { |
| 288 |
pageLayout.addStandaloneViewPlaceholder(id, intRelation, |
| 289 |
ratio, relative, !VAL_FALSE.equals(showTitle)); |
| 290 |
} else { |
| 291 |
pageLayout.addPlaceholder(id, intRelation, ratio, relative); |
| 292 |
} |
| 293 |
} |
| 294 |
} |
| 295 |
IViewLayout viewLayout = pageLayout.getViewLayout(id); |
| 296 |
// may be null if it's been filtered by activity |
| 297 |
if (viewLayout != null) { |
| 298 |
if (closeable != null) { |
| 299 |
viewLayout.setCloseable(!VAL_FALSE.equals(closeable)); |
| 300 |
} |
| 301 |
if (moveable != null) { |
| 302 |
viewLayout.setMoveable(!VAL_FALSE.equals(moveable)); |
| 303 |
} |
| 304 |
} |
| 305 |
|
| 306 |
return true; |
| 307 |
} |
| 308 |
|
| 309 |
/** |
| 310 |
* Process a view shortcut |
| 311 |
*/ |
| 312 |
private boolean processViewShortcut(IConfigurationElement element) { |
| 313 |
String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID); |
| 314 |
if (id != null) { |
| 315 |
pageLayout.addShowViewShortcut(id); |
| 316 |
} |
| 317 |
return true; |
| 318 |
} |
| 319 |
|
| 320 |
/** |
| 321 |
* Process a wizard shortcut |
| 322 |
*/ |
| 323 |
private boolean processWizardShortcut(IConfigurationElement element) { |
| 324 |
String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_ID); |
| 325 |
if (id != null) { |
| 326 |
pageLayout.addNewWizardShortcut(id); |
| 327 |
} |
| 328 |
return true; |
| 329 |
} |
| 330 |
|
| 331 |
protected boolean readElement(IConfigurationElement element) { |
| 332 |
String type = element.getName(); |
| 333 |
if (type.equals(IWorkbenchRegistryConstants.TAG_PERSPECTIVE_EXTENSION)) { |
| 334 |
String id = element.getAttribute(IWorkbenchRegistryConstants.ATT_TARGET_ID); |
| 335 |
if (targetID.equals(id) || "*".equals(id)) { //$NON-NLS-1$ |
| 336 |
if (tracker != null) { |
| 337 |
tracker.registerObject(element.getDeclaringExtension(), new DirtyPerspectiveMarker(id), IExtensionTracker.REF_STRONG); |
| 338 |
} |
| 339 |
return processExtension(element); |
| 340 |
} |
| 341 |
return true; |
| 342 |
} |
| 343 |
return false; |
| 344 |
} |
| 345 |
|
| 346 |
/** |
| 347 |
* Sets the tags to include. All others are ignored. |
| 348 |
* |
| 349 |
* @param tags the tags to include |
| 350 |
*/ |
| 351 |
public void setIncludeOnlyTags(String[] tags) { |
| 352 |
includeOnlyTags = new HashSet(); |
| 353 |
for (int i = 0; i < tags.length; i++) { |
| 354 |
includeOnlyTags.add(tags[i]); |
| 355 |
} |
| 356 |
} |
| 357 |
} |