org.eclipse.e4.ui.model.application.ui.basic.MPartStack Java Examples

The following examples show how to use org.eclipse.e4.ui.model.application.ui.basic.MPartStack. 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: ElexisFastViewUtil.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Transfer persisted state (incl. size) of fastview defined in perspective, to fastview
 * {@link MToolControl} defined in window.
 * 
 * @param fromPerspective
 * @param toWindow
 */
public static void transferFastViewPersistedState(MPerspective fromPerspective,
	MTrimmedWindow toWindow){
	EModelService modelService = getService(EModelService.class);
	String perspectiveId = fromPerspective.getElementId();
	
	Optional<MToolControl> mToolControl =
		getFastViewToolControl(modelService, toWindow, perspectiveId, SideValue.BOTTOM);
	mToolControl.ifPresent(toolControl -> {
		Optional<MPartStack> mStack = getFastViewPartStack(fromPerspective);
		mStack.ifPresent(stack -> {
			if (stack.getPersistedState() != null && !stack.getPersistedState().isEmpty()) {
				for (String key : stack.getPersistedState().keySet()) {
					toolControl.getPersistedState().put(key,
						stack.getPersistedState().get(key));
				}
			}
		});
	});
}
 
Example #2
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 #3
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 #4
Source File: ElexisFastViewUtil.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Transfer persisted state (incl. size) of fastview {@link MToolControl} defined in window, to
 * fastview defined in perspective.
 * 
 * @param fromWindow
 * @param toPerspective
 */
public static void transferFastViewPersistedState(MTrimmedWindow fromWindow,
	MPerspective toPerspective){
	EModelService modelService = getService(EModelService.class);
	// check if toolcontrol exists
	MToolControl toolControl = (MToolControl) modelService
		.find(ElexisFastViewUtil.getToolControlId(fromWindow, toPerspective), fromWindow);
	if (toolControl != null && toolControl.getPersistedState() != null) {
		Optional<MPartStack> mStack = getFastViewPartStack(toPerspective);
		mStack.ifPresent(stack -> {
			Map<String, String> perspectiveState = stack.getPersistedState();
			for (String key : toolControl.getPersistedState().keySet()) {
				perspectiveState.put(key, toolControl.getPersistedState().get(key));
			}
		});
	}
}
 
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: ElexisFastViewUtil.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
private static MPartStack createFastViewStack(MTrimmedWindow window, MPerspective mPerspective,
	EModelService eModelService){
	
	if (window != null && mPerspective != null) {
		MPartStack mPartStack = eModelService.createModelElement(MPartStack.class);
		mPartStack.setElementId(ELEXIS_FASTVIEW_STACK);
		mPartStack.setToBeRendered(true);
		mPartStack.getTags().add("Minimized");
		mPartStack.setOnTop(false);
		mPartStack.setVisible(false);
		mPartStack.getTags().add("NoAutoCollapse");
		mPartStack.getTags().add("active");
		mPerspective.getChildren().add(0, mPartStack);
		return mPartStack;
	}
	return null;
}
 
Example #7
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 #8
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 #9
Source File: ElexisFastViewUtil.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private static Optional<MPartStack> getFastViewPartStack(MPerspective mPerspective){
	EModelService modelService = getService(EModelService.class);
	MPartStack stack =
		(MPartStack) modelService.find(ElexisFastViewUtil.ELEXIS_FASTVIEW_STACK, mPerspective);
	if (stack != null) {
		return Optional.of(stack);
	}
	return Optional.empty();
}
 
Example #10
Source File: ElexisFastViewUtil.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean hasFastViewPersistedState(MPerspective mPerspective){
	Optional<MPartStack> mStack = getFastViewPartStack(mPerspective);
	if (mStack.isPresent()) {
		Map<String, String> persistedState = mStack.get().getPersistedState();
		return persistedState != null && !persistedState.isEmpty();
	}
	return false;
}
 
