All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.geneweaver.query.ui.QueryEngineEntry Maven / Gradle / Ivy

package org.geneweaver.query.ui;

import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.layout.RowLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Monitor;
import org.eclipse.swt.widgets.Shell;

public class QueryEngineEntry {
	

	/**
	 * Command to start this application is:
	 * java -XstartOnFirstThread -jar target/gweaver-query-engine-ui-0.0.4-SNAPSHOT-jar-with-dependencies.jar
     *
	 * @param args
	 */
	public static void open() throws Throwable {
		try {
			Display display = Display.getDefault();
			Shell shell = new Shell(display);
			
			ImageDescriptor des = ImageDescriptor.createFromURL(QueryEngineEntry.class.getClassLoader().getResource("GW2-logo-blue.ico"));
			Image gwIcon = des.createImage();
			shell.setImage(gwIcon);
			createContents(shell);
			
			/** take the primary monitor */
			Monitor primary = display.getPrimaryMonitor();
			
			/** get the size of the screen */
			Rectangle bounds = primary.getBounds();
			
			/** get the size of the window */
			Rectangle rect = shell.getBounds();
	
			/** calculate the centre */
			int x = bounds.x + (bounds.width - rect.width) / 2;
			int y = bounds.y + (bounds.height - rect.height) / 2;
			
			/** set the new location */
			shell.setLocation(x, y);
			//shell.open();
			
			QueryEngineWizard wizard = new QueryEngineWizard();
			NoDefaultButtonWizardDialog dialog = new NoDefaultButtonWizardDialog(shell, wizard);
			wizard.setDialog(dialog);
			dialog.create();
			dialog.getShell().setImage(gwIcon);
			dialog.open();
			
			while(! shell.isDisposed()) { // Event loop.
				if(! display.readAndDispatch()) display.sleep();
			}
			display.dispose();
		} catch (Throwable ne) {
			System.out.println("Usage 'java -XstartOnFirstThread -jar '");
			throw ne;
		}
	}
	
	private static Control createContents(Shell parent) {
	    
	    GridLayout fl = new GridLayout();
	    fl.numColumns = 1;
	    parent.setLayout(fl);
	    Composite content = new Composite(parent, SWT.NONE);
	    content.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
	    
	    Composite buttons = new Composite(parent, SWT.NONE);
	    buttons.setLayoutData(new GridData(SWT.RIGHT, SWT.BOTTOM, true, false));
	    RowLayout rowLayout = new RowLayout();
	    rowLayout.justify = true;
	    buttons.setLayout(rowLayout);
	    
	    Button run = new Button(buttons, SWT.PUSH);
	    run.setText("Run");
	    run.setEnabled(false);
	    
	    Button close = new Button(buttons, SWT.PUSH);
	    close.setText("Close");
	    close.addSelectionListener(new SelectionAdapter() {
	    	public void widgetSelected(SelectionEvent e) {
	    		parent.close();
	    	}
	    });

	    
	    return parent;
	}

	public static String getVersion() {
		/* Must set in Maven pom:
		       true
               true
		 */
		String version = QueryEngineEntry.class.getPackage().getImplementationVersion();
		if (version==null || version.isEmpty()) version = "dev";
		return version;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy