Search in sources :

Example 26 with DoubleClickEvent

use of org.eclipse.jface.viewers.DoubleClickEvent in project bndtools by bndtools.

the class RepositoriesView method createPartControl.

@Override
public void createPartControl(final Composite parent) {
    // CREATE CONTROLS
    final StackLayout stackLayout = new StackLayout();
    parent.setLayout(stackLayout);
    FormToolkit toolkit = new FormToolkit(parent.getDisplay());
    Composite defaultParent = toolkit.createComposite(parent, SWT.NONE);
    FillLayout fill = new FillLayout();
    fill.marginHeight = 5;
    fill.marginWidth = 5;
    defaultParent.setLayout(fill);
    if (!Central.hasWorkspaceDirectory()) {
        FormText form = toolkit.createFormText(defaultParent, true);
        form.setText("<form><p>No workspace configuration found. <a>Create a new Bnd workspace...</a></p></form>", true, false);
        form.addHyperlinkListener(new HyperlinkAdapter() {

            @Override
            public void linkActivated(HyperlinkEvent e) {
                IWorkbench workbench = PlatformUI.getWorkbench();
                IWorkbenchWindow window = workbench.getActiveWorkbenchWindow();
                WorkspaceSetupWizard wizard = new WorkspaceSetupWizard();
                wizard.init(workbench, StructuredSelection.EMPTY);
                WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
                dialog.open();
            }
        });
    } else {
        toolkit.createLabel(defaultParent, "Repositories are loading, please wait...");
    }
    stackLayout.topControl = defaultParent;
    parent.layout();
    final Composite mainPanel = new Composite(parent, SWT.NONE);
    filterPanel = filterPart.createControl(mainPanel, 5, 5);
    Tree tree = new Tree(mainPanel, SWT.FULL_SELECTION | SWT.MULTI);
    filterPanel.setBackground(tree.getBackground());
    viewer = new TreeViewer(tree);
    contentProvider = new SearchableRepositoryTreeContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            super.inputChanged(viewer, oldInput, newInput);
            if (newInput != null) {
                stackLayout.topControl = mainPanel;
                advancedSearchAction.setEnabled(true);
                refreshAction.setEnabled(true);
                collapseAllAction.setEnabled(true);
                configureOfflineAction();
                parent.layout();
            }
        }
    };
    viewer.setContentProvider(contentProvider);
    ColumnViewerToolTipSupport.enableFor(viewer);
    viewer.setLabelProvider(new RepositoryTreeLabelProvider(false));
    getViewSite().setSelectionProvider(viewer);
    Central.addRepositoriesViewer(viewer, RepositoriesView.this);
    JpmPreferences jpmPrefs = new JpmPreferences();
    final boolean showJpmOnClick = jpmPrefs.getBrowserSelection() != JpmPreferences.PREF_BROWSER_EXTERNAL;
    // LISTENERS
    filterPart.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            String filter = (String) event.getNewValue();
            updatedFilter(filter);
        }
    });
    ViewerDropAdapter dropAdapter = new ViewerDropAdapter(viewer) {

        @Override
        public boolean validateDrop(Object target, int operation, TransferData transferType) {
            if (target == null)
                return false;
            if (canDrop(target, transferType))
                return true;
            boolean valid = false;
            if (target instanceof RepositoryPlugin) {
                if (((RepositoryPlugin) target).canWrite()) {
                    if (URLTransfer.getInstance().isSupportedType(transferType))
                        return true;
                    if (LocalSelectionTransfer.getTransfer().isSupportedType(transferType)) {
                        ISelection selection = LocalSelectionTransfer.getTransfer().getSelection();
                        if (selection instanceof IStructuredSelection) {
                            for (Iterator<?> iter = ((IStructuredSelection) selection).iterator(); iter.hasNext(); ) {
                                Object element = iter.next();
                                if (element instanceof RepositoryBundle || element instanceof RepositoryBundleVersion) {
                                    valid = true;
                                    break;
                                }
                                if (element instanceof IFile) {
                                    valid = true;
                                    break;
                                }
                                if (element instanceof IAdaptable) {
                                    IFile file = (IFile) ((IAdaptable) element).getAdapter(IFile.class);
                                    if (file != null) {
                                        valid = true;
                                        break;
                                    }
                                }
                            }
                        }
                    } else {
                        valid = true;
                    }
                }
            }
            return valid;
        }

        @Override
        public void dragEnter(DropTargetEvent event) {
            super.dragEnter(event);
            event.detail = DND.DROP_COPY;
        }

        @Override
        public boolean performDrop(Object data) {
            if (RepositoriesView.this.performDrop(getCurrentTarget(), getCurrentEvent().currentDataType, data)) {
                viewer.refresh(getCurrentTarget(), true);
                return true;
            }
            boolean copied = false;
            if (URLTransfer.getInstance().isSupportedType(getCurrentEvent().currentDataType)) {
                try {
                    URL url = new URL((String) URLTransfer.getInstance().nativeToJava(getCurrentEvent().currentDataType));
                    if (!url.getPath().endsWith(".jar")) {
                        String uris = url.toString();
                        if (uris.contains("#!/p/sha/")) {
                            MessageDialog.openWarning(null, "Dropped URL is a JPM Revision Identifier, not a JAR", "The dropped URL is a JPM identifier, can only be dropped on a JPM repository. You can also select the revision on JPM and drag the 'jar' link of the revision to any of the other repositories.");
                            return false;
                        }
                    }
                    File tmp = File.createTempFile("dwnl", ".jar");
                    try (HttpClient client = new HttpClient()) {
                        IO.copy(client.connect(url), tmp);
                    }
                    if (isJarFile(tmp)) {
                        copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), new File[] { tmp });
                    } else {
                        tmp.delete();
                        MessageDialog.openWarning(null, "Unrecognized Artifact", "The dropped URL is not recognized as a remote JAR file: " + url.toString());
                    }
                } catch (Exception e) {
                    return false;
                }
            } else if (data instanceof String[]) {
                String[] paths = (String[]) data;
                File[] files = new File[paths.length];
                for (int i = 0; i < paths.length; i++) {
                    files[i] = new File(paths[i]);
                }
                copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), files);
            } else if (data instanceof IResource[]) {
                IResource[] resources = (IResource[]) data;
                File[] files = new File[resources.length];
                for (int i = 0; i < resources.length; i++) {
                    files[i] = resources[i].getLocation().toFile();
                }
                copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), files);
            } else if (data instanceof IStructuredSelection) {
                File[] files = convertSelectionToFiles((IStructuredSelection) data);
                if (files != null && files.length > 0)
                    copied = addFilesToRepository((RepositoryPlugin) getCurrentTarget(), files);
            }
            return copied;
        }
    };
    dropAdapter.setFeedbackEnabled(false);
    dropAdapter.setExpandEnabled(false);
    viewer.addDropSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { URLTransfer.getInstance(), FileTransfer.getInstance(), ResourceTransfer.getInstance(), LocalSelectionTransfer.getTransfer() }, dropAdapter);
    viewer.addDragSupport(DND.DROP_COPY | DND.DROP_MOVE, new Transfer[] { LocalSelectionTransfer.getTransfer() }, new SelectionDragAdapter(viewer));
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            boolean writableRepoSelected = false;
            IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            Object element = selection.getFirstElement();
            if (element instanceof RepositoryPlugin) {
                RepositoryPlugin repo = (RepositoryPlugin) element;
                writableRepoSelected = repo.canWrite();
            }
            addBundlesAction.setEnabled(writableRepoSelected);
        }
    });
    tree.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseUp(MouseEvent ev) {
            Object element = ((IStructuredSelection) viewer.getSelection()).getFirstElement();
            if (element instanceof ContinueSearchElement) {
                try {
                    getViewSite().getPage().showView(Plugin.JPM_BROWSER_VIEW_ID, null, showJpmOnClick ? IWorkbenchPage.VIEW_ACTIVATE : IWorkbenchPage.VIEW_CREATE);
                } catch (PartInitException e) {
                    Plugin.getDefault().getLog().log(e.getStatus());
                }
            }
        }
    });
    viewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            if (!event.getSelection().isEmpty()) {
                IStructuredSelection selection = (IStructuredSelection) event.getSelection();
                final Object element = selection.getFirstElement();
                if (element instanceof IAdaptable) {
                    final URI uri = (URI) ((IAdaptable) element).getAdapter(URI.class);
                    if (uri == null && element instanceof RepositoryEntry) {
                        boolean download = MessageDialog.openQuestion(getSite().getShell(), "Repositories", "This repository entry is unable to be opened because it has not been downloaded. Download and open it now?");
                        if (download) {
                            final RepositoryEntry entry = (RepositoryEntry) element;
                            Job downloadJob = new Job("Downloading repository entry " + entry.getBsn()) {

                                @Override
                                protected IStatus run(IProgressMonitor monitor) {
                                    final File repoFile = entry.getFile(true);
                                    if (repoFile != null && repoFile.exists()) {
                                        getSite().getShell().getDisplay().asyncExec(new Runnable() {

                                            @Override
                                            public void run() {
                                                openURI(repoFile.toURI());
                                            }
                                        });
                                    }
                                    return Status.OK_STATUS;
                                }
                            };
                            downloadJob.setUser(true);
                            downloadJob.schedule();
                        }
                    } else if (uri != null) {
                        openURI(uri);
                    }
                } else if (element instanceof ContinueSearchElement) {
                    ContinueSearchElement searchElement = (ContinueSearchElement) element;
                    try {
                        JpmPreferences jpmPrefs = new JpmPreferences();
                        if (jpmPrefs.getBrowserSelection() == JpmPreferences.PREF_BROWSER_EXTERNAL) {
                            URI browseUrl = searchElement.browse();
                            getViewSite().getWorkbenchWindow().getWorkbench().getBrowserSupport().getExternalBrowser().openURL(browseUrl.toURL());
                        } else
                            getViewSite().getPage().showView(Plugin.JPM_BROWSER_VIEW_ID, null, IWorkbenchPage.VIEW_VISIBLE);
                    } catch (PartInitException e) {
                        Plugin.getDefault().getLog().log(e.getStatus());
                    } catch (Exception e) {
                        Plugin.getDefault().getLog().log(new Status(IStatus.ERROR, Plugin.PLUGIN_ID, 0, "Failed to load repository browser view", e));
                    }
                } else if (element instanceof RepositoryPlugin) {
                    viewer.setExpandedState(element, !viewer.getExpandedState(element));
                }
            }
        }
    });
    createContextMenu();
    // LAYOUT
    GridLayout layout = new GridLayout(1, false);
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = 0;
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    mainPanel.setLayout(layout);
    tree.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    filterPanel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    // Toolbar
    createActions();
    fillToolBar(getViewSite().getActionBars().getToolBarManager());
    prefs.addPropertyChangeListener(workspaceOfflineListener);
    // synthenic call to "refresh" so that we can get the repositories to show up in the UI
    new WorkspaceJob("Load repositories") {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
            try {
                Central.refreshPlugins();
            } catch (Exception e) {
            // ignore errors there may be no workspace yet
            }
            return Status.OK_STATUS;
        }
    }.schedule();
    IActionBars actionBars = getViewSite().getActionBars();
    actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(), refreshAction);
}
Also used : RepositoryBundle(bndtools.model.repo.RepositoryBundle) IAdaptable(org.eclipse.core.runtime.IAdaptable) RepositoryBundleVersion(bndtools.model.repo.RepositoryBundleVersion) TreeViewer(org.eclipse.jface.viewers.TreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryEntry(bndtools.model.repo.RepositoryEntry) ContinueSearchElement(bndtools.model.repo.ContinueSearchElement) Tree(org.eclipse.swt.widgets.Tree) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Job(org.eclipse.core.runtime.jobs.Job) Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) PropertyChangeEvent(java.beans.PropertyChangeEvent) JpmPreferences(bndtools.preferences.JpmPreferences) FormText(org.eclipse.ui.forms.widgets.FormText) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) DropTargetEvent(org.eclipse.swt.dnd.DropTargetEvent) FillLayout(org.eclipse.swt.layout.FillLayout) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) JarFile(java.util.jar.JarFile) SelectionDragAdapter(bndtools.utils.SelectionDragAdapter) IStatus(org.eclipse.core.runtime.IStatus) HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) IFile(org.eclipse.core.resources.IFile) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) PropertyChangeListener(java.beans.PropertyChangeListener) RemoteRepositoryPlugin(aQute.bnd.service.RemoteRepositoryPlugin) RepositoryPlugin(aQute.bnd.service.RepositoryPlugin) URI(java.net.URI) URL(java.net.URL) SearchableRepositoryTreeContentProvider(bndtools.model.repo.SearchableRepositoryTreeContentProvider) GridLayout(org.eclipse.swt.layout.GridLayout) TransferData(org.eclipse.swt.dnd.TransferData) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) StackLayout(org.eclipse.swt.custom.StackLayout) ISelection(org.eclipse.jface.viewers.ISelection) PartInitException(org.eclipse.ui.PartInitException) IActionBars(org.eclipse.ui.IActionBars) IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) MouseEvent(org.eclipse.swt.events.MouseEvent) Composite(org.eclipse.swt.widgets.Composite) MouseAdapter(org.eclipse.swt.events.MouseAdapter) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) ViewerDropAdapter(org.eclipse.jface.viewers.ViewerDropAdapter) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) IWorkbench(org.eclipse.ui.IWorkbench) WorkspaceSetupWizard(bndtools.wizards.workspace.WorkspaceSetupWizard) RepositoryTreeLabelProvider(bndtools.model.repo.RepositoryTreeLabelProvider) HttpClient(aQute.bnd.http.HttpClient) GridData(org.eclipse.swt.layout.GridData) WizardDialog(org.eclipse.jface.wizard.WizardDialog) IResource(org.eclipse.core.resources.IResource) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter)

Example 27 with DoubleClickEvent

use of org.eclipse.jface.viewers.DoubleClickEvent in project eclipse.platform.text by eclipse.

the class TemplatePreferencePage method createContents.

@Override
protected Control createContents(Composite ancestor) {
    Composite parent = new Composite(ancestor, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    parent.setLayout(layout);
    Composite innerParent = new Composite(parent, SWT.NONE);
    GridLayout innerLayout = new GridLayout();
    innerLayout.numColumns = 2;
    innerLayout.marginHeight = 0;
    innerLayout.marginWidth = 0;
    innerParent.setLayout(innerLayout);
    GridData gd = new GridData(GridData.FILL_BOTH);
    gd.horizontalSpan = 2;
    innerParent.setLayoutData(gd);
    Composite tableComposite = new Composite(innerParent, SWT.NONE);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.widthHint = 360;
    data.heightHint = convertHeightInCharsToPixels(10);
    tableComposite.setLayoutData(data);
    ColumnLayout columnLayout = new ColumnLayout();
    tableComposite.setLayout(columnLayout);
    Table table = new Table(tableComposite, SWT.CHECK | SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION | SWT.H_SCROLL | SWT.V_SCROLL);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    GC gc = new GC(getShell());
    gc.setFont(JFaceResources.getDialogFont());
    TemplateViewerComparator viewerComparator = new TemplateViewerComparator();
    TableColumn column1 = new TableColumn(table, SWT.NONE);
    column1.setText(TemplatesMessages.TemplatePreferencePage_column_name);
    int minWidth = computeMinimumColumnWidth(gc, TemplatesMessages.TemplatePreferencePage_column_name);
    columnLayout.addColumnData(new ColumnWeightData(2, minWidth, true));
    column1.addSelectionListener(new TemplateColumnSelectionAdapter(column1, 0, viewerComparator));
    TableColumn column2 = new TableColumn(table, SWT.NONE);
    column2.setText(TemplatesMessages.TemplatePreferencePage_column_context);
    minWidth = computeMinimumContextColumnWidth(gc);
    columnLayout.addColumnData(new ColumnWeightData(1, minWidth, true));
    column2.addSelectionListener(new TemplateColumnSelectionAdapter(column2, 1, viewerComparator));
    TableColumn column3 = new TableColumn(table, SWT.NONE);
    column3.setText(TemplatesMessages.TemplatePreferencePage_column_description);
    minWidth = computeMinimumColumnWidth(gc, TemplatesMessages.TemplatePreferencePage_column_description);
    columnLayout.addColumnData(new ColumnWeightData(3, minWidth, true));
    column3.addSelectionListener(new TemplateColumnSelectionAdapter(column3, 2, viewerComparator));
    TableColumn column4 = new TableColumn(table, SWT.NONE);
    column4.setAlignment(SWT.CENTER);
    column4.setText(TemplatesMessages.TemplatePreferencePage_column_autoinsert);
    minWidth = computeMinimumColumnWidth(gc, TemplatesMessages.TemplatePreferencePage_column_autoinsert);
    minWidth = Math.max(minWidth, computeMinimumColumnWidth(gc, TemplatesMessages.TemplatePreferencePage_on));
    columnLayout.addColumnData(new ColumnPixelData(minWidth, false, false));
    column4.addSelectionListener(new TemplateColumnSelectionAdapter(column4, 3, viewerComparator));
    gc.dispose();
    fTableViewer = new CheckboxTableViewer(table);
    fTableViewer.setLabelProvider(new TemplateLabelProvider());
    fTableViewer.setContentProvider(new TemplateContentProvider());
    fTableViewer.setComparator(viewerComparator);
    // Specify default sorting
    table.setSortColumn(column1);
    table.setSortDirection(viewerComparator.getDirection());
    fTableViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent e) {
            edit();
        }
    });
    fTableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent e) {
            selectionChanged1();
        }
    });
    fTableViewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            TemplatePersistenceData d = (TemplatePersistenceData) event.getElement();
            d.setEnabled(event.getChecked());
        }
    });
    BidiUtils.applyTextDirection(fTableViewer.getControl(), BidiUtils.BTD_DEFAULT);
    Composite buttons = new Composite(innerParent, SWT.NONE);
    buttons.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    buttons.setLayout(layout);
    fAddButton = new Button(buttons, SWT.PUSH);
    fAddButton.setText(TemplatesMessages.TemplatePreferencePage_new);
    fAddButton.setLayoutData(getButtonGridData(fAddButton));
    fAddButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            add();
        }
    });
    fEditButton = new Button(buttons, SWT.PUSH);
    fEditButton.setText(TemplatesMessages.TemplatePreferencePage_edit);
    fEditButton.setLayoutData(getButtonGridData(fEditButton));
    fEditButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            edit();
        }
    });
    fRemoveButton = new Button(buttons, SWT.PUSH);
    fRemoveButton.setText(TemplatesMessages.TemplatePreferencePage_remove);
    fRemoveButton.setLayoutData(getButtonGridData(fRemoveButton));
    fRemoveButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            remove();
        }
    });
    createSeparator(buttons);
    fRestoreButton = new Button(buttons, SWT.PUSH);
    fRestoreButton.setText(TemplatesMessages.TemplatePreferencePage_restore);
    fRestoreButton.setLayoutData(getButtonGridData(fRestoreButton));
    fRestoreButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            restoreDeleted();
        }
    });
    fRevertButton = new Button(buttons, SWT.PUSH);
    fRevertButton.setText(TemplatesMessages.TemplatePreferencePage_revert);
    fRevertButton.setLayoutData(getButtonGridData(fRevertButton));
    fRevertButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            revert();
        }
    });
    createSeparator(buttons);
    fImportButton = new Button(buttons, SWT.PUSH);
    fImportButton.setText(TemplatesMessages.TemplatePreferencePage_import);
    fImportButton.setLayoutData(getButtonGridData(fImportButton));
    fImportButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            import_();
        }
    });
    fExportButton = new Button(buttons, SWT.PUSH);
    fExportButton.setText(TemplatesMessages.TemplatePreferencePage_export);
    fExportButton.setLayoutData(getButtonGridData(fExportButton));
    fExportButton.addListener(SWT.Selection, new Listener() {

        @Override
        public void handleEvent(Event e) {
            export();
        }
    });
    fPatternViewer = doCreateViewer(parent);
    if (isShowFormatterSetting()) {
        fFormatButton = new Button(parent, SWT.CHECK);
        fFormatButton.setText(TemplatesMessages.TemplatePreferencePage_use_code_formatter);
        GridData gd1 = new GridData();
        gd1.horizontalSpan = 2;
        fFormatButton.setLayoutData(gd1);
        fFormatButton.setSelection(getPreferenceStore().getBoolean(getFormatterPreferenceKey()));
    }
    fTableViewer.setInput(fTemplateStore);
    fTableViewer.setAllChecked(false);
    fTableViewer.setCheckedElements(getEnabledTemplates());
    updateButtons();
    Dialog.applyDialogFont(parent);
    innerParent.layout();
    return parent;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) SelectionListener(org.eclipse.swt.events.SelectionListener) ITextListener(org.eclipse.jface.text.ITextListener) Listener(org.eclipse.swt.widgets.Listener) ModifyListener(org.eclipse.swt.events.ModifyListener) DisposeListener(org.eclipse.swt.events.DisposeListener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) IMenuListener(org.eclipse.jface.action.IMenuListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) FocusListener(org.eclipse.swt.events.FocusListener) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) ICheckStateListener(org.eclipse.jface.viewers.ICheckStateListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GC(org.eclipse.swt.graphics.GC) TemplatePersistenceData(org.eclipse.jface.text.templates.persistence.TemplatePersistenceData) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) GridData(org.eclipse.swt.layout.GridData) FocusEvent(org.eclipse.swt.events.FocusEvent) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) ModifyEvent(org.eclipse.swt.events.ModifyEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent) Event(org.eclipse.swt.widgets.Event) TextEvent(org.eclipse.jface.text.TextEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) CheckStateChangedEvent(org.eclipse.jface.viewers.CheckStateChangedEvent)

Example 28 with DoubleClickEvent

use of org.eclipse.jface.viewers.DoubleClickEvent in project linuxtools by eclipse.

the class DoubleClickTest method doDoubleClick.

private static void doDoubleClick(TreePath path) {
    CachegrindViewPart view = (CachegrindViewPart) ValgrindUIPlugin.getDefault().getView().getDynamicView();
    TreeViewer treeViewer = view.getViewer();
    ICachegrindElement element = (ICachegrindElement) path.getLastSegment();
    treeViewer.expandToLevel(element, AbstractTreeViewer.ALL_LEVELS);
    TreeSelection selection = new TreeSelection(path);
    IDoubleClickListener listener = view.getDoubleClickListener();
    listener.doubleClick(new DoubleClickEvent(treeViewer, selection));
}
Also used : ICachegrindElement(org.eclipse.linuxtools.internal.valgrind.cachegrind.model.ICachegrindElement) AbstractTreeViewer(org.eclipse.jface.viewers.AbstractTreeViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) TreeSelection(org.eclipse.jface.viewers.TreeSelection) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) CachegrindViewPart(org.eclipse.linuxtools.internal.valgrind.cachegrind.CachegrindViewPart)

Example 29 with DoubleClickEvent

use of org.eclipse.jface.viewers.DoubleClickEvent in project linuxtools by eclipse.

