Search in sources :

Example 6 with IPreferenceNode

use of org.eclipse.jface.preference.IPreferenceNode in project tdi-studio-se by Talend.

the class ProjectSettingsPreferenceDialog method openPage.

@Override
public boolean openPage(String nodeId, Object data) {
    if (this instanceof IWorkbenchPreferenceContainer) {
        ((IWorkbenchPreferenceContainer) this).openPage(nodeId, data);
    } else {
        // impl by self
        final IPreferenceNode node = findNodeMatching(nodeId);
        if (node != null) {
            getTreeViewer().setSelection(new StructuredSelection(node));
            showPage(node);
        }
        IPreferencePage page = getCurrentPage();
        if (page instanceof PreferencePage) {
            ((PreferencePage) page).applyData(data);
        }
        return true;
    }
    return false;
}
Also used : PreferencePage(org.eclipse.jface.preference.PreferencePage) IPreferencePage(org.eclipse.jface.preference.IPreferencePage) IWorkbenchPreferenceContainer(org.eclipse.ui.preferences.IWorkbenchPreferenceContainer) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IPreferencePage(org.eclipse.jface.preference.IPreferencePage) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode)

Example 7 with IPreferenceNode

use of org.eclipse.jface.preference.IPreferenceNode in project tdi-studio-se by Talend.

the class ProjectSettingsPreferenceDialog method addChildrenPreferenceNodes.

@Override
public boolean addChildrenPreferenceNodes(String parentId, List<IPreferenceNode> childrenNodes) {
    IPreferenceNode findNodeMatching = findNodeMatching(parentId);
    if (findNodeMatching != null && childrenNodes != null) {
        IPreferenceNode[] subNodes = findNodeMatching.getSubNodes();
        // remove old one to make sure the add nodes is front.
        if (subNodes != null) {
            for (IPreferenceNode n : subNodes) {
                findNodeMatching.remove(n);
            }
        }
        // add new nodes.
        for (IPreferenceNode n : childrenNodes) {
            findNodeMatching.add(n);
        }
        // add back the original nodes.
        for (IPreferenceNode n : subNodes) {
            findNodeMatching.add(n);
        }
        this.getTreeViewer().refresh();
        return true;
    }
    return false;
}
Also used : IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode)

Example 8 with IPreferenceNode

use of org.eclipse.jface.preference.IPreferenceNode in project translationstudio8 by heartsome.

the class ProjectSettingDialog method addListeners.

protected void addListeners(final TreeViewer viewer) {
    viewer.addPostSelectionChangedListener(new ISelectionChangedListener() {

        private void handleError() {
            try {
                // remove the listener temporarily so that the events caused
                // by the error handling dont further cause error handling
                // to occur.
                viewer.removePostSelectionChangedListener(this);
                // select Current PageAgain;
                if (lastSuccessfulNode == null) {
                    return;
                }
                getTreeViewer().setSelection(new StructuredSelection(lastSuccessfulNode));
                getCurrentPage().setVisible(true);
                // clear Selected Node
                setSelectedNodePreference(null);
            } finally {
                viewer.addPostSelectionChangedListener(this);
            }
        }

        public void selectionChanged(SelectionChangedEvent event) {
            final Object selection = getSingleSelection(event.getSelection());
            if (selection instanceof IPreferenceNode) {
                BusyIndicator.showWhile(getShell().getDisplay(), new Runnable() {

                    public void run() {
                        if (!isCurrentPageValid()) {
                            handleError();
                        } else if (!showPage((IPreferenceNode) selection)) {
                            // Page flipping wasn't successful
                            handleError();
                        } else {
                            // Everything went well
                            lastSuccessfulNode = (IPreferenceNode) selection;
                        }
                    }
                });
            }
        }
    });
    ((Tree) viewer.getControl()).addSelectionListener(new SelectionAdapter() {

        public void widgetDefaultSelected(final SelectionEvent event) {
            ISelection selection = viewer.getSelection();
            if (selection.isEmpty()) {
                return;
            }
            IPreferenceNode singleSelection = getSingleSelection(selection);
            boolean expanded = viewer.getExpandedState(singleSelection);
            viewer.setExpandedState(singleSelection, !expanded);
        }
    });
    // Register help listener on the tree to use context sensitive help
    viewer.getControl().addHelpListener(new HelpListener() {

        public void helpRequested(HelpEvent event) {
            if (getCurrentPage() == null) {
                // no current page? open dialog's help
                openDialogHelp();
                return;
            }
            // A) A typical path: the current page has registered its own help link
            // via WorkbenchHelpSystem#setHelp(). When just call it and let
            // it handle the help request.
            Control pageControl = getCurrentPage().getControl();
            if (pageControl != null && pageControl.isListening(SWT.Help)) {
                getCurrentPage().performHelp();
                return;
            }
            // B) Less typical path: no standard listener has been created for the page.
            // In this case we may or may not have an override of page's #performHelp().
            // 1) Try to get default help opened for the dialog;
            openDialogHelp();
            // 2) Next call currentPage's #performHelp(). If it was overridden, it might switch help
            // to something else.
            getCurrentPage().performHelp();
        }

        private void openDialogHelp() {
            if (getPageContainer() == null)
                return;
            for (Control currentControl = getPageContainer(); currentControl != null; currentControl = currentControl.getParent()) {
                if (currentControl.isListening(SWT.Help)) {
                    currentControl.notifyListeners(SWT.Help, new Event());
                    break;
                }
            }
        }
    });
}
Also used : HelpEvent(org.eclipse.swt.events.HelpEvent) HelpListener(org.eclipse.swt.events.HelpListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode) Control(org.eclipse.swt.widgets.Control) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) Tree(org.eclipse.swt.widgets.Tree) DisposeEvent(org.eclipse.swt.events.DisposeEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) HelpEvent(org.eclipse.swt.events.HelpEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent)

