Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Show About Dialog in RCP 4 Application(Create Dialog and handle it )
Show About Dialog in RCP 4 Application [message #1767652] Sat, 08 July 2017 13:35 Go to next message
Davide Vergnani is currently offline Davide VergnaniFriend
Messages: 1
Registered: July 2017
Junior Member
Hi everybody,
I'm new in the eclipse rcp 4 develop, and I'm in throuble when I want to create a custom dialog. I don't know how I can handle that dialog.

My intension is to create a command whit method execute and open that dialog created in te Windows and Dialogs menu in the Application.e4xmi.

Somebody can help me?!
Re: Show About Dialog in RCP 4 Application [message #1775135 is a reply to message #1767652] Wed, 25 October 2017 08:10 Go to previous message
Mihael Schmidt is currently offline Mihael SchmidtFriend
Messages: 81
Registered: August 2010
Member
Just write a simple handler and open the dialog in the execute method.

Handler:

public class AboutHandler {
	
	@Inject
	private IEclipseContext context;
	
	@Execute
	public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell) {
		AboutDialog dialog = new AboutDialog(shell);
		
		ContextInjectionFactory.inject(dialog, context);
		
		dialog.open();
	}
}


Dialog code:
import java.io.IOException;
import java.io.InputStream;

import javax.inject.Inject;

import org.eclipse.e4.core.services.translation.TranslationService;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.util.Geometry;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;
import org.osgi.framework.FrameworkUtil;

public class AboutDialog extends Dialog {

	private final String PLUGIN_URI = "platform:/plugin/my.plugin";
	
	@Inject
	private TranslationService translations;

	public AboutDialog(Shell shell) {
		super(shell);
		setShellStyle(SWT.TITLE | SWT.RESIZE);
	}

	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setText(translations.translate("%about.dialog.title", PLUGIN_URI));
	}

	@Override
	protected Control createDialogArea(Composite parent) {
		parent.setLayout(new GridLayout(2, false));

		InputStream in = null;
		try {
			in = FrameworkUtil.getBundle(this.getClass()).getResource("/images/about-side.jpg")
					.openStream();
		}
		catch (IOException e) {
			e.printStackTrace();
		}

		Image image = new Image(Display.getCurrent(), in);

		Label sideImage = new Label(parent, SWT.BORDER);
		sideImage.setImage(image);

		GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
		Label text = new Label(parent, SWT.WRAP);
		text.setText(getDialogText());
		text.setLayoutData(layoutData);

		parent.pack();
		
		return super.createDialogArea(parent);
	}

	@Override
	protected void createButtonsForButtonBar(Composite parent) {
		createButton(parent, IDialogConstants.OK_ID,
				translations.translate("%common.close", PLUGIN_URI), true);
	}

	private String getDialogText() {
		String text = translations.translate("%about.dialog.text", PLUGIN_URI);
		return text;
	}
	
	@Override
	protected Control createContents(Composite parent) {
		Control content = super.createContents(parent);
		parent.pack();
		return content;
	}
	
	@Override
	protected void initializeBounds() {
		super.initializeBounds();
		Rectangle bounds = getShell().getBounds();
		Point location = getInitialLocation(new Point(bounds.width, bounds.height));
		getShell().setBounds(location.x, location.y, bounds.width, bounds.height);
	}
	
	/**
	 * Returns the initial location to use for the shell. The default
	 * implementation centers the shell horizontally (1/2 of the difference to
	 * the left and 1/2 to the right) and vertically (1/3 above and 2/3 below)
	 * relative to the parent shell, or display bounds if there is no parent
	 * shell.
	 * 
	 * @param initialSize
	 *            the initial size of the shell, as returned by
	 *            <code>getInitialSize</code>.
	 * @return the initial location of the shell
	 */
	protected Point getInitialLocation(Point initialSize) {
		Composite parent = getShell().getParent();

		Monitor monitor = getShell().getDisplay().getPrimaryMonitor();
		if (parent != null) {
			monitor = parent.getMonitor();
		}

		Rectangle monitorBounds = monitor.getClientArea();
		Point centerPoint;
		if (parent != null) {
			centerPoint = Geometry.centerPoint(parent.getBounds());
		} else {
			centerPoint = Geometry.centerPoint(monitorBounds);
		}

		return new Point(centerPoint.x - (initialSize.x / 2), Math.max(
				monitorBounds.y, Math.min(centerPoint.y
						- (initialSize.y * 2 / 3), monitorBounds.y
						+ monitorBounds.height - initialSize.y)));
	}
	
	@Override
	protected boolean isResizable() {
		return true;
	}
}

Previous Topic:Missing project explorer icons after update of platform (git projects)
Next Topic:P2 site
Goto Forum:
  


Current Time: Sun Nov 18 01:35:18 GMT 2018

Powered by FUDForum. Page generated in 0.02437 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top