Example usage for org.eclipse.jface.dialogs Dialog getShell

List of usage examples for org.eclipse.jface.dialogs Dialog getShell

Introduction

In this page you can find the example usage for org.eclipse.jface.dialogs Dialog getShell.

Prototype

@Override
public Shell getShell() 

Source Link

Document

Returns this window's shell.

Usage

From source file:org.eclipse.servicesregistry.search.ui.test.classifications.pageobjects.ClassificationsTreePageObject.java

License:Open Source License

private void createUi(final ClassificationTreeContribution contribution,
        final IDiscoveryEnvironment environment) {
    asyncExec(new VoidResult() {
        @Override//  w w w .  j  a v  a2  s  .  c  o  m
        public void run() {
            final Dialog dlg = new Dialog(PlatformUI.getWorkbench().getDisplay().getActiveShell()) {
                @Override
                protected Control createContents(Composite parent) {
                    parent.setLayout(new FillLayout(SWT.VERTICAL));
                    final Composite hostComposite = new Composite(parent, SWT.NONE);
                    hostComposite.setLayout(new FormLayout());
                    contribution.createUi(hostComposite, Mockito.mock(IServicesRegistryDestination.class),
                            toolkit, environment, null);
                    contribution.handleVisibilityChange(true);
                    return parent;
                }
            };

            dlg.setBlockOnOpen(false);
            dlg.open();
            shell = new SWTBotShell(dlg.getShell());
        }
    });

    Assertions.waitAssert(new IWaitCondition() {

        @Override
        public boolean checkCondition() throws ConditionCheckException {
            return shell != null;
        }
    }, "Test shell could not be created");
}

From source file:org.eclipse.ui.tests.harness.util.DialogCheck.java

License:Open Source License

/**
 * Automated test that checks all the labels and buttons of a dialog
 * to make sure there is enough room to display all the text.  Any
 * text that wraps is only approximated and is currently not accurate.
 * //from  w ww . ja v  a 2  s .  c  o m
 * @param dialog the test dialog to be verified.
 * @param assert this is the test case object, assertions will be
 * executed on this object.
 */
public static void assertDialogTexts(Dialog dialog, Assert assertion) {
    Assert.assertNotNull(dialog);
    dialog.setBlockOnOpen(false);
    dialog.open();
    Shell shell = dialog.getShell();
    verifyCompositeText(shell, assertion);
    dialog.close();
}

From source file:org.eclipse.ui.tests.leaks.LeakTests.java

License:Open Source License

/**
 * Test for leaks if dialog is disposed before it is closed.
 * This is really testing the framework rather than individual
 * dialogs, since many dialogs or windows will fail if the shell
 * is destroyed prior to closing them./*from w  ww. j  ava2 s . com*/
 * See bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=123296
 */
public void testDestroyedDialogLeaks() throws Exception {
    ReferenceQueue queue = new ReferenceQueue();
    // Use SaveAs dialog because it's simple to invoke and utilizes
    // framework function such as storing dialog bounds.  
    // We are really testing the framework itself here.
    Dialog newDialog = new SaveAsDialog(fWin.getShell());
    newDialog.setBlockOnOpen(false);
    newDialog.open();
    assertNotNull(newDialog);
    Reference ref = createReference(queue, newDialog);
    try {
        // Dispose the window before closing it.  
        newDialog.getShell().dispose();
        newDialog.close();
        newDialog = null;
        checkRef(queue, ref);
    } finally {
        ref.clear();
    }
}

From source file:org.jboss.tools.common.verification.ui.vrules.wizard.runtime2.VerifyWizardView.java

License:Open Source License

public void setDialog(Dialog d) {
    super.setDialog(d);
    d.getShell().addShellListener(new CL());
}

From source file:org.locationtech.udig.catalog.tests.ui.workflow.BasicWorkflowTest.java

License:Open Source License