Example 9 with IPreferenceNode

use of org.eclipse.jface.preference.IPreferenceNode in project translationstudio8 by heartsome.

the class ProjectSettingDialog method selectSavedItem.

/**
	 * Selects the saved item in the tree of preference pages. If it cannot do this it saves the first one.
	 */
protected void selectSavedItem() {
    IPreferenceNode node = findNodeMatching(getSelectedNodePreference());
    if (node == null) {
        IPreferenceNode[] nodes = preferenceManager.getRootSubNodes();
        ViewerComparator comparator = getTreeViewer().getComparator();
        if (comparator != null) {
            comparator.sort(null, nodes);
        }
        for (int i = 0; i < nodes.length; i++) {
            IPreferenceNode selectedNode = nodes[i];
            if (selectedNode != null) {
                node = selectedNode;
                break;
            }
        }
    }
    if (node != null) {
        getTreeViewer().setSelection(new StructuredSelection(node), true);
        // Keep focus in tree. See bugs 2692, 2621, and 6775.
        getTreeViewer().getControl().setFocus();
        boolean expanded = getTreeViewer().getExpandedState(node);
        getTreeViewer().setExpandedState(node, !expanded);
    }
}
Also used : ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode)

Example 10 with IPreferenceNode

use of org.eclipse.jface.preference.IPreferenceNode in project cubrid-manager by CUBRID.

the class ApplicationWorkbenchWindowAdvisor method removePlatformDependencyActions.

private void removePlatformDependencyActions() {
    // remove some menu items
    IMenuManager mm = getWindowConfigurer().getActionBarConfigurer().getMenuManager();
    for (IContributionItem item : mm.getItems()) {
        if (item == null) {
            continue;
        }
        MenuManager sm = (MenuManager) item;
        for (IContributionItem sitem : sm.getItems()) {
            if (sitem == null || sitem.getId() == null) {
                continue;
            }
            if (sitem.getId().equals("org.eclipse.ui.actions.showKeyAssistHandler") || sitem.getId().equals("com.cubrid.common.update.p2.menu.install") || sitem.getId().equals("converstLineDelimitersTo") || sitem.getId().equals("save.ext") || sitem.getId().equals("org.eclipse.ui.openLocalFile") || sitem.getId().equals("new.ext")) {
                sm.remove(sitem.getId());
                sm.update(true);
                mm.update(true);
            }
        }
    }
    // remove some tool bar items
    ICoolBarManager cm = getWindowConfigurer().getActionBarConfigurer().getCoolBarManager();
    for (IContributionItem item : cm.getItems()) {
        if (item == null || item.getId() == null) {
            continue;
        }
        if (item.getId().equals("org.eclipse.ui.edit.text.actionSet.annotationNavigation") || item.getId().equals("org.eclipse.ui.edit.text.actionSet.navigation")) {
            cm.remove(item.getId());
            cm.update(true);
        }
    }
    // remove some preference items
    PreferenceManager pm = getWindowConfigurer().getWindow().getWorkbench().getPreferenceManager();
    for (IPreferenceNode item : pm.getRootSubNodes()) {
        if (item.getId().equals("org.eclipse.help.ui.browsersPreferencePage") || item.getId().equals("org.eclipse.ui.preferencePages.Workbench")) {
            pm.remove(item.getId());
        }
    }
}
Also used : IContributionItem(org.eclipse.jface.action.IContributionItem) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) IPreferenceNode(org.eclipse.jface.preference.IPreferenceNode) PreferenceManager(org.eclipse.jface.preference.PreferenceManager) ICoolBarManager(org.eclipse.jface.action.ICoolBarManager)

Aggregations

IPreferenceNode (org.eclipse.jface.preference.IPreferenceNode)13 PreferenceManager (org.eclipse.jface.preference.PreferenceManager)6 ArrayList (java.util.ArrayList)5 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)4 List (java.util.List)2 HsPreferenceDialog (net.heartsome.cat.common.ui.dialog.HsPreferenceDialog)2 CoreException (org.eclipse.core.runtime.CoreException)2 IContributionItem (org.eclipse.jface.action.IContributionItem)2 ICoolBarManager (org.eclipse.jface.action.ICoolBarManager)2 IMenuManager (org.eclipse.jface.action.IMenuManager)2 MenuManager (org.eclipse.jface.action.MenuManager)2 IPreferencePage (org.eclipse.jface.preference.IPreferencePage)2 PreferenceLabelProvider (org.eclipse.jface.preference.PreferenceLabelProvider)2 ISelection (org.eclipse.jface.viewers.ISelection)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 Image (org.eclipse.swt.graphics.Image)2 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)2 HashMap (java.util.HashMap)1 ProjectInfoBean (net.heartsome.cat.common.bean.ProjectInfoBean)1