Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example handler for an alternative inline display #2093

Closed
vogella opened this issue Jul 16, 2024 · 3 comments
Closed

Example handler for an alternative inline display #2093

vogella opened this issue Jul 16, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@vogella
Copy link
Contributor

vogella commented Jul 16, 2024

@HeikoKlare and @Wittmaxi while cleanup up my inbox I found this example code for showing something inline of the current editor. I wanted to share it with you so that you are aware of this option. No error check are included in the example code, it is just a demo which might help you for future developments.

Result:

image

package handler.handlers;

import java.util.List;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.ui.advanced.MArea;
import org.eclipse.e4.ui.model.application.ui.basic.MPartStack;
import org.eclipse.e4.ui.model.application.ui.basic.MWindow;
import org.eclipse.e4.ui.workbench.modeling.EModelService;
import org.eclipse.e4.ui.workbench.modeling.EPartService;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;

public class SampleHandler extends AbstractHandler {
	
	
	MPartStack pipStack = null;
	Composite pipComp = null;

	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		IWorkbenchWindow window = HandlerUtil
				.getActiveWorkbenchWindowChecked(event);
		MApplication theApp = (MApplication) window
				.getService(MApplication.class);
		MWindow win1 = theApp.getChildren().get(0);
		EPartService ps = win1.getContext().get(EPartService.class);
		EModelService ms = win1.getContext().get(EModelService.class);

		if (pipStack == null) {
			// Find the MArea
			List<MArea> areas = ms.findElements(win1, null, MArea.class, null);
			if (areas.size() > 0) {
				MArea area = areas.get(0);
				List<MPartStack> areaStacks = ms.findElements(area, null,
						MPartStack.class, null);
				if (areaStacks.size()==1) {
					pipStack =	ms.createModelElement(MPartStack.class);
					Composite areaComp = (Composite) area.getWidget();
					Rectangle ar = areaComp.getBounds();

					pipComp = new Composite(areaComp, SWT.BORDER);
					pipComp.setSize((ar.width / 2) - 20, (ar.height / 2) - 20);
					pipComp.setLocation((ar.width / 2) - 25, (ar.height / 2) - 25);
					pipComp.moveAbove(null);
					pipComp.setLayout(new FillLayout());

					pipStack.setVisible(true);
					Control stackCtrl = (Control) pipStack.getWidget();
					stackCtrl.setParent(pipComp);
					pipComp.layout(true);
				}
			}
		} else {
			pipStack.setVisible(true);
			pipComp.dispose();
			pipStack = null;
			pipComp = null;
		}
		return null;
	}
}

@vogella vogella added the enhancement New feature or request label Jul 16, 2024
@vogella
Copy link
Contributor Author

vogella commented Jul 16, 2024

Closing as this is only intended for a FYI (and I did not find a better place to put it).

@vogella vogella closed this as completed Jul 16, 2024
@HeikoKlare
Copy link
Contributor

Thank you for the pointer, @vogella! That's really interesting.

@Wittmaxi
Copy link

Wittmaxi commented Jul 16, 2024

Thank you @vogella :)
Nice to see that we are not the first ones to think of this! What a shame this was never used more widely

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants