Example usage for org.eclipse.jface.preference IPreferencePage getControl

List of usage examples for org.eclipse.jface.preference IPreferencePage getControl

Introduction

In this page you can find the example usage for org.eclipse.jface.preference IPreferencePage getControl.

Prototype

Control getControl();

Source Link

Document

Returns the top level control for this dialog page.

Usage

From source file:com.siteview.mde.internal.runtime.spy.sections.ActiveHelpSection.java

License:Open Source License

public void build(ScrolledForm form, SpyFormToolkit toolkit, ExecutionEvent event) {
    this.toolkit = toolkit;
    final Shell shell = HandlerUtil.getActiveShell(event);
    Object object = shell.getData();
    if (object == null)
        return;/*  w ww .j  ava  2 s .co m*/

    StringBuffer helpBuffer = new StringBuffer();
    // process help
    // TODO we need to make this cleaner... help processing is complicated atm
    if (object instanceof PreferenceDialog) {
        PreferenceDialog dialog = (PreferenceDialog) object;
        IPreferencePage page = (IPreferencePage) dialog.getSelectedPage();
        processHelp(page.getControl().getShell(), helpBuffer);
        processChildren(page.getControl(), helpBuffer);
    } else if (object instanceof Dialog) {
        Dialog dialog = (Dialog) object;
        processChildren(dialog.getShell(), helpBuffer);
    } else {
        helpBuffer.append(processControlHelp(event, toolkit));
    }

    if (helpBuffer != null && helpBuffer.length() > 0) {
        Section section = toolkit.createSection(form.getBody(), ExpandableComposite.TITLE_BAR);
        section.setText(MDERuntimeMessages.SpyDialog_activeHelpSection_title);
        section.clientVerticalSpacing = 9;

        FormText text = toolkit.createFormText(section, true);
        section.setClient(text);
        TableWrapData td = new TableWrapData();
        td.align = TableWrapData.FILL;
        td.grabHorizontal = true;
        section.setLayoutData(td);

        Image image = PDERuntimePluginImages.get(PDERuntimePluginImages.IMG_CONTEXTID_OBJ);
        text.setImage("contextid", image); //$NON-NLS-1$

        StringBuffer buffer = new StringBuffer();
        buffer.append("<form>"); //$NON-NLS-1$
        buffer.append("<p>"); //$NON-NLS-1$
        buffer.append(MDERuntimeMessages.SpyDialog_activeHelpSection_desc);
        buffer.append("</p>"); //$NON-NLS-1$
        buffer.append(helpBuffer.toString());
        buffer.append("</form>"); //$NON-NLS-1$
        String content = buffer.toString().replaceAll("&", "&amp;"); //$NON-NLS-1$ //$NON-NLS-2$
        text.setText(content, true, false);
    }

}

From source file:net.sourceforge.eclipsetrader.trading.wizards.accounts.AccountSettingsDialog.java

License:Open Source License

protected void okPressed() {
    SafeRunnable.run(new SafeRunnable() {
        private boolean errorOccurred;

        /* (non-Javadoc)
         * @see org.eclipse.core.runtime.ISafeRunnable#run()
         *//*w ww  . j  ava2s .c  o  m*/
        public void run() {
            getButton(IDialogConstants.OK_ID).setEnabled(false);
            errorOccurred = false;
            boolean hasFailedOK = false;
            try {
                // Notify all the pages and give them a chance to abort
                Iterator nodes = getPreferenceManager().getElements(PreferenceManager.PRE_ORDER).iterator();
                while (nodes.hasNext()) {
                    IPreferenceNode node = (IPreferenceNode) nodes.next();
                    IPreferencePage page = node.getPage();
                    if (page != null && page.getControl() != null) {
                        if (!page.performOk()) {
                            hasFailedOK = true;
                            return;
                        }
                    }
                }
            } catch (Exception e) {
                handleException(e);
            } finally {
                //Don't bother closing if the OK failed
                if (hasFailedOK)
                    return;

                if (!errorOccurred)
                    //Give subclasses the choice to save the state of the
                    //preference pages.
                    handleSave();

                close();
            }
        }

        /* (non-Javadoc)
         * @see org.eclipse.core.runtime.ISafeRunnable#handleException(java.lang.Throwable)
         */
        public void handleException(Throwable e) {
            errorOccurred = true;

            Policy.getLog().log(new Status(IStatus.ERROR, Policy.JFACE, 0, e.toString(), e));

            setSelectedNodePreference(null);
            String message = JFaceResources.getString("SafeRunnable.errorMessage"); //$NON-NLS-1$
            MessageDialog.openError(getShell(), JFaceResources.getString("Error"), message); //$NON-NLS-1$

        }
    });
}

