org.eclipse.e4.ui.model.application.ui.MElementContainer Java Examples

The following examples show how to use org.eclipse.e4.ui.model.application.ui.MElementContainer. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ArrangeDisplayViews.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public static void execute(final GamaTree<String> tree) {
	listDisplayViews();
	// final List<IGamaView.Display> displays = WorkbenchHelper.getDisplayViews();

	if (tree != null) {
		DEBUG.LOG("Tree root = " + tree.getRoot().getChildren().get(0).getData() + " weight "
				+ tree.getRoot().getChildren().get(0).getWeight());
		if (tree.getRoot().getChildren().get(0).getWeight() == null) {
			tree.getRoot().getChildren().get(0).setWeight(5000);
		}
		final List<MPlaceholder> holders = listDisplayViews();
		final MPartStack displayStack = getDisplaysPlaceholder();
		if (displayStack == null) { return; }
		displayStack.setToBeRendered(true);
		final MElementContainer<?> root = displayStack.getParent();
		hideDisplays(displayStack, holders);
		process(root, tree.getRoot().getChildren().get(0), holders);
		showDisplays(root, holders);
	} else {
		decorateDisplays();
	}

}
 
Example #2
Source File: E4WindowCmd.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Find the first element with which we should join
 * 
 * @param dragStack the stack to join
 * @return the target stack 
 */
@SuppressWarnings("unchecked")  // for safe cast to MElementContainer<MUIElement>
protected MElementContainer<MUIElement> getAdjacentElement(MElementContainer<MUIElement> dragStack, MPart part, boolean stackp) {
	MElementContainer<MUIElement> result = null;
	if (dragStack != null) {
		MElementContainer<MUIElement> psash = dragStack.getParent();
		if ((Object)psash instanceof MPartSashContainer) {
			List<MUIElement> children = psash.getChildren();
			int size = children.size(); 
			if (size > 1) {
				int index = children.indexOf(dragStack)+1;
				// use the next element, or previous if we're the last one
				result = (MElementContainer<MUIElement>)children.get((index == size) ? index - 2 : index);
				if (stackp) {
					result =  findTheStack(result);
				}
			}
		}
	}
	return result;
}
 
Example #3
Source File: FrameJoinCmd.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * @see com.mulgasoft.emacsplus.e4.commands.E4WindowCmd#getAdjacentElement(org.eclipse.e4.ui.model.application.ui.MElementContainer, boolean, org.eclipse.e4.ui.model.application.ui.basic.MPart)
 */
protected MElementContainer<MUIElement> getAdjacentElement(MElementContainer<MUIElement> dragStack, MPart part, boolean stackp) {
	MElementContainer<MUIElement> result = null;
	if (dragStack != null) {
		MElementContainer<MUIElement> psash = dragStack.getParent();
		MElementContainer<MUIElement> top = getTopElement(psash);
		if ((Object)top instanceof MTrimmedWindow) {
			// if we contain splits, remove them first
			if (top != psash) {
				super.joinAll(part);
			}
			Collection<MPart> parts = getParts(application.getChildren().get(0), EModelService.IN_SHARED_AREA);
			for (MPart p : parts) {
				List<MElementContainer<MUIElement>> all = getOrderedStacks(p);
				// if it has a PartStack, it sh/c/ould be an editor stack
				if (!all.isEmpty()) {
					result = all.get(0);
					break;
				};
			};
		}
	}
	return result;
}
 
Example #4
Source File: WindowJoinCmd.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Merge the stack containing the selected part into its neighbor and return the 
 * element to activate.  This will be the originating buffer on split-self or the
 * active element in the other stack if not.
 * 
 * @param apart
 * @return the element to select
 */
MPart joinOne(MPart apart) {
	// We're going to end up with 1, so avoid the overhead of futzing with the stacks
	if (isSplitSelf() && getOrderedStacks(apart).size() < 3) {
		this.joinAll(apart);
		return apart;
	} else {
		PartAndStack ps = getParentStack(apart);
		MElementContainer<MUIElement> pstack = ps.getStack();
		MPart part = ps.getPart();		
		MElementContainer<MUIElement> adjacent = getAdjacentElement(pstack, part, true);
		MUIElement otherPart = getSelected(adjacent);
		// deduplicate editors across these two stacks
		closeOthers(pstack, adjacent);
		if (pstack == null || join2Stacks(pstack, adjacent, part) == null) {
			// Invalid state 
			Beeper.beep();
		}
		return (otherPart instanceof MPart) ? (MPart)otherPart : apart;
	}
}
 
