Example usage for org.eclipse.jface.preference PreferenceDialog getShell

List of usage examples for org.eclipse.jface.preference PreferenceDialog getShell

Introduction

In this page you can find the example usage for org.eclipse.jface.preference PreferenceDialog getShell.

Prototype

@Override
public Shell getShell() 

Source Link

Document

Returns this window's shell.

Usage

From source file:org.apache.directory.studio.ldapbrowser.common.actions.PropertiesAction.java

License:Apache License

/**
 * {@inheritDoc}//from w ww. ja  v  a 2  s .c  o  m
 */
public void run() {

    IAdaptable element = null;
    String pageId = null;
    String title = null;

    if (getSelectedValues().length == 1) {
        element = (IAdaptable) getSelectedValues()[0];
        pageId = BrowserCommonConstants.PROP_VALUE;
        title = getSelectedValues()[0].toString();
    } else if (getSelectedAttributes().length == 1) {
        element = (IAdaptable) getSelectedAttributes()[0];
        pageId = BrowserCommonConstants.PROP_ATTRIBUTE;
        title = getSelectedAttributes()[0].toString();
    } else if (getSelectedAttributeHierarchies().length == 1) {
        IAttribute att = getSelectedAttributeHierarchies()[0].getAttribute();
        element = att;
        pageId = BrowserCommonConstants.PROP_ATTRIBUTE;
        title = att.toString();
    } else if (getSelectedSearches().length == 1) {
        element = (IAdaptable) getSelectedSearches()[0];
        pageId = BrowserCommonConstants.PROP_SEARCH;
        title = getSelectedSearches()[0].getName();
    } else if (getSelectedBookmarks().length == 1) {
        element = (IAdaptable) getSelectedBookmarks()[0];
        pageId = BrowserCommonConstants.PROP_BOOKMARK;
        title = getSelectedBookmarks()[0].getName();
    } else if (getSelectedEntries().length == 1) {
        element = (IAdaptable) getSelectedEntries()[0];
        pageId = BrowserCommonConstants.PROP_ENTRY;
        title = getSelectedEntries()[0].getDn().getName();
    } else if (getSelectedSearchResults().length == 1) {
        element = (IAdaptable) getSelectedSearchResults()[0];
        pageId = BrowserCommonConstants.PROP_ENTRY;
        title = getSelectedSearchResults()[0].getDn().getName();
    }

    if (element != null) {
        PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn(getShell(), element, pageId, null,
                null);
        if (dialog != null) {
            title = Utils.shorten(title, 30);
        }

        dialog.getShell().setText(NLS.bind(Messages.getString("PropertiesAction.PropertiesForX"), title)); //$NON-NLS-1$
        dialog.open();

    }
}

From source file:org.apache.directory.studio.ldapbrowser.ui.actions.BrowserPasteAction.java

License:Apache License

private void pasteSearches(ISearch[] searches) {
    IBrowserConnection browserConnection = null;
    if (getSelectedBrowserViewCategories().length > 0) {
        browserConnection = getSelectedBrowserViewCategories()[0].getParent();
    } else if (getSelectedSearches().length > 0) {
        browserConnection = getSelectedSearches()[0].getBrowserConnection();
    }// www . j  av  a  2s .c  om

    if (browserConnection != null) {
        ISearch clone = null;
        for (ISearch search : searches) {
            SearchParameter searchParameter = (SearchParameter) search.getSearchParameter().clone();
            clone = new Search(browserConnection, searchParameter);
            browserConnection.getSearchManager().addSearch(clone);
        }

        if (searches.length == 1) {
            IAdaptable element = (IAdaptable) clone;
            String pageId = BrowserCommonConstants.PROP_SEARCH;
            String title = clone.getName();

            PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn(getShell(), element, pageId, null,
                    null);
            if (dialog != null) {
                title = Utils.shorten(title, 30);
            }
            dialog.getShell().setText(NLS.bind(Messages.getString("PropertiesAction.PropertiesForX"), title)); //$NON-NLS-1$
            dialog.open();
        }
    }
}

From source file:org.apache.directory.studio.ldapservers.actions.PropertiesAction.java

License:Apache License

/**
 * {@inheritDoc}/* w ww. j ava2 s  .c o  m*/
 */
public void run() {
    if (view != null) {
        StructuredSelection selection = (StructuredSelection) view.getViewer().getSelection();
        if (!selection.isEmpty()) {
            LdapServer server = (LdapServer) selection.getFirstElement();
            PreferenceDialog dialog = PreferencesUtil.createPropertyDialogOn(view.getViewSite().getShell(),
                    server, LdapServersPluginConstants.PROP_SERVER_PROPERTY_PAGE, null, null);
            dialog.getShell().setText(NLS.bind(Messages.getString("PropertiesAction.PropertiesFor"), //$NON-NLS-1$
                    shorten(server.getName(), 30)));
            dialog.open();
        }
    }
}

From source file:org.eclipse.datatools.connectivity.ui.actions.ConnectAction.java

License:Open Source License

public void run(IAction action) {
    if (mSelection != null && allProfilesInSelectionAreDisconnected(mSelection)) {
        List list = mSelection.toList();
        if (list == null || list.size() == 0)
            return;

        for (int i = 0; i < list.size(); i++) {
            PropertyDialogAction propertyDialogAction = new PropertyDialogAction(new SameShellProvider(mShell),
                    this);
            if (list.get(i) instanceof IConnectionProfile) {
                IConnectionProfile profile = (IConnectionProfile) list.get(i);
                StructuredSelection ssel = new StructuredSelection(profile);
                propertyDialogAction.selectionChanged(ssel);
                if (!profile.arePropertiesComplete() && propertyDialogAction.isApplicableForSelection()) {
                    PreferenceDialog dialog = propertyDialogAction.createDialog();
                    dialog.getShell()
                            .setText(ConnectivityUIPlugin.getDefault().getResourceString("ConnectAction.title", //$NON-NLS-1$
                                    new String[] { profile.getName() }));
                    String initialPage = getInitialPropertyPageID(profile);
                    if (initialPage != null) {
                        ((IWorkbenchPreferenceContainer) dialog).openPage(initialPage, null);
                    }/*from   w ww.j  a va 2 s . c  o  m*/
                    if (dialog.open() == Dialog.CANCEL) {
                        return;
                    }
                }
                ConnectActionStatusListener listener = new ConnectActionStatusListener(profile);
                profile.connect(listener);
            }
        }
    }
}

From source file:org.eclipse.datatools.connectivity.ui.actions.ViewPropertyAction.java

License:Open Source License

public void run() {
    Object selected = getSelectedObject();
    PreferenceDialog propertyDialog = ProfileUIManager.createPreferenceDialog(mViewer.getControl().getShell(),
            selected);/* w  w w  .j a va  2  s .  c o m*/
    if (propertyDialog == null)
        return;

    // check for size settings
    IDialogSettings dset = ConnectivityUIPlugin.getDefault().getDialogSettings();
    boolean foundSettings = false;
    if (dset != null) {
        IDialogSettings dSection = dset.getSection(MEMENTO_ROOT);
        if (dSection != null) {
            if (dSection.get(MEMENTO_DIALOG_SIZE_HEIGHT) != null
                    && dSection.get(MEMENTO_DIALOG_SIZE_HEIGHT).trim().length() > 0) {
                mShellHeight = dSection.getInt(MEMENTO_DIALOG_SIZE_HEIGHT);
                mShellWidth = dSection.getInt(MEMENTO_DIALOG_SIZE_WIDTH);
                foundSettings = true;
            }
        }
    }
    // if we found them, set it to the old values
    if (foundSettings) {
        propertyDialog.getShell().setSize(mShellWidth, mShellHeight);
        propertyDialog.getShell().layout();
        // if not, initialize 'mShellWidth' and 'mShellHeigth'
    } else {
        mShellHeight = propertyDialog.getShell().getSize().y;
        mShellWidth = propertyDialog.getShell().getSize().x;
    }

    this.mShell = propertyDialog.getShell();
    String title = ConnectivityUIPlugin.getDefault().getResourceString("properties.dialog"); //$NON-NLS-1$
    if (selected instanceof IConnectionProfile) {
        IConnectionProfile profile = (IConnectionProfile) selected;
        title = ConnectivityUIPlugin.getDefault().getResourceString("ConnectAction.title", //$NON-NLS-1$
                new String[] { profile.getName() });
    }
    propertyDialog.getShell().setText(title);

    // add a listener to make sure we get any resizes of the dialog
    // to store for the next time
    this.mShell.addControlListener(new ControlListener() {

        public void controlMoved(ControlEvent e) {
        }

        public void controlResized(ControlEvent e) {
            if (e.getSource() instanceof Shell) {
                Shell shell = (Shell) e.getSource();
                ViewPropertyAction.this.mShellHeight = shell.getSize().y;
                ViewPropertyAction.this.mShellWidth = shell.getSize().x;
            }
        }
    });

    // check to see if the profile is in a read-only repository
    // and if so, disable the controls on each page selected
    boolean inReadOnlyRepository = false;
    if (getSelectedObject() instanceof IConnectionProfile) {
        IConnectionProfile profile = (IConnectionProfile) getSelectedObject();
        if (profile.getParentProfile() != null) {
            IManagedConnection imc = ((IConnectionProfile) profile.getParentProfile()).getManagedConnection(
                    IConnectionProfileRepositoryConstants.REPOSITORY_CONNECTION_FACTORY_ID);
            if (imc != null && imc.isConnected()) {
                IConnectionProfileRepository repo = (IConnectionProfileRepository) imc.getConnection()
                        .getRawConnection();
                inReadOnlyRepository = repo.isReadOnly();
            }
        }
    }

    // handle the initial page selected in the dialog for the
    // read only repository page disabling...
    propertyDialog.addPageChangedListener(new PropertyPageChangeListener(inReadOnlyRepository));
    if (inReadOnlyRepository && propertyDialog.getSelectedPage() != null) {
        PropertyPage page = (PropertyPage) propertyDialog.getSelectedPage();
        if (propertyDialog.getSelectedPage() instanceof ConnectionProfileDetailsPage
                || propertyDialog.getSelectedPage() instanceof ProfileDetailsPropertyPage) {
            if (page.getControl() instanceof Composite) {
                Composite composite = (Composite) page.getControl();
                if (inReadOnlyRepository)
                    disableControls(composite, !inReadOnlyRepository, true);
            }
        } else if (propertyDialog.getSelectedPage() instanceof PropertyPage) {
            if (page.getControl() instanceof Composite) {
                Composite composite = (Composite) page.getControl();
                disableControls(composite, !inReadOnlyRepository);
            }
        }
    }
    int rtn_val = propertyDialog.open();
    if (rtn_val == Dialog.OK)
        saveState();

    mViewer.setSelection(mViewer.getSelection());
}

