Example usage for org.eclipse.jface.util ConfigureColumns forTable

List of usage examples for org.eclipse.jface.util ConfigureColumns forTable

Introduction

In this page you can find the example usage for org.eclipse.jface.util ConfigureColumns forTable.

Prototype

public static boolean forTable(Table table, IShellProvider shellProvider) 

Source Link

Document

Configure the columns of the given tree in a keyboard-accessible way, using the given shell provider to parent dialogs.

Usage

From source file:org.eclipse.jface.snippets.viewers.Snippet019TableViewerAddRemoveColumnsWithEditing.java

License:Open Source License

private void addMenu(final TableViewer v) {
    final MenuManager mgr = new MenuManager();

    final Action insertEmailBefore = new Action("Insert E-Mail before") {
        @Override//  w w  w  . ja  va 2  s .  c o m
        public void run() {
            addEmailColumn(v, activeColumn);
        }
    };

    final Action insertEmailAfter = new Action("Insert E-Mail after") {
        @Override
        public void run() {
            addEmailColumn(v, activeColumn + 1);
        }
    };

    final Action removeEmail = new Action("Remove E-Mail") {
        @Override
        public void run() {
            removeEmailColumn(v);
        }
    };

    final Action configureColumns = new Action("Configure Columns...") {
        @Override
        public void run() {
            ConfigureColumns.forTable(v.getTable(), new SameShellProvider(v.getControl()));
        }
    };

    mgr.setRemoveAllWhenShown(true);
    mgr.addMenuListener(new IMenuListener() {

        @Override
        public void menuAboutToShow(IMenuManager manager) {
            if (v.getTable().getColumnCount() == 2) {
                manager.add(insertEmailBefore);
                manager.add(insertEmailAfter);
            } else {
                manager.add(removeEmail);
            }
            manager.add(configureColumns);
        }

    });

    v.getControl().setMenu(mgr.createContextMenu(v.getControl()));
}

From source file:org.eclipse.ui.internal.about.AboutFeaturesPage.java

License:Open Source License

private void handleColumnsPressed() {
    ConfigureColumns.forTable(table, this);
}

From source file:org.eclipse.ui.internal.about.AboutPluginsPage.java

License:Open Source License

/**
 * 
 */
private void handleColumnsPressed() {
    ConfigureColumns.forTable(vendorInfo.getTable(), this);
}

From source file:org.eclipse.wst.ide.remote.ui.internal.MonitorPreferencePage.java

License:Open Source License

/**
 * Create the preference options.//from www  .  j a va2s  .  com
 *
 * @param parent org.eclipse.swt.widgets.Composite
 * @return org.eclipse.swt.widgets.Control
 */
protected Control createContents(Composite parent) {
    initializeDialogUnits(parent);

    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.numColumns = 2;
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(4);
    layout.verticalSpacing = convertVerticalDLUsToPixels(3);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    composite.setLayout(layout);
    GridData data = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
    composite.setLayoutData(data);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, ContextIds.PREF);

    Text description = new Text(composite, SWT.READ_ONLY);
    description.setText(Messages.preferenceDescription);
    data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    data.horizontalSpan = 2;
    description.setLayoutData(data);

    displayButton = new Button(composite, SWT.CHECK);
    displayButton.setText(Messages.prefShowView);
    displayButton.setSelection(MonitorUIPlugin.getShowOnActivityPreference());
    data = new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING);
    data.horizontalSpan = 2;
    data.verticalIndent = 8;
    displayButton.setLayoutData(data);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(displayButton, ContextIds.PREF_SHOW);

    Label label = new Label(composite, SWT.WRAP);
    label.setText(Messages.monitorList);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.horizontalSpan = 2;
    data.verticalIndent = 8;
    label.setLayoutData(data);

    table = new Table(composite, SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
    data = new GridData(GridData.FILL_BOTH);
    data.widthHint = 350;
    table.setLayoutData(data);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(table, ContextIds.PREF_MONITORS);

    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    TableLayout tableLayout = new TableLayout();

    TableColumn statusColumn = new TableColumn(table, SWT.NONE);
    statusColumn.setText(Messages.columnStatus);
    ColumnWeightData colData = new ColumnWeightData(6, 60, true);
    tableLayout.addColumnData(colData);

    TableColumn remoteColumn = new TableColumn(table, SWT.NONE);
    remoteColumn.setText(Messages.columnRemote);
    colData = new ColumnWeightData(12, 120, true);
    tableLayout.addColumnData(colData);

    TableColumn httpColumn = new TableColumn(table, SWT.NONE);
    httpColumn.setText(Messages.columnType);
    colData = new ColumnWeightData(5, 50, true);
    tableLayout.addColumnData(colData);

    TableColumn localColumn = new TableColumn(table, SWT.NONE);
    localColumn.setText(Messages.columnLocal);
    colData = new ColumnWeightData(6, 60, true);
    tableLayout.addColumnData(colData);

    TableColumn startOnStartupColumn = new TableColumn(table, SWT.NONE);
    startOnStartupColumn.setText(Messages.columnAutoStart);
    colData = new ColumnWeightData(7, 70, true);
    tableLayout.addColumnData(colData);

    table.setLayout(tableLayout);

    tableViewer = new TableViewer(table);
    tableViewer.setContentProvider(new MonitorContentProvider());
    tableViewer.setLabelProvider(new MonitorTableLabelProvider());
    tableViewer.setInput("root");

    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            setSelection(event.getSelection());
        }
    });

    Composite buttonComp = new Composite(composite, SWT.NONE);
    layout = new GridLayout();
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = convertVerticalDLUsToPixels(3);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 1;
    buttonComp.setLayout(layout);
    data = new GridData(GridData.HORIZONTAL_ALIGN_END | GridData.VERTICAL_ALIGN_FILL);
    buttonComp.setLayoutData(data);

    Button add = SWTUtil.createButton(buttonComp, Messages.add);
    add.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            MonitorDialog dialog = new MonitorDialog(getShell());
            if (dialog.open() == Window.CANCEL)
                return;
            tableViewer.refresh();

            IMonitor[] monitors = MonitorCore.getMonitors();
            Object monitor = monitors[monitors.length - 1];
            tableViewer.setSelection(new StructuredSelection(monitor));
        }
    });

    edit = SWTUtil.createButton(buttonComp, Messages.edit);
    edit.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            IMonitor monitor = (IMonitor) getSelection().get(0);
            IMonitorWorkingCopy wc = monitor.createWorkingCopy();

            MonitorDialog dialog = new MonitorDialog(getShell(), wc);
            if (dialog.open() != Window.CANCEL) {
                try {
                    tableViewer.refresh(wc.save());
                } catch (Exception ex) {
                    // ignore
                }
            }
        }
    });
    edit.setEnabled(false);

    remove = SWTUtil.createButton(buttonComp, Messages.remove);
    remove.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Iterator iterator = getSelection().iterator();
            while (iterator.hasNext()) {
                IMonitor monitor = (IMonitor) iterator.next();
                try {
                    monitor.delete();
                } catch (Exception ex) {
                    // ignore
                }
                tableViewer.remove(monitor);

                IMonitor[] monitors = MonitorCore.getMonitors();
                if (monitors.length > 0) {
                    Object monitor2 = monitors[monitors.length - 1];
                    tableViewer.setSelection(new StructuredSelection(monitor2));
                }
            }
        }
    });
    remove.setEnabled(false);

    start = SWTUtil.createButton(buttonComp, Messages.start);
    data = (GridData) start.getLayoutData();
    data.verticalIndent = 9;
    start.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Iterator iterator = getSelection().iterator();
            while (iterator.hasNext()) {
                IMonitor monitor = (IMonitor) iterator.next();
                try {
                    monitor.start();
                } catch (CoreException ce) {
                    MessageDialog.openError(getShell(), Messages.errorDialogTitle, ce.getStatus().getMessage());
                } catch (Exception ce) {
                    MessageDialog.openError(getShell(), Messages.errorDialogTitle, ce.getMessage());
                }
                tableViewer.refresh(monitor, true);
            }
            tableViewer.setSelection(tableViewer.getSelection());
        }
    });
    start.setEnabled(false);

    stop = SWTUtil.createButton(buttonComp, Messages.stop);
    stop.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            Iterator iterator = getSelection().iterator();
            while (iterator.hasNext()) {
                IMonitor monitor = (IMonitor) iterator.next();
                try {
                    monitor.stop();
                } catch (Exception ex) {
                    // ignore
                }
                tableViewer.refresh(monitor, true);
            }
            tableViewer.setSelection(tableViewer.getSelection());
        }
    });
    stop.setEnabled(false);

    columns = SWTUtil.createButton(buttonComp, Messages.columns);
    data = (GridData) columns.getLayoutData();
    data.verticalIndent = 9;

    final MonitorPreferencePage thisClass = this;
    columns.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            ConfigureColumns.forTable(tableViewer.getTable(), thisClass);
        }
    });

    Dialog.applyDialogFont(composite);

    return composite;
}