From source file:net.sourceforge.eclipsetrader.trading.wizards.accounts.NewAccountWizard.java

License:Open Source License

public boolean performFinish() {
    for (Iterator iter = additionalPages.iterator(); iter.hasNext();) {
        IPreferencePage page = (PreferencePage) ((WizardPageAdapter) iter.next()).getPreferencePage();
        if (page.getControl() != null)
            page.performOk();/*from  www  . j av  a2s  .co m*/
    }

    account = CorePlugin.createAccount(pluginSelectionPage.getPluginId(), preferenceStore, new ArrayList());
    account.setPluginId(pluginSelectionPage.getPluginId());
    account.setGroup(group);
    account.setDescription(generalPage.getText());
    account.setCurrency(generalPage.getCurrency());
    account.setInitialBalance(generalPage.getBalance());

    if (group != null) {
        account.setGroup(group);
        CorePlugin.getRepository().save(group);
    }

    CorePlugin.getRepository().save(account);

    return true;
}

From source file:org.eclipse.pde.internal.runtime.spy.sections.ActiveHelpSection.java

License:Open Source License

public void build(ScrolledForm form, SpyFormToolkit toolkit, ExecutionEvent event) {
    this.toolkit = toolkit;
    final Shell shell = HandlerUtil.getActiveShell(event);
    Object object = shell.getData();
    if (object == null)
        return;// w w  w  . j av a2  s.co  m

    StringBuffer helpBuffer = new StringBuffer();
    // process help
    // TODO we need to make this cleaner... help processing is complicated atm
    if (object instanceof PreferenceDialog) {
        PreferenceDialog dialog = (PreferenceDialog) object;
        IPreferencePage page = (IPreferencePage) dialog.getSelectedPage();
        processHelp(page.getControl().getShell(), helpBuffer);
        processChildren(page.getControl(), helpBuffer);
    } else if (object instanceof Dialog) {
        Dialog dialog = (Dialog) object;
        processChildren(dialog.getShell(), helpBuffer);
    } else {
        helpBuffer.append(processControlHelp(event, toolkit));
    }

    if (helpBuffer != null && helpBuffer.length() > 0) {
        Section section = toolkit.createSection(form.getBody(), ExpandableComposite.TITLE_BAR);
        section.setText(PDERuntimeMessages.SpyDialog_activeHelpSection_title);
        section.clientVerticalSpacing = 9;

        FormText text = toolkit.createFormText(section, true);
        section.setClient(text);
        TableWrapData td = new TableWrapData();
        td.align = TableWrapData.FILL;
        td.grabHorizontal = true;
        section.setLayoutData(td);

        Image image = PDERuntimePluginImages.get(PDERuntimePluginImages.IMG_CONTEXTID_OBJ);
        text.setImage("contextid", image); //$NON-NLS-1$

        StringBuffer buffer = new StringBuffer();
        buffer.append("<form>"); //$NON-NLS-1$
        buffer.append("<p>"); //$NON-NLS-1$
        buffer.append(PDERuntimeMessages.SpyDialog_activeHelpSection_desc);
        buffer.append("</p>"); //$NON-NLS-1$
        buffer.append(helpBuffer.toString());
        buffer.append("</form>"); //$NON-NLS-1$
        String content = buffer.toString().replaceAll("&", "&amp;"); //$NON-NLS-1$ //$NON-NLS-2$
        text.setText(content, true, false);
    }

}

From source file:org.eclipse.ui.internal.dialogs.WorkbenchPreferenceDialog.java

License:Open Source License