the class LinkedResourceDoubleClickTest method doDoubleClick.

private void doDoubleClick() {
    ValgrindViewPart view = ValgrindUIPlugin.getDefault().getView();
    CoreMessagesViewer viewer = view.getMessagesViewer();
    // get first leaf
    IValgrindMessage[] elements = (IValgrindMessage[]) viewer.getTreeViewer().getInput();
    IValgrindMessage element = elements[0];
    TreePath path = new TreePath(new Object[] { element });
    frame = null;
    while (element.getChildren().length > 0) {
        element = element.getChildren()[0];
        path = path.createChildPath(element);
        if (element instanceof ValgrindStackFrame) {
            frame = (ValgrindStackFrame) element;
        }
    }
    assertNotNull(frame);
    viewer.getTreeViewer().expandToLevel(frame, AbstractTreeViewer.ALL_LEVELS);
    TreeSelection selection = new TreeSelection(path);
    // do double click
    IDoubleClickListener listener = viewer.getDoubleClickListener();
    listener.doubleClick(new DoubleClickEvent(viewer.getTreeViewer(), selection));
}
Also used : ValgrindViewPart(org.eclipse.linuxtools.internal.valgrind.ui.ValgrindViewPart) IValgrindMessage(org.eclipse.linuxtools.valgrind.core.IValgrindMessage) TreePath(org.eclipse.jface.viewers.TreePath) TreeSelection(org.eclipse.jface.viewers.TreeSelection) ValgrindStackFrame(org.eclipse.linuxtools.internal.valgrind.core.ValgrindStackFrame) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) CoreMessagesViewer(org.eclipse.linuxtools.internal.valgrind.ui.CoreMessagesViewer)