@Ignore
@Test/*from  w  w w  .  jav a 2 s  .co m*/
public void testStateFailureNonBlocking() {
    Shell shell = new Shell(Display.getDefault());
    final Dialog dialog = new Dialog(shell) {
    };

    //test where one state craps out
    s4.run = false;

    Listener1 l = new Listener2() {
        @Override
        public void stateFailed(State state) {
            super.stateFailed(state);

            if (dialog.getShell().isVisible()) {

                dialog.getShell().getDisplay().asyncExec(new Runnable() {
                    public void run() {
                        dialog.close();
                    };
                });
            }

        }

        @Override
        public void finished(State state) {
            super.finished(state);
            dialog.close();
        }
    };
    pipe.addListener(l);

    pipe.start();
    pipe.next();
    pipe.next();
    pipe.next();
    pipe.next();
    pipe.next();

    //need to open a dialog here to "halt" the ui thread so that the 
    // the workbench doesn't close while the pipe is still running
    // create a watchdog to kill it after a specified amount of time
    Runnable runnable = new Runnable() {

        public void run() {
            System.out.println("Running"); //$NON-NLS-1$
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Is dialog active dialog"); //$NON-NLS-1$
            Display.getDefault().syncExec(new Runnable() {
                public void run() {
                    if (dialog.getShell().isVisible()) {
                        dialog.close();
                    }
                }
            });
        }
    };
    new Thread(runnable).start();

    dialog.setBlockOnOpen(true);
    if (!l.finished)
        dialog.open();
    if (!shell.isDisposed())
        shell.dispose();

    assertTrue(l.state1);
    assertTrue(l.state2);
    assertTrue(l.state3);
    assertTrue(!l.state4);
    assertTrue(!l.state5);
    assertTrue(!l.finished);
    assertTrue(!l.fail);
    assertEquals(i, 4);

    assertNotNull(pipe.getState(State1.class));
    assertNotNull(pipe.getState(State2.class));
    assertNotNull(pipe.getState(State3.class));
    assertNotNull(pipe.getState(State4.class));
    assertNull(pipe.getState(State5.class));

    assertTrue(pipe.getState(State1.class).ran);
    assertTrue(pipe.getState(State2.class).ran);
    assertTrue(pipe.getState(State3.class).ran);
    assertTrue(pipe.getState(State4.class).ran);

    assertEquals(pipe.getCurrentState(), s4);
}

From source file:org.nightlabs.base.ui.util.RCPUtil.java

License:Open Source License

/**
 * sets the location of a dialog so that it apperas in the center of the screen
 * @param d the Dialog to center//  ww w. j  a v a 2  s .  c  om
 */
public static void centerDialog(Dialog d) {
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    Point shellSize = d.getShell().getSize();
    int diffWidth = screenSize.width - shellSize.x;
    int diffHeight = screenSize.height - shellSize.y;
    d.getShell().setLocation(diffWidth / 2, diffHeight / 2);
}

From source file:org.talend.designer.core.ui.editor.properties.controllers.AbstractElementPropertySectionController.java

License:Open Source License

/**
 * DOC qzhang Comment method "openSQLBuilder".
 * //from   w  w  w .j a  v a2s .c o m
 * @param repositoryType
 * @param propertyName
 * @param query
 */