public int open() {
    IPreferencePage selectedPage = getCurrentPage();
    if ((initialPageId != null) && (selectedPage != null)) {
        Shell shell = getShell();//  www  .  j  a v a 2  s  .  co m
        if ((shell != null) && (!shell.isDisposed())) {
            shell.open(); // make the dialog visible to properly set the focus
            Control control = selectedPage.getControl();
            if (!SwtUtil.isFocusAncestor(control))
                control.setFocus();
        }
    }
    return super.open();
}

From source file:org.mailster.gui.prefs.ConfigurationDialog.java

License:Open Source License

/**
 * Shows the preference page corresponding to the given preference node.
 * Does nothing if that page is already current. This implementation
 * prevents auto resizing./* w  w  w .  jav  a  2s  .  c  o m*/
 * 
 * @param node the preference node, or <code>null</code> if none
 * @return <code>true</code> if the page flip was successful;
 *         <code>false</code> if unsuccessful
 */
protected boolean showPage(IPreferenceNode node) {
    IPreferencePage currentPage = this.getCurrentPage();
    final Composite pageContainer = this.getPageContainer();

    if (node == null)
        return false;

    // Create the page if nessessary
    if (node.getPage() == null)
        this.createPage(node);

    if (node.getPage() == null)
        return false;

    IPreferencePage newPage = this.getPage(node);
    if (newPage == currentPage)
        return true;

    if (currentPage != null && !currentPage.okToLeave())
        return (false);

    IPreferencePage oldPage = currentPage;
    this.setCurrentPage(newPage);
    currentPage = this.getCurrentPage();
    // Set the new page's container
    currentPage.setContainer(this);

    // Ensure that the page control has been created
    // (this allows lazy page control creation)
    final IPreferencePage curPage = currentPage;
    if (currentPage.getControl() == null) {
        final boolean[] failed = { false };
        SafeRunnable.run(new ISafeRunnable() {
            public void handleException(Throwable e) {
                failed[0] = true;
            }

            public void run() {
                createPageControl(curPage, pageContainer);
            }
        });
        if (failed[0])
            return false;
        // the page is responsible for ensuring the created control is
        // accessable via getControl.
        Assert.isNotNull(currentPage.getControl());
    }

    // Force calculation of the page's description label because
    // label can be wrapped.
    final Point[] size = new Point[1];
    final Point failed = new Point(-1, -1);
    SafeRunnable.run(new ISafeRunnable() {
        public void handleException(Throwable e) {
            size[0] = failed;
        }

        public void run() {
            size[0] = curPage.computeSize();
        }
    });
    if (size[0].equals(failed))
        return false;

    // Do we need resizing. Computation not needed if the
    // first page is inserted since computing the dialog's
    // size is done by calling dialog.open().
    // Also prevent auto resize if the user has manually resized
    if (oldPage != null) {
        Rectangle rect = pageContainer.getClientArea();
        Point containerSize = new Point(rect.width, rect.height);
        // Set the size to be sure we use the result of computeSize
        currentPage.setSize(containerSize);
    }
    // Ensure that all other pages are invisible
    // (including ones that triggered an exception during
    // their creation).
    Control[] children = pageContainer.getChildren();
    Control currentControl = currentPage.getControl();
    for (int i = 0; i < children.length; i++) {
        if (children[i] != currentControl)
            children[i].setVisible(false);
    }
    // Make the new page visible
    currentPage.setVisible(true);
    if (oldPage != null)
        oldPage.setVisible(false);

    // update the dialog controls
    this.update();
    return true;
}

From source file:org.netxms.ui.eclipse.tools.ExtendedPropertyDialog.java

License:Open Source License

/**
 * Create controls for all pages// w  w w. j  av a  2 s  . c o m
 */
public void createAllPages() {
    List<?> nodes = getPreferenceManager().getElements(PreferenceManager.POST_ORDER);
    Iterator<?> i = nodes.iterator();
    while (i.hasNext()) {
        IPreferenceNode node = (IPreferenceNode) i.next();
        if (node.getPage() == null)
            createPage(node);
        IPreferencePage page = getPage(node);
        page.setContainer(this);
        if (page.getControl() == null)
            page.createControl(getPageContainer());
    }
}