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

The following examples show how to use org.eclipse.e4.ui.model.application.ui.basic.MTrimBar. 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: GamlReferenceSearch.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public static void install() {
	WorkbenchHelper.runInUI("Install GAML Search", 0, m -> {
		final IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
		if (window instanceof WorkbenchWindow) {
			final MTrimBar topTrim = ((WorkbenchWindow) window).getTopTrim();
			for (final MTrimElement element : topTrim.getChildren()) {
				if ("SearchField".equals(element.getElementId())) {
					final Composite parent = ((Control) element.getWidget()).getParent();
					final Control old = (Control) element.getWidget();
					WorkbenchHelper.runInUI("Disposing old search control", 500, m2 -> old.dispose());
					element.setWidget(GamlSearchField.installOn(parent));
					parent.layout(true, true);
					parent.update();
					break;
				}
			}
		}
	});
}
 
Example #2
Source File: ElexisFastViewUtil.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
private static MToolControl createFastViewToolControl(MTrimmedWindow window,
	MPerspective mPerspective, EModelService eModelService, MTrimBar mTrimBar){
	if (mTrimBar != null) {
		MToolControl mToolControl = eModelService.createModelElement(MToolControl.class);
		mToolControl.setElementId(getToolControlId(window, mPerspective));
		mToolControl.setContributionURI(
			"bundleclass://org.eclipse.e4.ui.workbench.addons.swt/org.eclipse.e4.ui.workbench.addons.minmax.TrimStack");
		mToolControl.setToBeRendered(true);
		mToolControl.setVisible(true);
		mToolControl.getTags().add("TrimStack");
		if (!hasFastViewPersistedState(mPerspective)) {
			mToolControl.getPersistedState().put("YSize", "600");
		}
		mTrimBar.getChildren().add(0, mToolControl);
		mTrimBar.setVisible(true);
		mTrimBar.setToBeRendered(true);
		
		return mToolControl;
	}
	return null;
}
 
Example #3
Source File: ElexisFastViewUtil.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
private static Optional<MToolControl> getFastViewToolControl(EModelService eModelService,
	MTrimmedWindow workbenchWindow, String perspectiveId, SideValue sideValue){
	if (workbenchWindow != null) {
		MTrimBar trimbar = findTrimBar(eModelService, workbenchWindow, sideValue);
		if (trimbar != null) {
			MToolControl toolControl = (MToolControl) eModelService
				.find(getToolControlId(workbenchWindow, perspectiveId), trimbar);
			if (toolControl == null && workbenchWindow.getElementId() != null) {
				// it also can be that the main view id is also a part of the stack
				toolControl = (MToolControl) eModelService.find(ELEXIS_FASTVIEW_STACK + "("
					+ workbenchWindow.getElementId() + ").(" + perspectiveId + ")", trimbar);
				if (toolControl != null) {
					toolControl.setElementId(getToolControlId(workbenchWindow, perspectiveId));
				}
			}
			if (toolControl != null) {
				return Optional.of(toolControl);
			}
		}
	}
	return Optional.empty();
}
 
Example #4
Source File: UiStartupHandler.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private void addMandantSelectionItem(MApplication mApplication, EModelService eModelService){
	
	MTrimBar trimbar =
		(MTrimBar) eModelService.find("org.eclipse.ui.main.toolbar", mApplication);
	
	if (trimbar != null) {
		MTrimElement mTrimElement = null;
		int position = 0;
		int i = 0;
		List<MTrimElement> childrens = trimbar.getChildren();
		for (MTrimElement element : childrens) {
			
			if ("ch.elexis.core.ui.toolcontrol.mandantselection"
				.equals(element.getElementId())) {
				mTrimElement = element;
			}
			
			if (position == 0 && ("ch.elexis.toolbar1".equals(element.getElementId())
				|| "PerspectiveSpacer".equals(element.getElementId()))) {
				position = i;
			}
			i++;
		}
		
		if (mTrimElement == null) {
			MToolControl mToolControl = eModelService.createModelElement(MToolControl.class);
			mToolControl.setElementId("ch.elexis.core.ui.toolcontrol.mandantselection");
			mToolControl.setContributionURI(
				"bundleclass://ch.elexis.core.ui/ch.elexis.core.ui.coolbar.MandantSelectionContributionItem");
			mToolControl.setToBeRendered(true);
			mToolControl.setVisible(true);
			
			childrens.add(position, mToolControl);
		}
	}
	
}
 
Example #5
Source File: ElexisFastViewUtil.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private static MTrimBar findTrimBar(EModelService eModelService, MTrimmedWindow workbenchWindow,
	SideValue sideValue){
	if (workbenchWindow != null) {
		MTrimBar trimbar = eModelService.getTrim(workbenchWindow, sideValue);
		return trimbar;
	}
	return null;
}
 
Example #6
Source File: ElexisProcessor.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Clears the persisted state for the main toolbar, otherwise the positioning of the
 * toolbar-elements are in an incorrect order. That means all persisted toolbar-elements are
 * positioned before the dynamically created elements from
 * ApplicationActionBarAdvisor#fillCoolBar.
 * 
 **/
private void updateToolbar(){
	MTrimBar mTrimBar =
		(MTrimBar) eModelService.find("org.eclipse.ui.main.toolbar", mApplication);
	if (mTrimBar != null && mTrimBar.getChildren() != null) {
		mTrimBar.getChildren().clear();
	}
}
 
Example #7
Source File: CoolbarToolControl.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected boolean isRendered(final IEclipseContext context) {
    final MTrimBar topTrim = getTrimBar(context, "org.eclipse.ui.main.toolbar");
    return topTrim != null && topTrim.isToBeRendered() && !PlatformUtil.isHeadless();
}
 
Example #8
Source File: CoolbarToolControl.java    From bonita-studio with GNU General Public License v2.0 4 votes vote down vote up
protected MTrimBar getTrimBar(final IEclipseContext context, final String trimBarId) {
    final EModelService modelService = context.get(EModelService.class);
    final MWindow window = context.get(MWindow.class);
    final MTrimBar topTrim = (MTrimBar) modelService.find(trimBarId, window);
    return topTrim;
}
 
Example #9
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 #10
Source File: ElexisFastViewUtil.java    From elexis-3-core with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Changes the fastviews position from left trimbar to bottom trimbar
 */
private static void changeFastViewBarFromLeftToBottom(){
	EModelService eModelService = getService(EModelService.class);
	MApplication mApplication = getService(MApplication.class);
	MTrimmedWindow mWindow = getCurrentWindow(eModelService, mApplication);
	if (mWindow != null) {
		MPerspective mPerspective = eModelService.getActivePerspective(mWindow);
		
		if (mPerspective != null) {
			String perspectiveId = mPerspective.getElementId();
			
			Optional<MToolControl> mToolControl =
				getFastViewToolControl(eModelService, mWindow, perspectiveId, SideValue.BOTTOM);
			if (!mToolControl.isPresent()) {
				mToolControl = getFastViewToolControl(eModelService, mWindow, perspectiveId,
					SideValue.LEFT);
				mToolControl.ifPresent(toolControl -> {
					MTrimBar trimBarBottom =
						findTrimBar(eModelService, mWindow, SideValue.BOTTOM);
					if (trimBarBottom != null) {
						MToolControl copyToolcontrol =
							eModelService.createModelElement(MToolControl.class);
						copyToolcontrol.setElementId(toolControl.getElementId());
						copyToolcontrol.setContributionURI(
							"bundleclass://org.eclipse.e4.ui.workbench.addons.swt/org.eclipse.e4.ui.workbench.addons.minmax.TrimStack");
						copyToolcontrol.setToBeRendered(true);
						copyToolcontrol.setVisible(true);
						copyToolcontrol.getTags().add("TrimStack");
						
						if (!hasFastViewPersistedState(mPerspective)) {
							copyToolcontrol.getPersistedState().put("YSize", "600");
						}
						trimBarBottom.getChildren().add(0, copyToolcontrol);
						
						toolControl.setToBeRendered(false);
						toolControl.setVisible(false);
						toolControl.getParent().getChildren().remove(toolControl);
						toolControl.setParent(null);
						trimBarBottom.setVisible(true);
						trimBarBottom.setToBeRendered(true);
					}
				});
			} else {
				mToolControl.get().setToBeRendered(true);
			}
		}
	}
}