Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 316303 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/e4/ui/internal/workbench/ContributionsAnalyzer.java (-1 / +1 lines)
Lines 138-144 Link Here
138
		}
138
		}
139
	}
139
	}
140
140
141
	private static boolean processAddition(final MMenu menuModel,
141
	public static boolean processAddition(final MMenu menuModel,
142
			final ArrayList<MMenuElement> menuContributionsToRemove,
142
			final ArrayList<MMenuElement> menuContributionsToRemove,
143
			MMenuContribution menuContribution, final HashSet<String> existingMenuIds,
143
			MMenuContribution menuContribution, final HashSet<String> existingMenuIds,
144
			HashSet<String> existingSeparatorNames) {
144
			HashSet<String> existingSeparatorNames) {
(-)src/org/eclipse/e4/ui/workbench/renderers/swt/MenuRenderer.java (-18 / +120 lines)
Lines 10-26 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.e4.ui.workbench.renderers.swt;
11
package org.eclipse.e4.ui.workbench.renderers.swt;
12
12
13
import java.util.ArrayList;
14
import java.util.HashMap;
15
import java.util.HashSet;
13
import org.eclipse.e4.core.contexts.IEclipseContext;
16
import org.eclipse.e4.core.contexts.IEclipseContext;
17
import org.eclipse.e4.core.contexts.RunAndTrack;
18
import org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer;
19
import org.eclipse.e4.ui.model.application.MApplication;
14
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
20
import org.eclipse.e4.ui.model.application.ui.MElementContainer;
15
import org.eclipse.e4.ui.model.application.ui.MUIElement;
21
import org.eclipse.e4.ui.model.application.ui.MUIElement;
16
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
22
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
17
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
23
import org.eclipse.e4.ui.model.application.ui.menu.MMenu;
24
import org.eclipse.e4.ui.model.application.ui.menu.MMenuContribution;
18
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
25
import org.eclipse.e4.ui.model.application.ui.menu.MMenuElement;
19
import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator;
26
import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator;
20
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl;
27
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl;
21
import org.eclipse.e4.ui.workbench.swt.modeling.MenuServiceFilter;
28
import org.eclipse.e4.ui.workbench.modeling.ExpressionContext;
22
import org.eclipse.emf.ecore.EObject;
29
import org.eclipse.emf.ecore.EObject;
23
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.SWT;
31
import org.eclipse.swt.events.DisposeEvent;
32
import org.eclipse.swt.events.DisposeListener;
24
import org.eclipse.swt.widgets.Control;
33
import org.eclipse.swt.widgets.Control;
25
import org.eclipse.swt.widgets.Decorations;
34
import org.eclipse.swt.widgets.Decorations;
26
import org.eclipse.swt.widgets.Menu;
35
import org.eclipse.swt.widgets.Menu;
Lines 31-50 Link Here
31
 * Create a contribute part.
40
 * Create a contribute part.
32
 */
41
 */
33
public class MenuRenderer extends SWTPartRenderer {
42
public class MenuRenderer extends SWTPartRenderer {
43
	private MApplication application;
44
	private HashMap<MMenu, ArrayList<ArrayList<MMenuElement>>> pendingCleanup = new HashMap<MMenu, ArrayList<ArrayList<MMenuElement>>>();
45
46
	@Override
47
	public void init(IEclipseContext context) {
48
		super.init(context);
49
		application = context.get(MApplication.class);
50
	}
34
51
35
	public Object createWidget(final MUIElement element, Object parent) {
52
	public Object createWidget(final MUIElement element, Object parent) {
36
		if (!(element instanceof MMenu))
53
		if (!(element instanceof MMenu))
37
			return null;
54
			return null;
38
55
39
		MMenu menuModel = (MMenu) element;
56
		final MMenu menuModel = (MMenu) element;
40
57
41
		Menu newMenu = null;
58
		Menu newMenu = null;
42
		if (parent instanceof Decorations) {
59
		if (parent instanceof Decorations) {
43
			MUIElement container = (MUIElement) ((EObject) element)
60
			MUIElement container = (MUIElement) ((EObject) element)
44
					.eContainer();
61
					.eContainer();
45
			if (container instanceof MWindow)
62
			if (container instanceof MWindow) {
46
				newMenu = new Menu((Decorations) parent, SWT.BAR);
63
				newMenu = new Menu((Decorations) parent, SWT.BAR);
47
			else {
64
				newMenu.addDisposeListener(new DisposeListener() {
65
					public void widgetDisposed(DisposeEvent e) {
66
						cleanUp(menuModel);
67
					}
68
				});
69
			} else {
48
				newMenu = new Menu((Decorations) parent, SWT.POP_UP);
70
				newMenu = new Menu((Decorations) parent, SWT.POP_UP);
49
			}
71
			}
50
		} else if (parent instanceof Menu) {
72
		} else if (parent instanceof Menu) {
Lines 71-97 Link Here
71
	 */
93
	 */
72
	@Override
94
	@Override
73
	public void processContents(MElementContainer<MUIElement> container) {
95
	public void processContents(MElementContainer<MUIElement> container) {
74
		Object obj = container.getWidget();
75
		Object menuModel = container;
76
		if ((obj instanceof Menu) && (((Menu) obj).getStyle() & SWT.BAR) != 0
77
				&& (menuModel instanceof MMenu)) {
78
			if (container.getChildren().isEmpty()) {
79
				return;
80
			}
81
			// this is a crazy fill and run
82
			IEclipseContext ctx = getContext(container);
83
			MenuServiceFilter filter = ctx.get(MenuServiceFilter.class);
84
			filter.showMenu(null, (Menu) obj, (MMenu) menuModel);
85
			return;
86
		}
87
		if (container.getChildren().size() == 0) {
96
		if (container.getChildren().size() == 0) {
88
			MMenuSeparator sep = MenuFactoryImpl.eINSTANCE
97
			MMenuSeparator sep = MenuFactoryImpl.eINSTANCE
89
					.createMenuSeparator();
98
					.createMenuSeparator();
90
			sep.setElementId("placeholder"); //$NON-NLS-1$
99
			sep.setElementId("menu.placeholder"); //$NON-NLS-1$
91
			container.getChildren().add(sep);
100
			container.getChildren().add(sep);
92
		}
101
		}
93
102
94
		super.processContents(container);
103
		super.processContents(container);
104
105
		Object obj = container.getWidget();
106
		Object menuObj = container;
107
		if ((obj instanceof Menu) && (((Menu) obj).getStyle() & SWT.BAR) != 0
108
				&& (menuObj instanceof MMenu)) {
109
			MMenu menuModel = (MMenu) menuObj;
110
			IEclipseContext ctx = getContext(container);
111
			ExpressionContext eContext = new ExpressionContext(ctx);
112
			ArrayList<MMenuContribution> toContribute = new ArrayList<MMenuContribution>();
113
			ContributionsAnalyzer.gatherMenuContributions(menuModel,
114
					application.getMenuContributions(),
115
					menuModel.getElementId(), toContribute, eContext, false);
116
			addMenuBarContributions(menuModel, toContribute, ctx, eContext);
117
		}
118
	}
119
120
	// this is similar in nature to:
121
	// org.eclipse.e4.ui.internal.workbench.ContributionsAnalyzer.addMenuContributions(MMenu,
122
	// ArrayList<MMenuContribution>, ArrayList<MMenuElement>)
123
	// the difference is it needs to add all the contributions and manage their
124
	// visiblility through a RAT
125
	private void addMenuBarContributions(final MMenu menuModel,
126
			ArrayList<MMenuContribution> toContribute,
127
			final IEclipseContext ctx, final ExpressionContext eContext) {
128
		HashSet<String> existingMenuIds = new HashSet<String>();
129
		HashSet<String> existingSeparatorNames = new HashSet<String>();
130
		for (MMenuElement child : menuModel.getChildren()) {
131
			String elementId = child.getElementId();
132
			if (child instanceof MMenu && elementId != null) {
133
				existingMenuIds.add(elementId);
134
			} else if (child instanceof MMenuSeparator && elementId != null) {
135
				existingSeparatorNames.add(elementId);
136
			}
137
		}
138
139
		boolean done = toContribute.size() == 0;
140
		while (!done) {
141
			ArrayList<MMenuContribution> curList = new ArrayList<MMenuContribution>(
142
					toContribute);
143
			int retryCount = toContribute.size();
144
			toContribute.clear();
145
146
			for (final MMenuContribution menuContribution : curList) {
147
				final ArrayList<MMenuElement> menuContributionsToRemove = new ArrayList<MMenuElement>();
148
				if (!ContributionsAnalyzer.processAddition(menuModel,
149
						menuContributionsToRemove, menuContribution,
150
						existingMenuIds, existingSeparatorNames)) {
151
					toContribute.add(menuContribution);
152
				} else {
153
					if (menuContribution.getVisibleWhen() != null) {
154
						ctx.runAndTrack(new RunAndTrack() {
155
							@Override
156
							public boolean changed(IEclipseContext context) {
157
								if (!menuModel.isToBeRendered()
158
										|| !menuModel.isVisible()
159
										|| menuModel.getWidget() == null) {
160
									return false;
161
								}
162
								boolean rc = ContributionsAnalyzer.isVisible(
163
										menuContribution, eContext);
164
								for (MMenuElement element : menuContributionsToRemove) {
165
									element.setToBeRendered(rc);
166
								}
167
								return true;
168
							}
169
						});
170
					}
171
					ArrayList<ArrayList<MMenuElement>> lists = pendingCleanup
172
							.get(menuModel);
173
					if (lists == null) {
174
						lists = new ArrayList<ArrayList<MMenuElement>>();
175
						pendingCleanup.put(menuModel, lists);
176
					}
177
					lists.add(menuContributionsToRemove);
178
				}
179
			}
180
			// We're done if the retryList is now empty (everything done) or
181
			// if the list hasn't changed at all (no hope)
182
			done = (toContribute.size() == 0)
183
					|| (toContribute.size() == retryCount);
184
		}
95
	}
185
	}
96
186
97
	private void setItemText(MMenu model, MenuItem item) {
187
	private void setItemText(MMenu model, MenuItem item) {
Lines 145-148 Link Here
145
		return super.getUIContainer(element);
235
		return super.getUIContainer(element);
146
	}
236
	}
147
237
238
	void cleanUp(MMenu menuModel) {
239
		ArrayList<ArrayList<MMenuElement>> lists = pendingCleanup
240
				.remove(menuModel);
241
		if (lists == null) {
242
			return;
243
		}
244
		for (ArrayList<MMenuElement> list : lists) {
245
			for (MMenuElement item : list) {
246
				menuModel.getChildren().remove(item);
247
			}
248
		}
249
	}
148
}
250
}
(-)LegacyIDE.e4xmi (-2 lines)
Lines 1-8 Link Here
1
<?xml version="1.0" encoding="ASCII"?>
1
<?xml version="1.0" encoding="ASCII"?>
2
<application:Application xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:application="http://www.eclipse.org/ui/2010/UIModel/application" xmlns:basic="http://www.eclipse.org/ui/2010/UIModel/application/ui/basic" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xsi:schemaLocation="http://www.eclipse.org/ui/2010/UIModel/application/ui/basic http://www.eclipse.org/ui/2010/UIModel/application#//ui/basic http://www.eclipse.org/ui/2010/UIModel/application/ui/menu http://www.eclipse.org/ui/2010/UIModel/application#//ui/menu" xmi:id="org.eclipse.e4.legacy.ide.application" elementId="org.eclipse.e4.legacy.ide.application">
2
<application:Application xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:application="http://www.eclipse.org/ui/2010/UIModel/application" xmlns:basic="http://www.eclipse.org/ui/2010/UIModel/application/ui/basic" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xsi:schemaLocation="http://www.eclipse.org/ui/2010/UIModel/application/ui/basic http://www.eclipse.org/ui/2010/UIModel/application#//ui/basic http://www.eclipse.org/ui/2010/UIModel/application/ui/menu http://www.eclipse.org/ui/2010/UIModel/application#//ui/menu" xmi:id="org.eclipse.e4.legacy.ide.application" elementId="org.eclipse.e4.legacy.ide.application">
3
  <children xsi:type="basic:TrimmedWindow" xmi:id="IDEWindow" elementId="IDEWindow" label="Eclipse SDK 4.0" width="1024" height="768">
3
  <children xsi:type="basic:TrimmedWindow" xmi:id="IDEWindow" elementId="IDEWindow" label="Eclipse SDK 4.0" width="1024" height="768">
4
    <mainMenu xmi:id="_UW9TUPr3Ed6gmo7caOxU9g" elementId="org.eclipse.ui.main.menu">
5
    </mainMenu>
6
    <trimBars xmi:id="org.eclipse.ui.main.toolbar" elementId="org.eclipse.ui.main.toolbar">
4
    <trimBars xmi:id="org.eclipse.ui.main.toolbar" elementId="org.eclipse.ui.main.toolbar">
7
    </trimBars>
5
    </trimBars>
8
  </children>
6
  </children>
(-)Eclipse (+357 lines)
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
}
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchPage.java (+2 lines)
Lines 2220-2225 Link Here
2220
				perspective, this, true);
2220
				perspective, this, true);
2221
		factory.createInitialLayout(modelLayout);
2221
		factory.createInitialLayout(modelLayout);
2222
		PerspectiveTagger.tagPerspective(modelPerspective, modelService);
2222
		PerspectiveTagger.tagPerspective(modelPerspective, modelService);
2223
		PerspectiveExtensionReader reader = new PerspectiveExtensionReader();
2224
		reader.extendLayout(getExtensionTracker(), perspective.getId(), modelLayout);
2223
2225
2224
		if (lastPerspective != null) {
2226
		if (lastPerspective != null) {
2225
			legacyWindow.firePerspectiveDeactivated(this, lastPerspective);
2227
			legacyWindow.firePerspectiveDeactivated(this, lastPerspective);
(-)Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java (-13 / +3 lines)
Lines 75-81 Link Here
75
import org.eclipse.e4.ui.workbench.modeling.ISaveHandler;
75
import org.eclipse.e4.ui.workbench.modeling.ISaveHandler;
76
import org.eclipse.e4.ui.workbench.modeling.IWindowCloseHandler;
76
import org.eclipse.e4.ui.workbench.modeling.IWindowCloseHandler;
77
import org.eclipse.e4.ui.workbench.renderers.swt.TrimmedPartLayout;
77
import org.eclipse.e4.ui.workbench.renderers.swt.TrimmedPartLayout;
78
import org.eclipse.e4.ui.workbench.swt.modeling.MenuServiceFilter;
79
import org.eclipse.jface.action.AbstractGroupMarker;
78
import org.eclipse.jface.action.AbstractGroupMarker;
80
import org.eclipse.jface.action.ActionContributionItem;
79
import org.eclipse.jface.action.ActionContributionItem;
81
import org.eclipse.jface.action.ContributionManager;
80
import org.eclipse.jface.action.ContributionManager;
Lines 480-500 Link Here
480
			mainMenu = MenuFactoryImpl.eINSTANCE.createMenu();
479
			mainMenu = MenuFactoryImpl.eINSTANCE.createMenu();
481
			mainMenu.setElementId("org.eclipse.ui.main.menu"); //$NON-NLS-1$
480
			mainMenu.setElementId("org.eclipse.ui.main.menu"); //$NON-NLS-1$
482
481
483
			model.setMainMenu(mainMenu);
484
		}
485
486
		if (mainMenu.getChildren().isEmpty()) {
487
			fill(mainMenu, menuManager);
482
			fill(mainMenu, menuManager);
483
			model.setMainMenu(mainMenu);
484
			Menu menu = (Menu) engine.createGui(mainMenu, model.getWidget());
485
			shell.setMenuBar(menu);
488
		}
486
		}
489
487
490
		Menu menu = (Menu) engine.createGui(mainMenu, model.getWidget());
491
		shell.setMenuBar(menu);
492
493
		// this is a crazy fill and run
494
		IEclipseContext ctx = model.getContext();
495
		MenuServiceFilter filter = ctx.get(MenuServiceFilter.class);
496
		filter.showMenu(null, menu, mainMenu);
497
498
		createProgressIndicator(shell);
488
		createProgressIndicator(shell);
499
		createHeapStatus(shell);
489
		createHeapStatus(shell);
500
	}
490
	}
(-)Eclipse UI/org/eclipse/ui/internal/e4/compatibility/ModeledPageLayout.java (+44 lines)
Lines 136-144 Link Here
136
	}
