Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/internal/ModelUtils.java75
-rw-r--r--bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/internal/Position.java66
-rw-r--r--bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/internal/PositionInfo.java144
-rw-r--r--bundles/org.eclipse.ui.ide.application/LegacyIDE_fragment.e4xmi18
-rw-r--r--bundles/org.eclipse.ui.ide.application/META-INF/MANIFEST.MF3
-rw-r--r--bundles/org.eclipse.ui.ide.application/build.properties3
-rw-r--r--bundles/org.eclipse.ui.ide.application/plugin.xml7
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java249
-rw-r--r--bundles/org.eclipse.ui.workbench/LegacyIDE.e4xmi7
9 files changed, 507 insertions, 65 deletions
diff --git a/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/internal/ModelUtils.java b/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/internal/ModelUtils.java
index f96b4e5cada..a3e820faa47 100644
--- a/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/internal/ModelUtils.java
+++ b/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/internal/ModelUtils.java
@@ -7,6 +7,8 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * René Brandstetter - Bug 411821 - [QuickAccess] Contribute SearchField
+ * through a fragment or other means
*******************************************************************************/
package org.eclipse.e4.ui.model.internal;
@@ -83,38 +85,46 @@ public class ModelUtils {
boolean flag = true;
if( positionInList != null && positionInList.trim().length() != 0 ) {
int index = -1;
- if( positionInList.startsWith("first") ) {
- index = 0;
- } else if( positionInList.startsWith("index:") ) {
- index = Integer.parseInt(positionInList.substring("index:".length()));
- } else if( positionInList.startsWith("before:") || positionInList.startsWith("after:") ) {
- String elementId;
- boolean before;
- if( positionInList.startsWith("before:") ) {
- elementId = positionInList.substring("before:".length());
- before = true;
- } else {
- elementId = positionInList.substring("after:".length());
- before = false;
- }
-
- int tmpIndex = -1;
- for( int i = 0; i < list.size(); i++ ) {
- if( elementId.equals(((MApplicationElement)list.get(i)).getElementId()) ) {
- tmpIndex = i;
- break;
- }
- }
-
- if( tmpIndex != -1 ) {
- if( before ) {
- index = tmpIndex;
- } else {
- index = tmpIndex + 1;
- }
- } else {
- System.err.println("Could not find element with Id '"+elementId+"'");
- }
+
+ PositionInfo posInfo = PositionInfo.parse(positionInList);
+
+ if( posInfo != null ){
+ switch (posInfo.getPosition()){
+ case FIRST:
+ index = 0;
+ break;
+
+ case INDEX:
+ index = posInfo.getPositionReferenceAsInteger();
+ break;
+
+ case BEFORE:
+ case AFTER:
+ int tmpIndex = -1;
+ String elementId = posInfo.getPositionReference();
+
+ for( int i = 0; i < list.size(); i++ ) {
+ if( elementId.equals(((MApplicationElement)list.get(i)).getElementId()) ) {
+ tmpIndex = i;
+ break;
+ }
+ }
+
+ if( tmpIndex != -1 ) {
+ if( posInfo.getPosition() == Position.BEFORE ) {
+ index = tmpIndex;
+ } else {
+ index = tmpIndex + 1;
+ }
+ } else {
+ System.err.println("Could not find element with Id '"+elementId+"'");
+ }
+
+ case LAST:
+ default:
+ // both no special operation, because the default is adding it at the last position
+ break;
+ }
} else {
System.err.println("Not a valid list position.");
}
@@ -208,5 +218,4 @@ public class ModelUtils {
return null;
}
-
}
diff --git a/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/internal/Position.java b/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/internal/Position.java
new file mode 100644
index 00000000000..36d33357cc5
--- /dev/null
+++ b/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/internal/Position.java
@@ -0,0 +1,66 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2013 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * René Brandstetter - Bug 411821 - [QuickAccess] Contribute SearchField
+ * through a fragment or other means
+ ******************************************************************************/
+
+package org.eclipse.e4.ui.model.internal;
+
+/**
+ * All the possible positioning values which can be used to contribute
+ * elements into the wanted place of a list.
+ *
+ * @author René Brandstetter
+ */
+public enum Position {
+ /** Add an element to the end of a list (absolute positioning). */
+ LAST("last"),
+
+ /** Add an element at the beginning of a list (absolute positioning). */
+ FIRST("first"),
+
+ /** Add an element before another named element (relative positioning). */
+ BEFORE("before:"),
+
+ /** Add an element after a named element (relative positioning). */
+ AFTER("after:"),
+
+ /** Add an element at a specific index (absolute positioning). */
+ INDEX("index:");
+
+ /** The prefix of the enum which is used in the positioning string. */
+ final String prefix;
+
+ private Position(String prefix) {
+ assert prefix != null : "Prefix required!";
+ this.prefix = prefix;
+ }
+
+ /**
+ * Find the {@link Position} enum value used in the given positioning
+ * string.
+ *
+ * @param positionInfo
+ * the positioning string (can be <code>null</code>, which would
+ * result in <code>null</code>)
+ * @return the {@link Position} which is mentioned in the positioning
+ * string, or <code>null</code> if none can be found
+ */
+ public static final Position find(String positionInfo) {
+ if (positionInfo == null || positionInfo.length() <= 0)
+ return null;
+
+ for (Position position : Position.values()) {
+ if (positionInfo.startsWith(position.prefix))
+ return position;
+ }
+
+ return null;
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/internal/PositionInfo.java b/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/internal/PositionInfo.java
new file mode 100644
index 00000000000..35c76d28b81
--- /dev/null
+++ b/bundles/org.eclipse.e4.ui.model.workbench/src/org/eclipse/e4/ui/model/internal/PositionInfo.java
@@ -0,0 +1,144 @@
+/*******************************************************************************
+ * Copyright (c) 2010, 2013 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * René Brandstetter - Bug 411821 - [QuickAccess] Contribute SearchField
+ * through a fragment or other means
+ ******************************************************************************/
+
+package org.eclipse.e4.ui.model.internal;
+
+/**
+ * A holder class for the full information to position an element in a list.
+ *
+ * @author René Brandstetter
+ */
+public final class PositionInfo {
+ /** The position type to use. */
+ private final Position position;
+
+ /**
+ * The additional positioning information which can be used to position an
+ * element relative to another element.
+ */
+ private final String positionReference;
+
+ /**
+ * The {@link PositionInfo} which represent an insert at the beginning of
+ * the list.
+ */
+ public static final PositionInfo FIRST = new PositionInfo(Position.FIRST, null);
+
+ /**
+ * The {@link PositionInfo} which represent an insert at the end of the
+ * list.
+ */
+ public static final PositionInfo LAST = new PositionInfo(Position.LAST, null);
+
+ /**
+ * Creates an instance of the PositionInfo.
+ *
+ * @param position
+ * the kind of the positioning
+ * @param positionReference
+ * additional information which is need to position an element
+ * (e.g.: index, ID of another element)
+ * @throws NullPointerException
+ * if the <code>position</code> is <code>null</code>
+ */
+ public PositionInfo(Position position, String positionReference) {
+ if (position == null) {
+ throw new NullPointerException("No position given!");
+ }
+
+ this.position = position;
+ this.positionReference = positionReference;
+ }
+
+ /**
+ * Returns the kind/type of positioning which should be used.
+ *
+ * @return the position
+ */
+ public Position getPosition() {
+ return position;
+ }
+
+ /**
+ * Returns additional information which is needed to place an element.
+ *
+ * @return the positionReference, or <code>null</code> if no additional information is given
+ */
+ public String getPositionReference() {
+ return positionReference;
+ }
+
+ /**
+ * Returns the additional information which is needed to place an element as
+ * an int.
+ *
+ * @return the positionReference as an int
+ * @throws NumberFormatException
+ * if the {@link #positionReference} can't be parsed to an int
+ * @throws NullPointerException
+ * if the {@link #positionReference} is <code>null</code>
+ */
+ public int getPositionReferenceAsInteger() {
+ return Integer.parseInt(positionReference);
+ }
+
+ /**
+ * Creates a {@link PositionInfo} object out of the given positioning
+ * string.
+ *
+ * <p>
+ * <b>Examples for a positioning string:</b>
+ * <ul>
+ * <li><code>last</code> - place an element to the end of a list</li>
+ * <li><code>first</code> - place an element to the beginning of a list</li>
+ * <li><code>index:3</code> - place an element at the provided index 3 in a
+ * list</li>
+ * <li><code>before:org.eclipse.test.id</code> - place an element in a list
+ * in front of the element with the ID "org.eclipse.test.id"</li>
+ * <li><code>after:org.eclipse.test.id</code> - place an element in a list
+ * after the element with the ID "org.eclipse.test.id"</li>
+ * </ul>
+ * </p>
+ *
+ * @param positionInfo
+ * the positioning string
+ * @return a {@link PositionInfo} which holds all the data mentioned in the
+ * positioning string, or <code>null</code> if the positioning
+ * string doesn't hold a positioning information
+ */
+ public static PositionInfo parse(String positionInfo) {
+ Position position = Position.find(positionInfo);
+ if (position != null) {
+ switch (position) {
+ case FIRST:
+ return PositionInfo.FIRST;
+
+ case LAST:
+ return PositionInfo.LAST;
+
+ default:
+ return new PositionInfo(position, positionInfo.substring(position.prefix.length()));
+ }
+ }
+
+ return null;
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder back = new StringBuilder(position.prefix);
+ if (positionReference != null) {
+ back.append(positionReference);
+ }
+ return back.toString();
+ }
+} \ No newline at end of file
diff --git a/bundles/org.eclipse.ui.ide.application/LegacyIDE_fragment.e4xmi b/bundles/org.eclipse.ui.ide.application/LegacyIDE_fragment.e4xmi
new file mode 100644
index 00000000000..bd3755220ec
--- /dev/null
+++ b/bundles/org.eclipse.ui.ide.application/LegacyIDE_fragment.e4xmi
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="ASCII"?>
+<fragment:ModelFragments xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:fragment="http://www.eclipse.org/ui/2010/UIModel/fragment" xmlns:menu="http://www.eclipse.org/ui/2010/UIModel/application/ui/menu" xmi:id="_sTbSsF4zEeO8pdiqk8eUfg">
+ <fragments xsi:type="fragment:StringModelFragment" xmi:id="_xyk_UF9tEeO-yojH_y4TJA" featurename="trimContributions" parentElementId="org.eclipse.e4.legacy.ide.application" positionInList="last">
+ <elements xsi:type="menu:TrimContribution" xmi:id="_2r10UF9tEeO-yojH_y4TJA" elementId="org.eclipse.ui.ide.application.trimcontribution.QuickAccess" parentId="org.eclipse.ui.main.toolbar" positionInParent="last">
+ <children xsi:type="menu:ToolControl" xmi:id="_76uUAF9tEeO-yojH_y4TJA" elementId="Spacer Glue" contributionURI="bundleclass://org.eclipse.e4.ui.workbench.renderers.swt/org.eclipse.e4.ui.workbench.renderers.swt.LayoutModifierToolControl">
+ <tags>glue</tags>
+ <tags>move_after:PerspectiveSpacer</tags>
+ </children>
+ <children xsi:type="menu:ToolControl" xmi:id="_8tJPcF9tEeO-yojH_y4TJA" elementId="SearchField" contributionURI="bundleclass://org.eclipse.ui.workbench/org.eclipse.ui.internal.quickaccess.SearchField">
+ <tags>move_after:Spacer Glue</tags>
+ </children>
+ <children xsi:type="menu:ToolControl" xmi:id="_9LgmcF9tEeO-yojH_y4TJA" elementId="Search-PS Glue" contributionURI="bundleclass://org.eclipse.e4.ui.workbench.renderers.swt/org.eclipse.e4.ui.workbench.renderers.swt.LayoutModifierToolControl">
+ <tags>glue</tags>
+ <tags>move_after:SearchField</tags>
+ </children>
+ </elements>
+ </fragments>
+</fragment:ModelFragments>
diff --git a/bundles/org.eclipse.ui.ide.application/META-INF/MANIFEST.MF b/bundles/org.eclipse.ui.ide.application/META-INF/MANIFEST.MF
index 6765d8b71ba..882a6216505 100644
--- a/bundles/org.eclipse.ui.ide.application/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.ui.ide.application/META-INF/MANIFEST.MF
@@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.6.0,4.0.0)",
org.eclipse.ui;bundle-version="[3.6.0,4.0.0)",
org.eclipse.ui.navigator.resources;bundle-version="[3.4.0,4.0.0)",
org.eclipse.core.net;bundle-version="[1.0.0,2.0.0)",
- org.eclipse.core.filesystem;bundle-version="1.3.0"
+ org.eclipse.core.filesystem;bundle-version="1.3.0",
+ org.eclipse.e4.ui.workbench
Export-Package: org.eclipse.ui.internal.ide.application;x-internal:=true,
org.eclipse.ui.internal.ide.application.dialogs;x-internal:=true
Import-Package: com.ibm.icu.text
diff --git a/bundles/org.eclipse.ui.ide.application/build.properties b/bundles/org.eclipse.ui.ide.application/build.properties
index 4f5c84bf726..e2cef74c386 100644
--- a/bundles/org.eclipse.ui.ide.application/build.properties
+++ b/bundles/org.eclipse.ui.ide.application/build.properties
@@ -15,5 +15,6 @@ bin.includes = META-INF/,\
plugin.xml,\
plugin.properties,\
about.html,\
- icons/
+ icons/,\
+ LegacyIDE_fragment.e4xmi
src.includes = about.html
diff --git a/bundles/org.eclipse.ui.ide.application/plugin.xml b/bundles/org.eclipse.ui.ide.application/plugin.xml
index 2989128fd50..6702ee6d1e0 100644
--- a/bundles/org.eclipse.ui.ide.application/plugin.xml
+++ b/bundles/org.eclipse.ui.ide.application/plugin.xml
@@ -139,4 +139,11 @@
</menu>
</menuContribution>
</extension>
+ <extension
+ id="id1"
+ point="org.eclipse.e4.workbench.model">
+ <fragment
+ uri="LegacyIDE_fragment.e4xmi">
+ </fragment>
+ </extension>
</plugin>
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
index 84cb75fc57a..9f84056c319 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchWindow.java
@@ -10,6 +10,8 @@
* Zhongwei Zhao - Bug 379495 - Two "Run" on top menu
* Patrick Chuong - Bug 391481 - Contributing perspectiveExtension, hiddenMenuItem
* removes a menu from multiple perspectives
+ * René Brandstetter - Bug 411821 - [QuickAccess] Contribute SearchField
+ * through a fragment or other means
*******************************************************************************/
package org.eclipse.ui.internal;
@@ -18,6 +20,7 @@ import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -69,6 +72,8 @@ import org.eclipse.e4.ui.model.application.ui.menu.MMenuSeparator;
import org.eclipse.e4.ui.model.application.ui.menu.MOpaqueMenuItem;
import org.eclipse.e4.ui.model.application.ui.menu.MToolControl;
import org.eclipse.e4.ui.model.application.ui.menu.impl.MenuFactoryImpl;
+import org.eclipse.e4.ui.model.internal.Position;
+import org.eclipse.e4.ui.model.internal.PositionInfo;
import org.eclipse.e4.ui.services.EContextService;
import org.eclipse.e4.ui.workbench.IPresentationEngine;
import org.eclipse.e4.ui.workbench.UIEvents;
@@ -81,6 +86,8 @@ import org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRendererFilter;
import org.eclipse.e4.ui.workbench.renderers.swt.TrimBarLayout;
import org.eclipse.e4.ui.workbench.renderers.swt.TrimmedPartLayout;
import org.eclipse.e4.ui.workbench.swt.factories.IRendererFactory;
+import org.eclipse.emf.ecore.EObject;
+import org.eclipse.emf.ecore.util.EcoreUtil;
import org.eclipse.jface.action.AbstractGroupMarker;
import org.eclipse.jface.action.CoolBarManager;
import org.eclipse.jface.action.GroupMarker;
@@ -324,6 +331,25 @@ public class WorkbenchWindow implements IWorkbenchWindow {
static final int BAR_SIZE = 23;
+ /** Marks the beginning of a tag which contains positioning information. */
+ static final String MOVE_TAG = "move_"; //$NON-NLS-1$
+
+ /**
+ * Ordered list of element IDs which belong to the QuickAccess
+ * {@link MToolControl}s.
+ *
+ * <p>
+ * Element IDs which belong to QuickAccess:
+ * <ul>
+ * <li><code>Spacer Glue</code></li>
+ * <li><code>SearchField</code></li>
+ * <li><code>Search-PS Glue</code></li>
+ * </ul>
+ * </p>
+ */
+ private static final List<String> QUICK_ACCESS_ELEMENT_IDS = Collections
+ .unmodifiableList(Arrays.asList("Spacer Glue", "SearchField", "Search-PS Glue")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+
/**
* Coolbar visibility change property.
*
@@ -573,6 +599,19 @@ public class WorkbenchWindow implements IWorkbenchWindow {
initializeDefaultServices();
+ /*
+ * Remove the second QuickAccess control if an older workspace is
+ * opened.
+ *
+ * An older workspace will create an ApplicationModel which already
+ * contains the QuickAccess elements, from the old
+ * "popuolateTopTrimContribution()" method. The new implementation of
+ * this method doesn't add the QuickAccess elements anymore but an old
+ * workbench.xmi still has these entries in it and so they need to be
+ * removed.
+ */
+ cleanLegacyQuickAccessContribution();
+
// register with the tracker
fireWindowOpening();
@@ -602,6 +641,10 @@ public class WorkbenchWindow implements IWorkbenchWindow {
modelService.getTrim(model, SideValue.LEFT);
modelService.getTrim(model, SideValue.RIGHT);
+ // move the QuickAccess ToolControl to the correct position (only if it
+ // exists)
+ positionQuickAccess();
+
Shell shell = (Shell) model.getWidget();
if (model.getMainMenu() == null) {
final MMenu mainMenu = MenuFactoryImpl.eINSTANCE.createMenu();
@@ -748,6 +791,17 @@ public class WorkbenchWindow implements IWorkbenchWindow {
final MTrimBar trimBar = getTopTrim();
// TODO why aren't these added as trim contributions
// that would remove everything from this method except the fill(*)
+ /*
+ * Reason Why: The setup() method which calls this method also calls the
+ * ActionBarAdvisor to fill the TopTrim-Bar. Both this and the
+ * ActionBarAdvisor fill method will be called after the entire
+ * application model and all its fragments have been build already. This
+ * leads to the effect that all the elements contributed via the
+ * application model would be placed in front of the elements
+ * contributed by the setup() method. (Means all the "Save", "Save All",
+ * and so on, buttons which are normally placed at the beginning of the
+ * trimbar (left) would be moved to the end of it (right).)
+ */
MToolControl spacerControl = (MToolControl) modelService.find("PerspectiveSpacer", model); //$NON-NLS-1$
if (spacerControl == null) {
spacerControl = MenuFactoryImpl.eINSTANCE.createToolControl();
@@ -758,35 +812,6 @@ public class WorkbenchWindow implements IWorkbenchWindow {
trimBar.getChildren().add(spacerControl);
}
- MToolControl spacerGlueControl = (MToolControl) modelService.find("Spacer Glue", model); //$NON-NLS-1$
- if (spacerGlueControl == null) {
- spacerGlueControl = MenuFactoryImpl.eINSTANCE.createToolControl();
- spacerGlueControl.setElementId("Spacer Glue"); //$NON-NLS-1$
- spacerGlueControl
- .setContributionURI("bundleclass://org.eclipse.e4.ui.workbench.renderers.swt/org.eclipse.e4.ui.workbench.renderers.swt.LayoutModifierToolControl"); //$NON-NLS-1$
- spacerGlueControl.getTags().add(TrimBarLayout.GLUE);
- trimBar.getChildren().add(spacerGlueControl);
- }
-
- MToolControl searchControl = (MToolControl) modelService.find("SearchField", model); //$NON-NLS-1$
- if (searchControl == null) {
- searchControl = MenuFactoryImpl.eINSTANCE.createToolControl();
- searchControl.setElementId("SearchField"); //$NON-NLS-1$
- searchControl
- .setContributionURI("bundleclass://org.eclipse.ui.workbench/org.eclipse.ui.internal.quickaccess.SearchField"); //$NON-NLS-1$
- trimBar.getChildren().add(searchControl);
- }
-
- MToolControl glueControl = (MToolControl) modelService.find("Search-PS Glue", model); //$NON-NLS-1$
- if (glueControl == null) {
- glueControl = MenuFactoryImpl.eINSTANCE.createToolControl();
- glueControl.setElementId("Search-PS Glue"); //$NON-NLS-1$
- glueControl
- .setContributionURI("bundleclass://org.eclipse.e4.ui.workbench.renderers.swt/org.eclipse.e4.ui.workbench.renderers.swt.LayoutModifierToolControl"); //$NON-NLS-1$
- glueControl.getTags().add(TrimBarLayout.GLUE);
- trimBar.getChildren().add(glueControl);
- }
-
MToolControl switcherControl = (MToolControl) modelService.find(
"PerspectiveSwitcher", model); //$NON-NLS-1$
if (switcherControl == null) {
@@ -804,6 +829,172 @@ public class WorkbenchWindow implements IWorkbenchWindow {
updateLayoutDataForContents();
}
+ /**
+ * Removes the "legacy" QuickAccess related fields from the
+ * ApplicationModel.
+ * <p>
+ * The "legacy" QuickAccess fields exist in the ApplicationModel if an older
+ * workspace is opened which was build before the QuickAccess was
+ * contributed via e4xmi-fragment.
+ * </p>
+ */
+ private void cleanLegacyQuickAccessContribution() {
+ for (String quickAccessElementId : QUICK_ACCESS_ELEMENT_IDS) {
+ MToolControl legacyElement = (MToolControl) modelService.find(quickAccessElementId,
+ model);
+ if (legacyElement != null) {
+ EcoreUtil.remove((EObject) legacyElement);
+ }
+ }
+ }
+
+ /**
+ * Moves the QucickAccess related fields to the wanted position.
+ * <p>
+ * If the elements "Spacer Glue", "SearchField" and "Search-PS Glue" are
+ * available in the model this method will move them to the correct place if
+ * required. The movement can be influenced by a tag which begins with
+ * {@value #MOVE_TAG} followed by the normal positioning information (e.g.:
+ * move_after:PerspectiveSpacer). For more information about positioning
+ * have a look at: {@link PositionInfo#parse(String)}.
+ * </p>
+ */
+ private void positionQuickAccess() {
+ /*
+ * The QUICK_ACCESS_ELEMENT_IDS array contains the IDs of optional
+ * elements provided via an e4xmi application model fragment. The method
+ * checks if they should be moved to a special position. This behavior
+ * is required because nearly all elements in the legacy workbench are
+ * not provided via e4xmi application model. They are provided
+ * programmatically after the e4xmi application model and the
+ * corresponding fragment models are already processed.
+ */
+ for (String quickAccessElementId : QUICK_ACCESS_ELEMENT_IDS) {
+ MToolControl quickAccessElement = (MToolControl) modelService.find(
+ quickAccessElementId, model);
+ if (quickAccessElement != null) {
+ moveControl(quickAccessElement.getParent(), quickAccessElement);
+ }
+ }
+
+ }
+
+ /**
+ * Moves the given element from its current position to the position
+ * mentioned in one of its tags.
+ *
+ * @param elementContainer
+ * the list of elements in which the element should be moved
+ * @param element
+ * the element to move
+ */
+ private void moveControl(MElementContainer<MUIElement> elementContainer, MUIElement element) {
+ if (element == null || elementContainer == null)
+ return;
+
+ PositionInfo positionInfo = findMovePositionInfo(element);
+
+ // does the element has a tag with a "move_" position info
+ if (positionInfo != null) {
+ List<MUIElement> elements = elementContainer.getChildren();
+
+ if (elements.remove(element)) {
+ // reposition only if the element was in the list
+
+ switch (positionInfo.getPosition()) {
+ case LAST:
+ elements.add(element);
+ break;
+
+ case FIRST:
+ elements.add(0, element);
+ break;
+
+ case INDEX:
+ int index = positionInfo.getPositionReferenceAsInteger();
+ if (index >= 0 && index < elements.size()) {
+ elements.add(index, element);
+ } else {
+ elements.add(element);
+ }
+ break;
+
+ case BEFORE:
+ case AFTER:
+ int idx = indexOfElementWithID(elements, positionInfo.getPositionReference());
+ if (idx < 0) {
+ // element no found
+ elements.add(element);
+ } else {
+ if (positionInfo.getPosition() == Position.AFTER) {
+ idx++;
+ }
+
+ if (idx < elements.size()) {
+ elements.add(idx, element);
+ } else {
+ elements.add(element);
+ }
+ }
+ break;
+
+ default:
+ WorkbenchPlugin.log("Can't position control '" + element.getElementId() //$NON-NLS-1$
+ + "' because of the unknown position type '" //$NON-NLS-1$
+ + positionInfo.getPosition() + "'!"); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+
+ /**
+ * Find the element with the given id in the given list of
+ * {@link MUIElement}s.
+ *
+ * @param elements
+ * the list of {@link MUIElement}s to search
+ * @param id
+ * the id of the {@link MUIElement} to find
+ * @return the index of the {@link MUIElement} in the given list or -1 if
+ * element wasn't found
+ */
+ private int indexOfElementWithID(List<MUIElement> elements, String id) {
+ if (elements == null || id == null)
+ return -1;
+
+ int index = 0;
+ for (MUIElement element : elements) {
+ if (id.equals(element.getElementId())) {
+ return index;
+ }
+ index++;
+ }
+
+ return -1;
+ }
+
+ /**
+ * Checks if the {@link MUIElement} has a tag starting with
+ * {@value #MOVE_TAG} and if so it will extract the {@link PositionInfo} out
+ * of it.
+ *
+ * @param element
+ * the element to check
+ * @return the found {@link PositionInfo} on the given {@link MUIElement},
+ * or <code>null</code> if none was found
+ */
+ private PositionInfo findMovePositionInfo(MUIElement element) {
+ if (element != null) {
+ for (String tag : element.getTags()) {
+ if (tag.startsWith(MOVE_TAG)) {
+ return PositionInfo.parse(tag.substring(MOVE_TAG.length()));
+ }
+ }
+ }
+
+ return null;
+ }
+
private void populateStandardTrim(MTrimBar bottomTrim) {
// StatusLine
MToolControl slElement = (MToolControl) modelService.find(
diff --git a/bundles/org.eclipse.ui.workbench/LegacyIDE.e4xmi b/bundles/org.eclipse.ui.workbench/LegacyIDE.e4xmi
index e96f202e31e..6e2d8c6648d 100644
--- a/bundles/org.eclipse.ui.workbench/LegacyIDE.e4xmi
+++ b/bundles/org.eclipse.ui.workbench/LegacyIDE.e4xmi
@@ -1,6 +1,11 @@
<?xml version="1.0" encoding="ASCII"?>
<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" xsi:schemaLocation="http://www.eclipse.org/ui/2010/UIModel/application/ui/basic http://www.eclipse.org/ui/2010/UIModel/application#//ui/basic" xmi:id="org.eclipse.e4.legacy.ide.application" elementId="org.eclipse.e4.legacy.ide.application" bindingContexts="_SeXUHO8EEd6BC9cDb6iV7y">
- <children xsi:type="basic:TrimmedWindow" xmi:id="IDEWindow" elementId="IDEWindow" label="%trimmedwindow.label.eclipseSDK" width="5" height="5"/>
+ <children xsi:type="basic:TrimmedWindow" xmi:id="IDEWindow" elementId="IDEWindow" label="%trimmedwindow.label.eclipseSDK" width="5" height="5">
+ <trimBars xmi:id="_vCH1AF1sEeOF8qbLMOkG7A" elementId="org.eclipse.ui.main.toolbar"/>
+ <trimBars xmi:id="_CT96oF6VEeO_3ZCXGA_PQg" elementId="org.eclipse.ui.trim.status" side="Bottom"/>
+ <trimBars xmi:id="_DU4lEF6VEeO_3ZCXGA_PQg" elementId="org.eclipse.ui.trim.vertical1" side="Left"/>
+ <trimBars xmi:id="_Ek7QoF6VEeO_3ZCXGA_PQg" elementId="org.eclipse.ui.trim.vertical2" side="Right"/>
+ </children>
<bindingTables xmi:id="_SeXUEO8EEd6FC9cDb6iV7x" bindingContext="_SeXUHO8EEd6BC9cDb6iV7y"/>
<rootContext xmi:id="_SeXUHO8EEd6BC9cDb6iV7y" elementId="org.eclipse.ui.contexts.dialogAndWindow" name="%bindingcontext.name.dialogAndWindows">
<children xmi:id="_SeXUEO8EEd6FC9cDb6iV7w" elementId="org.eclipse.ui.contexts.window" name="%bindingcontext.name.windows">

Back to the top