From source file:org.eclipse.wst.server.ui.internal.RuntimePreferencePage.java

License:Open Source License

/**
 * Create the preference options./* www.ja  va 2 s  .c o m*/
 *
 * @param parent org.eclipse.swt.widgets.Composite
 * @return org.eclipse.swt.widgets.Control
 */
protected Control createContents(Composite parent) {
    initializeDialogUnits(parent);
    PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, ContextIds.PREF_GENERAL);

    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.horizontalSpacing = convertHorizontalDLUsToPixels(4);
    layout.verticalSpacing = convertVerticalDLUsToPixels(3);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 2;
    composite.setLayout(layout);
    GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
    composite.setLayoutData(data);

    Label label = new Label(composite, SWT.WRAP);
    data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    data.horizontalSpan = 2;
    label.setLayoutData(data);
    label.setText(Messages.preferenceRuntimesDescription);

    label = new Label(composite, SWT.WRAP);
    data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    data.horizontalSpan = 2;
    data.verticalIndent = 5;
    label.setLayoutData(data);
    label.setText(Messages.preferenceRuntimesTable);

    runtimeComp = new RuntimeComposite(composite, SWT.NONE, new RuntimeComposite.RuntimeSelectionListener() {
        public void runtimeSelected(IRuntime runtime) {
            if (runtime == null) {
                edit.setEnabled(false);
                remove.setEnabled(false);
                pathLabel.setText("");
            } else {
                IStatus status = runtime.validate(new NullProgressMonitor());
                if (status != null && status.getSeverity() == IStatus.ERROR) {
                    Color c = pathLabel.getDisplay().getSystemColor(SWT.COLOR_RED);
                    pathLabel.setForeground(c);
                    pathLabel.setText(status.getMessage());
                } else if (runtime.getLocation() != null) {
                    pathLabel.setForeground(edit.getForeground());
                    pathLabel.setText(runtime.getLocation() + "");
                } else
                    pathLabel.setText("");

                if (runtime.isReadOnly()) {
                    edit.setEnabled(false);
                    remove.setEnabled(false);
                } else {
                    if (runtime.getRuntimeType() != null)
                        edit.setEnabled(ServerUIPlugin.hasWizardFragment(runtime.getRuntimeType().getId()));
                    else
                        edit.setEnabled(false);
                    remove.setEnabled(true);
                }
            }
        }
    });
    runtimeComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL));

    Composite buttonComp = new Composite(composite, SWT.NONE);
    layout = new GridLayout();
    layout.horizontalSpacing = 0;
    layout.verticalSpacing = convertVerticalDLUsToPixels(3);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.numColumns = 1;
    buttonComp.setLayout(layout);
    data = new GridData(GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL);
    buttonComp.setLayoutData(data);

    Button add = SWTUtil.createButton(buttonComp, Messages.add);
    final RuntimeComposite runtimeComp2 = runtimeComp;
    add.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            if (showWizard(null) == Window.CANCEL)
                return;
            runtimeComp2.refresh();
        }
    });

    edit = SWTUtil.createButton(buttonComp, Messages.edit);
    edit.setEnabled(false);
    edit.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            IRuntime runtime = runtimeComp2.getSelectedRuntime();
            if (runtime != null) {
                IRuntimeWorkingCopy runtimeWorkingCopy = runtime.createWorkingCopy();
                if (showWizard(runtimeWorkingCopy) != Window.CANCEL) {
                    try {
                        runtimeComp2.refresh(runtime);
                    } catch (Exception ex) {
                        // ignore
                    }
                }
            }
        }
    });

    remove = SWTUtil.createButton(buttonComp, Messages.remove);
    remove.setEnabled(false);
    remove.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            IRuntime runtime = runtimeComp.getSelectedRuntime();
            if (removeRuntime(runtime))
                runtimeComp2.remove(runtime);
        }
    });

    Button search = SWTUtil.createButton(buttonComp, Messages.search);
    data = (GridData) search.getLayoutData();
    data.verticalIndent = 9;
    search.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            try {
                // select a target directory for the search
                DirectoryDialog directoryDialog = new DirectoryDialog(getShell());
                directoryDialog.setMessage(Messages.dialogRuntimeSearchMessage);
                directoryDialog.setText(Messages.dialogRuntimeSearchTitle);

                String pathStr = directoryDialog.open();
                if (pathStr == null)
                    return;

                final IPath path = new Path(pathStr);

                final ProgressMonitorDialog dialog = new ProgressMonitorDialog(getShell());
                dialog.setBlockOnOpen(false);
                dialog.setCancelable(true);
                dialog.open();
                final IProgressMonitor monitor = dialog.getProgressMonitor();
                final IRuntimeLocator[] locators = ServerPlugin.getRuntimeLocators();
                monitor.beginTask(Messages.dialogRuntimeSearchProgress, 100 * locators.length + 10);
                final List<IRuntimeWorkingCopy> list = new ArrayList<IRuntimeWorkingCopy>();

                final IRuntimeLocator.IRuntimeSearchListener listener = new IRuntimeLocator.IRuntimeSearchListener() {
                    public void runtimeFound(final IRuntimeWorkingCopy runtime) {
                        dialog.getShell().getDisplay().syncExec(new Runnable() {
                            public void run() {
                                monitor.subTask(runtime.getName());
                            }
                        });
                        list.add(runtime);
                    }
                };

                IRunnableWithProgress runnable = new IRunnableWithProgress() {
                    public void run(IProgressMonitor monitor2) {
                        int size = locators.length;
                        for (int i = 0; i < size; i++) {
                            if (!monitor2.isCanceled())
                                try {
                                    locators[i].searchForRuntimes(path, listener, monitor2);
                                } catch (CoreException ce) {
                                    if (Trace.WARNING) {
                                        Trace.trace(Trace.STRING_WARNING,
                                                "Error locating runtimes: " + locators[i].getId(), ce);
                                    }
                                }
                        }
                        if (Trace.INFO) {
                            Trace.trace(Trace.STRING_INFO, "Done search");
                        }
                    }
                };
                dialog.run(true, true, runnable);

                if (Trace.FINER) {
                    Trace.trace(Trace.STRING_FINER, "Found runtimes: " + list.size());
                }

                if (!monitor.isCanceled()) {
                    if (list.isEmpty()) {
                        EclipseUtil.openError(getShell(), Messages.infoNoRuntimesFound);
                        return;
                    }
                    monitor.worked(5);
                    if (Trace.FINER) {
                        Trace.trace(Trace.STRING_FINER, "Removing duplicates");
                    }
                    List<IRuntime> good = new ArrayList<IRuntime>();
                    Iterator iterator2 = list.iterator();
                    while (iterator2.hasNext()) {
                        boolean dup = false;
                        IRuntime wc = (IRuntime) iterator2.next();

                        IRuntime[] runtimes = ServerCore.getRuntimes();
                        if (runtimes != null) {
                            int size = runtimes.length;
                            for (int i = 0; i < size; i++) {
                                if (runtimes[i].getLocation() != null
                                        && runtimes[i].getLocation().equals(wc.getLocation()))
                                    dup = true;
                            }
                        }
                        if (!dup)
                            good.add(wc);
                    }
                    monitor.worked(5);

                    if (Trace.FINER) {
                        Trace.trace(Trace.STRING_FINER, "Adding runtimes: " + good.size());
                    }
                    Iterator iterator = good.iterator();
                    while (iterator.hasNext()) {
                        IRuntimeWorkingCopy wc = (IRuntimeWorkingCopy) iterator.next();
                        wc.save(false, monitor);
                    }
                    monitor.done();
                }
                dialog.close();
            } catch (Exception ex) {
                if (Trace.SEVERE) {
                    Trace.trace(Trace.STRING_SEVERE, "Error finding runtimes", ex);
                }
            }
            runtimeComp2.refresh();
        }
    });

    Button columnsButton = SWTUtil.createButton(buttonComp, Messages.actionColumns);
    data = (GridData) columnsButton.getLayoutData();
    final RuntimePreferencePage thisClass = this;
    columnsButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            ConfigureColumns.forTable(runtimeComp.getTable(), thisClass);
        }
    });

    pathLabel = new Label(parent, SWT.NONE);
    pathLabel.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    Dialog.applyDialogFont(composite);

    return composite;
}