Example #5
Source File: E4WindowCmd.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * The parent of the apart is typically a PartStack, but it could be something under an MCompositePart, so look up
 * @param apart the original selection
 * @return the MPart and PartStack
 */
protected PartAndStack getParentStack(MPart apart) {
	MPartSashContainerElement part = apart;
	MElementContainer<MUIElement> stack = apart.getParent();
	try {
		while (!((MPartSashContainerElement)stack instanceof MPartStack)) {
			if ((MPartSashContainerElement)stack instanceof MArea) {
				// some unexpected structure
				stack = null;
				part = apart;
				break;
			} else {
				part = (MPartSashContainerElement)stack;
				stack = stack.getParent();
			}
		}
	} catch (Exception e) {
		// Bail on anything unexpected - will just make the command a noop
		stack = null;
		part = apart;
	}
	return new PartAndStack((MPart)part, stack);
}
 
Example #6
Source File: WindowJoinCmd.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Get all the IEditorReferences in a given part stack
 * 
 * @param stack
 * @return the collection of IEditorReferences
 */
private Collection<IEditorReference> getStackEditors(MElementContainer<MUIElement> stack) {
	Collection<IEditorReference> editors = new ArrayList<IEditorReference>(); 
	for (MUIElement child : stack.getChildren()) {
		if (child instanceof MPart) {
			// TODO: There must be a better way of getting the editor out of e4, but I can't find it
			Object cEditor = ((MPart) child).getObject();
			if (cEditor != null) {
				try {
					// avoid discouraged access of org.eclipse.ui.internal.e4.compatibility.CompatibilityEditor
					// which is expected cEditor's type in e4
					Method method = cEditor.getClass().getMethod(GET_REF);
					if (method != null) {
						IEditorReference ie = (IEditorReference)method.invoke(cEditor);					
						editors.add(ie);

					}
				} catch (NoSuchMethodException | SecurityException | IllegalAccessException | IllegalArgumentException
						| InvocationTargetException | ClassCastException e) {

				}
			}
		}
	}
	return editors;
}
 
Example #7
Source File: SwitchToBufferOtherCmd.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
void switchTo(MPart newPart) {
	if (getOrderedStacks(apart).size() == 1) {
		// case 1: 1 frame, split with miniPart
		// convenience hack: change direction on uArg
		splitIt(newPart, getDirection((isUniversalPresent()) ? !DISPLAY_HORIZONTAL : DISPLAY_HORIZONTAL));
	} else {
		// case 2: multiple stacks, move to adjacent stack
		// get the starting stack
		MElementContainer<MUIElement> stack = getParentStack(apart).getStack();
		// get the topart's stack
		MElementContainer<MUIElement> tstack = getParentStack(newPart).getStack();
		stack = findNextStack(apart, stack, 1);
		if (stack != null && stack != tstack) {
			modelService.move(newPart, stack, 0);
		}
	}
	if (displayOnly) {
		// brings to top
		partService.showPart(newPart, PartState.VISIBLE);
		reactivate(apart);
	} else {
		// bug in Kepler forces us to activate the old before the new
		reactivate(apart);
		reactivate(newPart);
	}
}
 