Example #11
Source File: ElexisFastViewUtil.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private static boolean isViewInsideFastview(MPartStack stack, String placeholderId){
	if (stack != null) {
		for (MStackElement stackElement : stack.getChildren()) {
			if (stackElement.getElementId().equals(placeholderId)) {
				return true;
			}
		}
	}
	return false;
}
 
Example #12
Source File: ElexisRendererFactory.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public AbstractPartRenderer getRenderer(MUIElement uiElement, Object parent){
	if (uiElement instanceof MPartStack) {
		if (stackRenderer == null) {
			stackRenderer = new ElexisStackRenderer();
			super.initRenderer(stackRenderer);
		}
		return stackRenderer;
	}
	return super.getRenderer(uiElement, parent);
}
 
Example #13
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 #14
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 #15
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 #16
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 #17
Source File: LayoutTreeConverter.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public GamaTree<String> convertCurrentLayout(final List<MPlaceholder> holders) {
	final MPartStack displayStack = getDisplaysPlaceholder();
	if (displayStack == null) { return null; }
	final GamaTree<String> tree = newLayoutTree();
	save(displayStack.getParent(), holders, tree.getRoot(), null);
	return tree;
}
 
Example #18
Source File: ElexisFastViewUtil.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Adds a view to the fastview, if {@link MPartStack} not exists it will be created and the view
 * will be added within a {@link MPlaceholder} element.
 * 
 * @param perspectiveId
 * @param viewId
 */
public static void addToFastView(String perspectiveId, String viewId){
	EModelService eModelService = getService(EModelService.class);
	MApplication mApplication = getService(MApplication.class);
	
	MTrimmedWindow window = getCurrentWindow(eModelService, mApplication);
	
	if (window != null) {
		Object obj = eModelService.find(perspectiveId, mApplication);
		if (obj instanceof MPerspective) {
			MPerspective mPerspective = (MPerspective) obj;
			// check if fastview stack exists
			MPartStack stack =
				(MPartStack) eModelService.find(ELEXIS_FASTVIEW_STACK, mPerspective);
			
			if (stack == null) {
				stack = createFastViewStack(window, mPerspective, eModelService);
			}
			if (stack != null) {
				// check if toolcontrol exists
				MToolControl toolControl = (MToolControl) eModelService
					.find(getToolControlId(window, mPerspective), mApplication);
				
				if (toolControl == null) {
					MTrimBar mTrimBar = eModelService.getTrim(window, SideValue.BOTTOM);
					if (toolControl == null) {
						toolControl = createFastViewToolControl(window, mPerspective,
							eModelService, mTrimBar);
					}
				}
				if (toolControl != null
					&& !ElexisFastViewUtil.isViewInsideFastview(stack, viewId)
					&& mApplication.getContext().getActiveChild() != null) {
					EPartService partService = getService(EPartService.class);
					MPlaceholder placeholder = partService.createSharedPart(viewId);
					placeholder.setToBeRendered(true);
					placeholder.setElementId(viewId);
					placeholder.setCloseable(true);
					placeholder.getTags().add(EPartService.REMOVE_ON_HIDE_TAG);
					((MPart) placeholder.getRef()).setToBeRendered(true);
					stack.getChildren().add(placeholder); // Add part to stack
				}
				
			}
		}
	}
}
 
Example #19
Source File: LayoutTreeConverter.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
String prefix(final MElementContainer<?> container) {
	return container instanceof MPartStack ? STACK : container instanceof MPartSashContainer
			? ((MPartSashContainer) container).isHorizontal() ? HORIZONTAL : VERTICAL : "";
}
 
Example #20
Source File: ArrangeDisplayViews.java    From gama with GNU General Public License v3.0 4 votes vote down vote up
public static MPartStack getDisplaysPlaceholder() {
	final Object displayStack = getModelService().find("displays", getApplication());
	// DEBUG.OUT("Element displays found : " + displayStack);
	return displayStack instanceof MPartStack ? (MPartStack) displayStack : null;
}