From source file:org.eclipse.edt.ide.internal.sql.util.RDBConnectionUtility.java

License:Open Source License

public static IStatus connectWithPromptIfNeeded(IConnectionProfile profile, boolean reprompt) {
    String profileName = profile.getName();

    Shell shell = Display.getCurrent().getActiveShell();
    IStatus connectionStatus = null;//from  w w w  .  java 2 s . c o m
    ConnectionInfo info = null;
    if (profile != null) {
        if (shell == null) {
            connectionStatus = profile.connect();
        } else {
            connectionStatus = profile.connectWithoutJob();
            if (reprompt && profile.getConnectionState() != IConnectionProfile.CONNECTED_STATE
                    && connectionStatus.getCode() != IStatus.OK) // could be marked OK if the profile can't be found for some reason
            {
                String title = NLS.bind(SQLNlsStrings.SQL_CONNECTION_FAILURE_MSG, profile.getName());
                MessageDialog.openInformation(shell, title,
                        connectionStatus.getChildren()[0].getException().getLocalizedMessage());

                // Prompt to fix properties
                PropertyDialogAction propertyDialogAction = new PropertyDialogAction(
                        new SameShellProvider(shell), new ConnectionPropertiesWizardSelectionProvider(profile));

                StructuredSelection selection = new StructuredSelection(profile);
                propertyDialogAction.selectionChanged(selection);
                if (!profile.arePropertiesComplete() && propertyDialogAction.isApplicableForSelection()) {
                    //something in createDialog is failing to initialize the properties correctly the first time 
                    //around. I can't debug it because it crashes the debugger when I set a breakpoint, so I'll 
                    //call twice for now to get the initialization to happen until I figure it out.
                    PreferenceDialog dialog = propertyDialogAction.createDialog();
                    dialog = propertyDialogAction.createDialog();
                    String shellText = NLS.bind(SQLNlsStrings.SQL_CONNECTION_PROPERTIES_FOR, profile.getName());
                    dialog.getShell().setText(shellText);
                    IConnectionProfileProvider provider = profile.getProvider();
                    IPropertiesPersistenceHook hook = ((ConnectionProfileProvider) provider)
                            .getPropertiesPersistenceHook();
                    String initialPage = hook.getConnectionPropertiesPageID();
                    if (initialPage != null) {
                        ((IWorkbenchPreferenceContainer) dialog).openPage(initialPage, null);
                    }
                    if (dialog.open() == Dialog.CANCEL) {
                        reprompt = false;
                    }
                }
                if (reprompt) {
                    connectionStatus = profile.connectWithoutJob();
                }
            }
        }
    }

    return connectionStatus;
}