protected String openSQLBuilder(String repositoryType, String propertyName, String query) {
    if (repositoryType.equals(EmfComponent.BUILTIN)) {
        connParameters.setQuery(query);
        if (connParameters.isShowConfigParamDialog()) {
            if (!isUseExistingConnection()) {
                initConnectionParametersWithContext(elem,
                        part.getProcess().getContextManager().getDefaultContext());
            } else {
                initConnectionParametersWithContext(connectionNode,
                        part.getProcess().getContextManager().getDefaultContext());
            }
        }
        // add for bug TDI-20335
        if (part == null) {
            Shell parentShell = new Shell(composite.getShell().getDisplay());
            ISQLBuilderService service = (ISQLBuilderService) GlobalServiceRegister.getDefault()
                    .getService(ISQLBuilderService.class);
            Dialog sqlBuilder = service.openSQLBuilderDialog(parentShell, "", connParameters);
            sqlBuilder.open();
        } else {
            openSqlBuilderBuildIn(connParameters, propertyName);
        }

    } else if (repositoryType.equals(EmfComponent.REPOSITORY)) {
        String repositoryName2 = ""; //$NON-NLS-1$
        String repositoryId = null;
        IElementParameter memoParam = elem.getElementParameter(propertyName);
        IElementParameter repositoryParam = null;
        for (IElementParameter param : elem.getElementParameters()) {
            if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE
                    && param.getRepositoryValue().startsWith("DATABASE")) {
                repositoryParam = param;
                break;
            }
        }
        // in case no database property found, take the first property (to keep compatibility with old code)
        if (repositoryParam == null) {
            for (IElementParameter param : elem.getElementParameters()) {
                if (param.getFieldType() == EParameterFieldType.PROPERTY_TYPE) {
                    repositoryParam = param;
                    break;
                }
            }
        }

        if (repositoryParam != null) {
            IElementParameter itemFromRepository = repositoryParam.getChildParameters()
                    .get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
            String value = (String) itemFromRepository.getValue();
            repositoryId = value;
            // for (String key : this.dynamicProperty.getRepositoryConnectionItemMap().keySet()) {
            // if (key.equals(value)) {
            // repositoryName2 =
            // this.dynamicProperty.getRepositoryConnectionItemMap().get(key).getProperty().getLabel();
            // }
            // }
            /* get connection item dynamictly,not from cache ,see 16969 */
            IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            try {
                IRepositoryViewObject repobj = factory.getLastVersion(value);
                if (repobj != null) {
                    Property property = repobj.getProperty();
                    if (property != null) {
                        repositoryName2 = property.getLabel();
                    }
                }
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
        }
        // When no repository avaiable on "Repository" mode, open a MessageDialog.
        if (repositoryName2 == null || repositoryName2.length() == 0) {
            MessageDialog.openError(composite.getShell(), Messages.getString("NoRepositoryDialog.Title"), //$NON-NLS-1$
                    Messages.getString("NoRepositoryDialog.Text")); //$NON-NLS-1$
            return null;
        }

        // Part maybe not exist
        String processName = "";//$NON-NLS-1$
        String key = "";//$NON-NLS-1$

        if (elem instanceof Node) {
            processName = ((Node) elem).getProcess().getName();
            key = processName + ((Node) elem).getUniqueName();
        } else if (elem instanceof IProcess) {
            processName = ((IProcess) elem).getName();
            key = processName;
        }
        key += repositoryName2;

        final Dialog builderDialog = sqlbuilers.get(key);
        if (!composite.isDisposed() && builderDialog != null && builderDialog.getShell() != null
                && !builderDialog.getShell().isDisposed()) {
            builderDialog.getShell().setActive();
        } else {
            connParameters.setRepositoryName(repositoryName2);
            if (repositoryId != null) {
                connParameters.setRepositoryId(repositoryId);
            }
            Shell parentShell = new Shell(composite.getShell().getDisplay());
            String nodeLabel = null;
            if (elem instanceof Node) {
                nodeLabel = (String) ((Node) elem).getElementParameter(EParameterName.LABEL.getName())
                        .getValue();
            }
            TextUtil.setDialogTitle(processName, nodeLabel, elem.getElementName());

            ISQLBuilderService service = (ISQLBuilderService) GlobalServiceRegister.getDefault()
                    .getService(ISQLBuilderService.class);

            connParameters.setQuery(query);
            connParameters.setFirstOpenSqlBuilder(true); // first open Sql Builder,set true

            Dialog sqlBuilder = service.openSQLBuilderDialog(parentShell, processName, connParameters);

            sqlbuilers.put(key, sqlBuilder);
            if (Window.OK == sqlBuilder.open()) {
                if (!composite.isDisposed() && !connParameters.isNodeReadOnly()) {
                    String sql = connParameters.getQuery();
                    // modified by hyWang
                    if (!connParameters.getIfContextButtonCheckedFromBuiltIn()) {
                        sql = QueryUtil.checkAndAddQuotes(sql);
                    }
                    return sql;
                }
            }

        }
    }
    return null;
}

From source file:raptor.swt.SWTUtils.java

License:BSD License

/**
 * Centers the shell in the RaptorWindow.
 *//*from   ww  w . j  av a 2s.c  om*/
public static void centerInRaptorWindow(Dialog dialog) {
    Shell parent = Raptor.getInstance().getWindow().getShell();

    Rectangle parentSize = parent.getBounds();
    Point mySize = dialog.getShell().computeSize(0, 0);

    int locationX, locationY;
    locationX = (parentSize.width - mySize.x) / 2 + mySize.x;
    locationY = (parentSize.height - mySize.y) / 2 - mySize.y;

    dialog.getShell().setLocation(new Point(locationX, locationY));

}