Example #8
Source File: OtherWindowCmd.java    From e4macs with Eclipse Public License 1.0 6 votes vote down vote up
@Execute
protected void doOtherWindow(@Active MPart apart, @Named(E4CmdHandler.CMD_CTX_KEY)String cmd, @Active EmacsPlusCmdHandler handler) {
	PartAndStack ps = getParentStack(apart); 
	MElementContainer<MUIElement> otherStack = getAdjacentElement(ps.getStack(), ps.getPart(), true);
	MPart other = (MPart)otherStack.getSelectedElement();
	// TODO An egregious hack that may break at any time
	// Is there a defined way of getting the IEditorPart from an MPart?
	if (other.getObject() instanceof CompatibilityEditor) {
		IEditorPart editor = ((CompatibilityEditor) other.getObject()).getEditor();
		try {
			reactivate(other);
			if (handler.isUniversalPresent()) {
				EmacsPlusUtils.executeCommand(cmd, handler.getUniversalCount(), null, editor);
			} else {
				EmacsPlusUtils.executeCommand(cmd, null, editor);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		finally {
			reactivate(apart);
		}
	}
}
 
Example #9
Source File: CustomPopupMenuExtender.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * well, this goes to the renderer.
 *
 * @param mgr
 */
public void addMenuContributions(IMenuManager mgr) {
    IRendererFactory factory = modelPart.getContext().get(IRendererFactory.class);
    AbstractPartRenderer obj = factory.getRenderer(menuModel, null);
    if (obj instanceof MenuManagerRenderer) {
        MenuManagerRenderer renderer = (MenuManagerRenderer) obj;
        renderer.reconcileManagerToModel(menu, menuModel);
        renderer.processContributions(menuModel, menuModel.getElementId(), false, true);
        // double cast because we're bad people
        renderer.processContents((MElementContainer<MUIElement>) ((Object) menuModel));
        List<MMenuElement> toRemove = new ArrayList<>();
        for (MMenuElement e : menuModel.getChildren()) {
            if (!(e instanceof MMenuSeparator || INCLUDES.contains(e.getElementId())
                    || e.getElementId() == null)) {
                if (e.getElementId() != null && !e.getElementId().startsWith("org.bonitasoft.studio.")) {
                    toRemove.add(e);
                    e.setVisible(false);
                }
            }
        }
        menuModel.getChildren().removeAll(toRemove);
    }

}
 
Example #10
Source File: LayoutTreeConverter.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
private void save(final MUIElement element, final List<MPlaceholder> holders, final GamaNode<String> parent,
		final String weight) {
	final String data = weight == null ? getWeight(element) : weight;
	if (element instanceof MPlaceholder && holders.contains(element)) {
		parent.addChild(valueOf(element.getTransientData().get(DISPLAY_INDEX_KEY)), parseInt(data));
	} else if (element instanceof MElementContainer) {
		final MElementContainer<?> container = (MElementContainer<?>) element;
		final List<? extends MUIElement> children = getNonEmptyChildren(container, holders);
		if (children.size() == 0) { return; }
		if (children.size() == 1) {
			save(children.get(0), holders, parent, data);
		} else {
			final GamaNode<String> node = parent.addChild(prefix(container), parseInt(data));
			children.forEach(e -> save(e, holders, node, null));
		}
	}
}
 
Example #11
Source File: ArrangeDisplayViews.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
static MElementContainer create(final MElementContainer root, final String weight, final Boolean dir) {
	if (dir == null) { // stacks cannot be stacked
		if (root instanceof MPartStack && isPartOfLayout(root)) { return root; }
	}
	if (dir == null && (root instanceof MPartStack || !PerspectiveHelper.keepTabs())) { return root; }
	final MElementContainer c = dir != null ? INSTANCE.createPartSashContainer() : INSTANCE.createPartStack();
	c.getTransientData().put("Dynamic", true);
	c.getTransientData().put(LAYOUT, true);
	c.setContainerData(weight);
	if (dir != null) {
		((MPartSashContainer) c).setHorizontal(dir);
	}
	if (root != null) {
		root.getChildren().add(c);
	}
	return c;
}
 
Example #12
Source File: ArrangeDisplayViews.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public static void process(final MElementContainer uiRoot, final GamaNode<String> treeRoot,
		final List<MPlaceholder> holders) {
	final String data = treeRoot.getData();
	final String weight = String.valueOf(treeRoot.getWeight());
	// DEBUG.OUT("Processing " + data + " with weight " + weight);
	final Boolean dir = !data.equals(HORIZONTAL) && !data.equals(VERTICAL) ? null : data.equals(HORIZONTAL);
	final MPlaceholder holder = StreamEx.of(holders)
			.findFirst(h -> h.getTransientData().get(DISPLAY_INDEX_KEY).equals(data)).orElse(null);
	final MElementContainer container = create(uiRoot, weight, dir);
	if (holder != null) {
		if (container.equals(uiRoot)) {
			holder.setContainerData(weight);
		}
		container.getChildren().add(holder);
	} else {
		for (final GamaNode<String> node : treeRoot.getChildren()) {
			process(container, node, holders);
		}
	}
}
 
Example #13
Source File: ArrangeDisplayViews.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public static void hideDisplays(final MPartStack displayStack, final List<MPlaceholder> holders) {
	final MElementContainer<MUIElement> parent = displayStack.getParent();
	parent.setVisible(false);
	holders.forEach((ph) -> {
		ph.setVisible(false);
		displayStack.getChildren().add(ph);
	});
	activateDisplays(holders, false);
	for (final MUIElement element : new ArrayList<>(parent.getChildren())) {
		if (element.getTransientData().containsKey(LAYOUT)) {
			element.setVisible(false);
			element.setToBeRendered(false);
			parent.getChildren().remove(element);
		}
	}
}
 
Example #14
Source File: WindowJoinCmd.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Check if containerData size needs updating.
 * This should be handled by the Eclipse framework, but apparently not...
 * @param pstack - source stack
 * @param dropStack - destination stack
 */
protected void checkSizeData(MElementContainer<MUIElement> pstack, MElementContainer<MUIElement> dropStack) {
	if (pstack.getParent().getContainerData() == null) {
		int s1 = getIntData(pstack);;
		if (dropStack.getParent().getContainerData() == null) {
			// stacks are vertically side by side, add their sizes together 
			dropStack.setContainerData(String.valueOf(s1 + getIntData(dropStack)));
		} else {
			// source is vertical & destination is in a horizontal containing PartSash
			dropStack.getParent().setContainerData(String.valueOf(s1 + getIntData(dropStack.getParent())));
		}
	}
}
 
Example #15
Source File: WindowJoinCmd.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Given 2 partStacks, move children of pstack into dropStack
 * @param pstack - source stack
 * @param dropStack - destination stack
 * @param apart - the initiating part
 * @return the enhanced dropStack
 */
protected MElementContainer<MUIElement> join2Stacks(MElementContainer<MUIElement> pstack, MElementContainer<MUIElement> dropStack, MPart apart) {
	if (dropStack != null && ((MPartSashContainerElement)dropStack) instanceof MPartStack) {
		List<MUIElement> eles = pstack.getChildren();
		boolean hasPart = apart != null;
		int offset = 1;
		List<MUIElement> drops = dropStack.getChildren();
		while (eles.size() > (hasPart ? 1 : 0)) {
			MUIElement ele = eles.get(eles.size() - offset);
			if (hasPart && ele == apart) {
				offset++;
				continue;
			}
			eles.remove(ele);
			if (hasPart) {
					drops.add(0,ele);
				} else {
					drops.add(ele);
				}
		}
		if (hasPart) {
			// Move the selected element to the leftmost position
			eles.remove(apart);
			drops.add(0,apart);
			dropStack.setSelectedElement(apart);
		}
		checkSizeData(pstack,dropStack);
	} 
	return dropStack;
}
 
Example #16
Source File: WindowJoinCmd.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Close any duplicate editors in the supplied part stacks
 * 
 * @param stack1
 * @param stack2
 * @return true if any duplicates were closed
 */
boolean closeOthers(MElementContainer<MUIElement> stack1, 	MElementContainer<MUIElement> stack2) {
	boolean result = false;
	Collection<IEditorReference> editors = getStackEditors(stack1);
	editors.addAll(getStackEditors(stack2));
	try {
		result = IDeduplication.closeDuplicates(EmacsPlusUtils.getWorkbenchPage(), editors.toArray(new IEditorReference[editors.size()]));
	} catch (PartInitException e) {
		// Ignore
	}
	return result;
}
 
Example #17
Source File: WindowJoinCmd.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Merge all stacks into one
 * 
 * @param apart - the selected MPart
 */
void joinAll(MPart apart) {
	try {
		// deduplicate editors across all stacks
		IDeduplication.closeAllDuplicates(EmacsPlusUtils.getWorkbenchPage());
	} catch (PartInitException e) {
		// Ignore
	}
	List<MElementContainer<MUIElement>> stacks = getOrderedStacks(apart);
	if (stacks.size() > 1) {
		PartAndStack ps = getParentStack(apart);
		MElementContainer<MUIElement> pstack = ps.getStack();
		MPart part = ps.getPart();		

		// check for unexpected result - who knows what Eclipse might do
		if (pstack != null) {
			MElementContainer<MUIElement> dropStack = stacks.get(0);
			for (int i = 1; i < stacks.size(); i++) {
				MElementContainer<MUIElement> stack = stacks.get(i); 
				if (stack == pstack) {
					continue;
				}
				join2Stacks(stacks.get(i), dropStack, null);
			}
			// lastly, join in the selected stack
			if (pstack != dropStack) {
				join2Stacks(pstack, dropStack, part);
			}
		} else {
			Beeper.beep();
		}
	}
}
 
Example #18
Source File: ElexisProcessor.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private void updateModelVersions(MApplication mApplication, EModelService eModelService){
	try {
		List<MWindow> windows = mApplication.getChildren();
		if (!windows.isEmpty() && windows.get(0) instanceof MTrimmedWindow) {
			MTrimmedWindow mWindow = (MTrimmedWindow) windows.get(0);
			// remove old model elements like perspectives etc
			for (String modelElementId : removeModelElements) {
				MUIElement element = eModelService.find(modelElementId, mApplication);
				if (element != null) {
					if (element instanceof MPerspective) {
						eModelService.removePerspectiveModel((MPerspective) element, mWindow);
						logger.info(
							"model element (perspective): " + modelElementId + " removed!");
					} else {
						MElementContainer<MUIElement> parent = element.getParent();
						parent.getChildren().remove(element);
						element.setToBeRendered(false);
						logger.info("model element: " + modelElementId + " removed!");
					}
				}
			}
		} else {
			logger.warn("cannot find active window");
		}
	} catch (Exception e) {
		logger.error("unexpected exception - cannot do updates on models", e);
	}
}
 
Example #19
Source File: FrameJoinCmd.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
@Override
void joinAll(MPart apart) {
	joined = true;
	List<MTrimmedWindow> frames = getDetachedFrames();
	MElementContainer<MUIElement> last = getTopElement((MElementContainer<MUIElement>) apart.getParent());
	for (MTrimmedWindow mt : frames) {
		if (!mt.equals(last)) {
			joinOne(mt);
		}
	}
	// only join apart if its top element is a frame
	if ((Object)last instanceof MTrimmedWindow) {
		super.joinOne(apart);
	}
}
 
Example #20
Source File: PerspektiveImportHandler.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private void switchToPerspectiveLegacy(MPerspective loadedPerspective,
	List<String> preLoadedFastViewIds){
	
	EModelService modelService = getService(EModelService.class);
	EPartService partService = getService(EPartService.class);
	MApplication mApplication = getService(MApplication.class);
	MTrimmedWindow mWindow = (MTrimmedWindow) modelService.find("IDEWindow", mApplication);
	if (mWindow == null) {
		List<MWindow> windows = mApplication.getChildren();
		if (!windows.isEmpty() && windows.get(0) instanceof MTrimmedWindow) {
			mWindow = (MTrimmedWindow) windows.get(0);
		}
	}
	MPerspective activePerspective = modelService.getActivePerspective(mWindow);
	MElementContainer<MUIElement> perspectiveParent = activePerspective.getParent();
	List<String> fastViewIds = preLoadedFastViewIds;
	
	// add the loaded perspective and switch to it
	String id = loadedPerspective.getElementId();
	Iterator<MUIElement> it = perspectiveParent.getChildren().iterator();
	while (it.hasNext()) {
		MUIElement element = it.next();
		if (id.equals(element.getElementId()) || element.getElementId().startsWith(id + ".<")) {
			it.remove();
		}
	}
	perspectiveParent.getChildren().add(loadedPerspective);
	
	// add fast view
	for (String fastViewId : fastViewIds) {
		ElexisFastViewUtil.addToFastView(loadedPerspective.getElementId(), fastViewId);
	}
	// the workbench window must be on top - otherwise the exception 'Application does not have an active window' occurs
	PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().open();
	
	partService.switchPerspective(loadedPerspective);
}
 
Example #21
Source File: WindowSplitCmd.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Wrap the editor (MPart) up in a new PartStack
 * @param apart
 * @return the wrapped MPart
 */
private MPartStack getStack(MPart apart, MElementContainer<MUIElement> parent) {
	MPartStack result = MBasicFactory.INSTANCE.createPartStack();
	MStackElement stackElement = (MStackElement) apart;
	parent.getChildren().remove(apart);
	result.getChildren().add(stackElement);
	result.setSelectedElement(stackElement);
	return result;
}
 
Example #22
Source File: WindowSplitCmd.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
protected void splitIt(MPart apart, int location) {
	PartAndStack ps = getParentStack(apart);
	MElementContainer<MUIElement> pstack = ps.getStack();
	if (pstack.getChildren().size() > 1) {
		MPart newpart = ps.getPart();		

		MPartStack nstack = getStack(newpart, pstack);
		// Let the model service take care of the rest of the split
		modelService.insert(nstack, (MPartSashContainerElement)pstack, location, ratio);
	}
}
 
Example #23
Source File: E4WindowCmd.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
@SuppressWarnings("unchecked") // manually checked
MUIElement getSelected(MUIElement ele) {
 	MUIElement sel = ele;
	while (sel instanceof MElementContainer) {
		sel = ((MElementContainer<MUIElement>)sel).getSelectedElement();
	}
	// on occasion the above returns null which is bizarre, so try skipping the first level
	if (sel == null && ele instanceof MElementContainer) {
		List<MUIElement> c = ((MElementContainer<MUIElement>)ele).getChildren();
		if (c.size() == 1 && c.get(0) instanceof MPartStack) {
			sel = ((MElementContainer<MUIElement>)c.get(0)).getSelectedElement();
		}
	}
	return sel;
}
 
Example #24
Source File: E4WindowCmd.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * @param ele start from here
 * @return the most distant parent for the editor area
 */
protected MElementContainer<MUIElement> getTopElement(MElementContainer<MUIElement> ele) {
	MElementContainer<MUIElement> parent = ele;
	// get the outer container
	if (parent != null) {
		while (!((Object)parent instanceof MArea) && parent.getParent() != null) {
				parent = parent.getParent();
		}
	}
	return parent;
}
 
Example #25
Source File: E4WindowCmd.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Rotate through stacks by <count> elements
 *  
 * @param part the source part
 * @param stack the source stack
 * @param count the number to rotate by
 * @return the destination stack
 */
protected MElementContainer<MUIElement> findNextStack(MPart part, MElementContainer<MUIElement> stack, int count) {
	MElementContainer<MUIElement> nstack = null;		
	List<MElementContainer<MUIElement>> stacks = getOrderedStacks(part);		
	int size = stacks.size();
	if (size > 1) {
		int index = stacks.indexOf(stack) + (count % size);
		nstack = (index < 0) ? stacks.get(size + index) : (index < size) ? stacks.get(index) : stacks.get(index - size); 
	}
	return nstack;
}
 
Example #26
Source File: E4WindowCmd.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * If parent is a sash, keep looking until we find a PartStack
 * 
 * @param parent a sash of PartStack
 * @return the first PartStack we find
 */
@SuppressWarnings("unchecked")  // for safe cast to MElementContainer<MUIElement>
private MElementContainer<MUIElement> findTheStack(MElementContainer<MUIElement> parent) {
	MElementContainer<MUIElement> result = parent;
	if ((MPartSashContainerElement)parent instanceof MPartSashContainer) {
		List<MUIElement> children = parent.getChildren();
		result = findTheStack((MElementContainer<MUIElement>)children.get(0));
	}
	return result;
}
 
Example #27
Source File: E4WindowCmd.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
private List<MElementContainer<MUIElement>> getStacks(List<MElementContainer<MUIElement>> result, MElementContainer<MUIElement> container) {
	for (MUIElement child : container.getChildren()) {
		@SuppressWarnings("unchecked") // We type check all the way down
		MElementContainer<MUIElement> c = (MElementContainer<MUIElement>)child;
		if (child instanceof MPartStack) {
			result.add(c);
		} else {
			getStacks(result,c);
		}
	}
	return result;
}
 
Example #28
Source File: E4WindowCmd.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
private int sizeIt(MUIElement ele) {
	int result = 0;
	if (ele.getContainerData() != null) {
		result = getIntData(ele);
	} else if (ele instanceof MElementContainer) {
		@SuppressWarnings("unchecked") //checked
		List<MUIElement> mlist = ((MElementContainer<MUIElement>)ele).getChildren();
		for (MUIElement mui : mlist) {
			result += sizeIt(mui);
		}
	}
	return result;
}
 
Example #29
Source File: ArrangeDisplayViews.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public static void showDisplays(final MElementContainer<?> root, final List<MPlaceholder> holders) {
	root.setVisible(true);
	decorateDisplays();
	holders.forEach((ph) -> {
		ph.setVisible(true);
		ph.setToBeRendered(true);
	});
	activateDisplays(holders, true);
}
 
Example #30
Source File: E4WindowCmd.java    From e4macs with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Get the ordered list of stacks
 * @param apart
 * @return a list of MElementContainer<MUIElement> representing all the PartStacks
 */
protected List<MElementContainer<MUIElement>> getOrderedStacks(MPart apart) {
	List<MElementContainer<MUIElement>> result = new ArrayList<MElementContainer<MUIElement>>();
	MElementContainer<MUIElement> parent = getTopElement(apart.getParent());
	if (parent != null) {
		result = getStacks(result, parent);
	} 
	return result;
}