From source file:org.eclipse.help.ui.internal.views.ScopeSetDialog.java

License:Open Source License

private void doEdit() {
    IStructuredSelection ssel = (IStructuredSelection) viewer.getSelection();
    ScopeSet set = (ScopeSet) ssel.getFirstElement();
    if (set == null) {
        return;/*from  w w  w  . java2  s.  c om*/
    }
    PreferenceManager manager = new ScopePreferenceManager(descManager, set);

    if (!localOnly) {
        PreferenceDialog dialog = new ScopePreferenceDialog(getShell(), manager, descManager, set.isEditable());
        dialog.setPreferenceStore(set.getPreferenceStore());
        dialog.create();
        dialog.getShell().setText(NLS.bind(Messages.ScopePreferenceDialog_wtitle, set.getName()));
        dialog.open();
    } else {
        LocalScopeDialog localDialog = new LocalScopeDialog(getShell(), manager, descManager, set);
        localDialog.create();
        localDialog.getShell().setText(NLS.bind(Messages.ScopePreferenceDialog_wtitle, set.getName()));
        localDialog.open();
    }
}

From source file:org.eclipse.help.ui.internal.views.SearchPart.java

License:Open Source License

private void doAdvanced() {
    ScopeSet set = scopeSetManager.getActiveSet();
    PreferenceManager manager = new ScopePreferenceManager(parent.getEngineManager(), set);
    PreferenceDialog dialog = new ScopePreferenceDialog(container.getShell(), manager,
            parent.getEngineManager(), set.isEditable());
    dialog.setPreferenceStore(set.getPreferenceStore());
    dialog.create();/* w w  w.j  av  a 2  s .  com*/
    dialog.getShell().setText(NLS.bind(Messages.ScopePreferenceDialog_wtitle, set.getName()));
    dialog.open();
    updateMasters(set);
}

From source file:org.eclipse.jdt.text.tests.performance.OpenPreferencePageTest.java

License:Open Source License

public void testOpenPreferencePage() {
    Display display = EditorTestHelper.getActiveDisplay();

    PreferenceDialog d = PreferencesUtil.createPreferenceDialogOn(null, null, null, null);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(d.getShell(), IWorkbenchHelpContextIds.PREFERENCE_DIALOG);
    // HACK to get control back instantly
    d.setBlockOnOpen(false);//  ww  w  .  ja va2  s .  co  m
    d.open();
    EditorTestHelper.runEventQueue();

    Tree tree = findTree(d.getShell());
    assertNotNull(tree);

    tree.forceFocus();

    TreeItem javaNode = findTreeItem(tree.getItems(), "Java"); //$NON-NLS-1$
    assertTrue(javaNode != null);
    tree.setSelection(new TreeItem[] { javaNode });
    EditorTestHelper.runEventQueue();

    // setExpanded does not work - use keyboard events
    // item.setExpanded(true);
    SWTEventHelper.pressKeyCode(display, SWT.KEYPAD_ADD);
    long timeout = System.currentTimeMillis() + 5000;
    TreeItem editorNode = null;
    while (editorNode == null && System.currentTimeMillis() < timeout) {
        EditorTestHelper.runEventQueue();
        editorNode = findTreeItem(javaNode.getItems(), "Editor");
    }
    assertNotNull(editorNode);

    EditorTestHelper.runEventQueue();

    Rectangle bounds = editorNode.getBounds();
    Point p = new Point(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
    p = tree.toDisplay(p);
    Event event = new Event();
    event.type = SWT.MouseMove;
    event.x = p.x;
    event.y = p.y;
    display.post(event);
    EditorTestHelper.runEventQueue();
    event.type = SWT.MouseDown;
    event.button = 1;

    fMeter.start();
    display.post(event);
    event.type = SWT.MouseUp;
    display.post(event);
    EditorTestHelper.runEventQueue();
    fMeter.stop();
    fMeter.commit();

    d.close();

    assertPerformance(fMeter);
}

From source file:org.eclipse.oomph.setup.ui.recorder.PreferenceInitializationDialog.java

License:Open Source License

public PreferenceInitializationDialog(PreferenceDialog preferenceDialog, PreferenceManager preferenceManager) {
    super(preferenceDialog.getShell(), "Preference Pages", 500, 600, SetupUIPlugin.INSTANCE, true);
    this.preferenceDialog = preferenceDialog;
    this.preferenceManager = preferenceManager;
}