136
	}
137
137
138
	public void addFastView(String viewId) {
138
	public void addFastView(String viewId) {
139
		E4Util.unsupported("addFastView: " + viewId); //$NON-NLS-1$
139
	}
140
	}
140
141
141
	public void addFastView(String viewId, float ratio) {
142
	public void addFastView(String viewId, float ratio) {
143
		E4Util.unsupported("addFastView: " + viewId); //$NON-NLS-1$
142
	}
144
	}
143
145
144
	public void addNewWizardShortcut(String id) {
146
	public void addNewWizardShortcut(String id) {
Lines 179-184 Link Here
179
		insertView(viewId, relationship, ratio, refId, true, true);
181
		insertView(viewId, relationship, ratio, refId, true, true);
180
	}
182
	}
181
183
184
	public void addView(String viewId, int relationship, float ratio, String refId,
185
			boolean minimized) {
186
		if (minimized) {
187
			E4Util.unsupported("addView: use of minimized for " + viewId + " ref " + refId); //$NON-NLS-1$ //$NON-NLS-2$
188
		}
189
		insertView(viewId, relationship, ratio, refId, true, true);
190
	}
191
182
	public IFolderLayout createFolder(String folderId, int relationship,
192
	public IFolderLayout createFolder(String folderId, int relationship,
183
			float ratio, String refId) {
193
			float ratio, String refId) {
184
		MPartStack stack = insertStack(folderId, relationship, ratio, refId,
194
		MPartStack stack = insertStack(folderId, relationship, ratio, refId,
Lines 488-491 Link Here
488
		MUIElement element = modelService.find(id, toSearch);
498
		MUIElement element = modelService.find(id, toSearch);
489
		return element instanceof MPart ? (MPart) element : null;
499
		return element instanceof MPart ? (MPart) element : null;
490
	}
500
	}
501
502
	public void addHiddenMenuItemId(String id) {
503
		E4Util.unsupported("addHiddenMenuItemId: " + id); //$NON-NLS-1$
504
	}
505
506
	public void addHiddenToolBarItemId(String id) {
507
		E4Util.unsupported("addHiddenToolBarItemId: " + id); //$NON-NLS-1$
508
	}
509
510
	public void removePlaceholder(String id) {
511
		MUIElement refModel = findElement(perspModel, id);
512
		if (!(refModel instanceof MPlaceholder)) {
513
			E4Util.unsupported("removePlaceholder: failed to find " + id + ": " + refModel); //$NON-NLS-1$ //$NON-NLS-2$
514
			return;
515
		}
516
		MElementContainer<MUIElement> parent = refModel.getParent();
517
		if (parent != null) {
518
			parent.getChildren().remove(refModel);
519
		}
520
	}
521
522
	public void stackView(String id, String refId, boolean visible) {
523
		MUIElement refModel = findElement(perspModel, refId);
524
		if (refModel instanceof MPart || refModel instanceof MPlaceholder) {
525
			refModel = refModel.getParent();
526
		}
527
		if (!(refModel instanceof MPartStack)) {
528
			E4Util.unsupported("stackView: failed to find " + refId + " for " + id); //$NON-NLS-1$//$NON-NLS-2$
529
			return;
530
		}
531
		MStackElement viewModel = createViewModel(application, id, visible, page, partService,
532
				createReferences);
533
		((MPartStack) refModel).getChildren().add(viewModel);
534
	}
491
}
535
}

Return to bug 316303