Example 30 with DoubleClickEvent

use of org.eclipse.jface.viewers.DoubleClickEvent in project knime-core by knime.

the class KnimeResourceNavigator method createViewer.

/**
 * {@inheritDoc}
 */
@Override
protected TreeViewer createViewer(final Composite parent) {
    TreeViewer viewer = new TreeViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL) {

        @Override
        protected void handleDoubleSelect(final SelectionEvent event) {
            // the default implementation in the navigator
            // performs a collapse/expand AND an open event.
            // We only want either, depending on the selection.
            Object sel = ((StructuredSelection) getSelection()).getFirstElement();
            if (isWorkflow(sel)) {
                // this is issued asynchronously, in order to avoid bug #3478
                final TreeViewer myself = this;
                Display.getCurrent().asyncExec(new Runnable() {

                    @Override
                    public void run() {
                        KnimeResourceNavigator.this.handleOpen(new OpenEvent(myself, getSelection()));
                    }
                });
            } else {
                // expand the double-clicked element one level down
                KnimeResourceNavigator.super.handleDoubleClick(new DoubleClickEvent(this, getSelection()));
            }
        }
    };
    viewer.setUseHashlookup(true);
    initContentProvider(viewer);
    initLabelProvider(viewer);
    initFilters(viewer);
    initListeners(viewer);
    return viewer;
}
Also used : TreeViewer(org.eclipse.jface.viewers.TreeViewer) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) OpenEvent(org.eclipse.jface.viewers.OpenEvent)

Aggregations

DoubleClickEvent (org.eclipse.jface.viewers.DoubleClickEvent)68 IDoubleClickListener (org.eclipse.jface.viewers.IDoubleClickListener)67 GridData (org.eclipse.swt.layout.GridData)40 TableViewer (org.eclipse.jface.viewers.TableViewer)37 SelectionEvent (org.eclipse.swt.events.SelectionEvent)33 Composite (org.eclipse.swt.widgets.Composite)33 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)29 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)25 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)25 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)23 GridLayout (org.eclipse.swt.layout.GridLayout)21 Table (org.eclipse.swt.widgets.Table)16 TableViewerColumn (org.eclipse.jface.viewers.TableViewerColumn)15 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)13 Button (org.eclipse.swt.widgets.Button)13 Label (org.eclipse.swt.widgets.Label)13 TableColumn (org.eclipse.swt.widgets.TableColumn)13 TreeViewer (org.eclipse.jface.viewers.TreeViewer)12 ISelection (org.eclipse.jface.viewers.ISelection)11 FillLayout (org.eclipse.swt.layout.FillLayout)10