Example usage for org.eclipse.jface.viewers TableViewer TableViewer

List of usage examples for org.eclipse.jface.viewers TableViewer TableViewer

Introduction

In this page you can find the example usage for org.eclipse.jface.viewers TableViewer TableViewer.

Prototype

public TableViewer(Composite parent, int style) 

Source Link

Document

Creates a table viewer on a newly-created table control under the given parent.

Usage

From source file:com.astra.ses.spell.database.browser.views.telemetry.TelemetryViewPart.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    GridLayout parentLayout = new GridLayout(1, true);
    parentLayout.marginHeight = 0;//from w w  w.j  a va  2s .  c om
    parentLayout.marginWidth = 0;
    parent.setLayout(parentLayout);

    /*
     * DB Details composite
     */
    Composite dbDetails = new Composite(parent, SWT.NONE);
    GridLayout detailsLayout = new GridLayout(2, false);
    GridData detailsData = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
    detailsLayout.marginHeight = 0;
    detailsLayout.marginWidth = 1;
    dbDetails.setLayout(detailsLayout);
    dbDetails.setLayoutData(detailsData);

    Label dbPathLabel = new Label(dbDetails, SWT.NONE);
    dbPathLabel.setText("Path");

    GridData labelData = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
    m_dbPathLabel = new Label(dbDetails, SWT.NONE);
    m_dbPathLabel.setLayoutData(labelData);
    m_dbPathLabel.addControlListener(new ControlListener() {
        @Override
        public void controlMoved(ControlEvent e) {
            /*DO NOTHING*/}

        @Override
        public void controlResized(ControlEvent e) {
            if (m_currentDB != null) {
                String dbPath = m_currentDB.getDatabasePath();
                ViewUtils.adjustLabelContents(m_dbPathLabel, dbPath);
            }
        }
    });

    Label dbVersionLabel = new Label(dbDetails, SWT.NONE);
    dbVersionLabel.setText("Version");

    m_dbDetailsLabel = new Label(dbDetails, SWT.NONE);
    m_dbDetailsLabel.setLayoutData(labelData);
    m_dbDetailsLabel.addControlListener(new ControlListener() {
        @Override
        public void controlMoved(ControlEvent e) {
            /*DO NOTHING*/}

        @Override
        public void controlResized(ControlEvent e) {
            if (m_currentDB != null) {
                String content = m_currentDB.getName() + " " + m_currentDB.getVersion();
                ViewUtils.adjustLabelContents(m_dbDetailsLabel, content);
            }
        }
    });
    /*
     * end of DB details widget
     */

    m_viewer = new TableViewer(parent, SWT.VIRTUAL | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);

    TableColumn nameCol = new TableColumn(m_viewer.getTable(), SWT.LEFT);
    nameCol.setText("Name");
    nameCol.setWidth(80);
    TableColumn descCol = new TableColumn(m_viewer.getTable(), SWT.LEFT);
    descCol.setText("Description");
    descCol.setWidth(140);

    /* Table viewer */
    GridData viewerData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
    m_viewer.getTable().setLayoutData(viewerData);
    m_viewer.getTable().setHeaderVisible(true);
    m_viewer.getTable().setLinesVisible(false);

    /* Text widget */
    GridData textData = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
    textData.horizontalIndent = 0;
    textData.verticalIndent = 0;
    m_filterText = new Text(parent, SWT.BORDER);
    m_filterText.setLayoutData(textData);
    m_filterText.addModifyListener(new ModifyListener() {
        @Override
        public void modifyText(ModifyEvent e) {
            Text filterText = (Text) e.widget;
            String filter = filterText.getText().toUpperCase();
            try {
                Pattern regex = Pattern.compile(FilterUtils.globify(filter));
                m_viewerFilter.setPattern(regex);
                m_viewer.refresh();
            } catch (PatternSyntaxException p) {
                // do nothing
            }
        }
    });

    initContents();
    initDragAction();
}

From source file:com.astra.ses.spell.gui.dialogs.StartWithParametersDialog.java

License:Open Source License

/***************************************************************************
 * Create the dialog area contents./*w  ww  . ja v  a 2  s.  c  o  m*/
 * 
 * @param parent
 *            The base composite of the dialog
 * @return The resulting contents
 **************************************************************************/
protected Control createDialogArea(Composite parent) {
    Composite ctrl = new Composite(parent, SWT.NONE);
    ctrl.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
    GridLayout controlBarLayout = new GridLayout();
    controlBarLayout.numColumns = 3;
    ctrl.setLayout(controlBarLayout);

    Button b1 = new Button(ctrl, SWT.PUSH);
    b1.setText("More");
    b1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    b1.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            addArgument();
        }
    });
    Button b2 = new Button(ctrl, SWT.PUSH);
    b2.setText("Less");
    b2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    b2.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            delArgument();
        }
    });
    Button b3 = new Button(ctrl, SWT.PUSH);
    b3.setText("Clear");
    b3.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    b3.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            clearArguments();
        }
    });

    // Main composite of the dialog area -----------------------------------
    m_viewer = new TableViewer(parent, SWT.BORDER);
    TableColumn c0 = new TableColumn(m_viewer.getTable(), SWT.NONE);
    c0.setText("#");
    c0.setAlignment(SWT.LEFT);
    c0.setResizable(false);
    TableColumn c1 = new TableColumn(m_viewer.getTable(), SWT.NONE);
    c1.setText("Argument");
    c1.setResizable(false);
    TableColumn c2 = new TableColumn(m_viewer.getTable(), SWT.NONE);
    c2.setText("Value");
    c2.setResizable(false);
    m_viewer.getTable().setHeaderVisible(true);
    m_viewer.getTable().setLinesVisible(true);
    m_viewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));

    final TableEditor editor = new TableEditor(m_viewer.getTable());
    editor.horizontalAlignment = SWT.LEFT;
    editor.grabHorizontal = true;

    m_viewer.getTable().addListener(SWT.MouseDown, new Listener() {
        public void handleEvent(Event event) {
            Table table = (Table) event.widget;
            Rectangle clientArea = table.getClientArea();
            Point pt = new Point(event.x, event.y);
            int index = table.getTopIndex();
            while (index < table.getItemCount()) {
                boolean visible = false;
                final TableItem item = table.getItem(index);
                for (int i = 1; i < table.getColumnCount(); i++) {
                    Rectangle rect = item.getBounds(i);
                    if (rect.contains(pt)) {
                        final int column = i;
                        final Text text = new Text(table, SWT.NONE);
                        Listener textListener = new Listener() {
                            public void handleEvent(final Event e) {
                                switch (e.type) {
                                case SWT.FocusOut:
                                    item.setText(column, text.getText());
                                    if (item.getText(1).isEmpty() || item.getText(2).isEmpty()) {
                                        item.setBackground(0,
                                                Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW));
                                    } else {
                                        item.setBackground(0,
                                                Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
                                    }
                                    text.dispose();
                                    break;
                                case SWT.Traverse:
                                    switch (e.detail) {
                                    case SWT.TRAVERSE_RETURN:
                                        item.setText(column, text.getText());
                                        //FALL THROUGH
                                    case SWT.TRAVERSE_ESCAPE:
                                        if (item.getText(1).isEmpty() || item.getText(2).isEmpty()) {
                                            item.setBackground(0,
                                                    Display.getCurrent().getSystemColor(SWT.COLOR_YELLOW));
                                        } else {
                                            item.setBackground(0,
                                                    Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
                                        }
                                        text.dispose();
                                        e.doit = false;
                                    }
                                    break;
                                }
                            }
                        };
                        text.addListener(SWT.FocusOut, textListener);
                        text.addListener(SWT.Traverse, textListener);
                        editor.setEditor(text, item, i);
                        text.setText(item.getText(i));
                        text.selectAll();
                        text.setFocus();
                        return;
                    }
                    if (!visible && rect.intersects(clientArea)) {
                        visible = true;
                    }
                }
                if (!visible)
                    return;
                index++;
            }
        }
    });

    m_viewer.getControl().addControlListener(

            new ControlAdapter() {
                @Override
                public void controlResized(ControlEvent e) {
                    Table table = (Table) e.widget;
                    int width = table.getBounds().width;
                    int w1 = width / 2 - 15;
                    int w2 = width - w1 - table.getBorderWidth() * 2 - 15;
                    table.getColumn(0).setWidth(15);
                    table.getColumn(1).setWidth(w1);
                    table.getColumn(2).setWidth(w2);
                }

            });

    addArgument();

    return parent;
}

From source file:com.astra.ses.spell.gui.views.controls.SplitPanel.java

License:Open Source License

/***************************************************************************
 * Test method/*from   w  ww.  j  ava  2s  . c o m*/
 * @param args
 **************************************************************************/
public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);

    final SplitPanel panel = new SplitPanel(shell, true, 20, 50, Section.SECOND);

    // 1. THE CONTAINER
    GridLayout l = new GridLayout();
    l.numColumns = 1;
    shell.setLayout(l);
    panel.setLayoutData(new GridData(GridData.FILL_BOTH));

    panel.getSection(Section.FIRST).setLayout(new GridLayout());
    panel.getSection(Section.SECOND).setLayout(new GridLayout());

    TableViewer viewer = new TableViewer(panel.getSection(Section.FIRST), SWT.NONE);
    Table table = viewer.getTable();

    TableColumn c1 = new TableColumn(table, SWT.NONE);
    c1.setText("Idx");
    c1.setWidth(15);
    TableColumn c2 = new TableColumn(table, SWT.NONE);
    c2.setText("Description");
    c2.setWidth(120);

    for (int idx = 0; idx < 10; idx++) {
        TableItem item = new TableItem(table, SWT.NONE);
        item.setText(0, Integer.toString(idx));
        item.setText(1, "This is the item " + idx);
    }

    Button button1 = new Button(panel.getSection(Section.FIRST), SWT.PUSH);
    button1.setText("Button 1");
    button1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    button1.addSelectionListener(new SelectionListener() {
        public void widgetDefaultSelected(SelectionEvent e) {
        };

        public void widgetSelected(SelectionEvent e) {
            if (panel.getSection(Section.SECOND).getChildren().length > 5) {
                Control[] cld = panel.getSection(Section.SECOND).getChildren();
                cld[cld.length - 1].dispose();
            } else {
                Button newButton = new Button(panel.getSection(Section.SECOND), SWT.PUSH);
                newButton.setText("New button");
            }
            panel.computeSection(Section.SECOND);
        }
    });

    panel.computeSection(Section.FIRST);

    Button button2 = new Button(panel.getSection(Section.SECOND), SWT.PUSH);
    button2.setText("Button 2");
    button2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));

    panel.computeSection(Section.SECOND);

    shell.pack();
    shell.open();
    while (!shell.isDisposed()) {
        if (!display.readAndDispatch())
            display.sleep();
    }
    display.dispose();
}

From source file:com.astra.ses.spell.gui.views.controls.watchvariables.WatchVariablesPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    m_top = new Composite(parent, SWT.BORDER);
    m_top.setLayoutData(new GridData(GridData.FILL_BOTH));

    GridLayout gLayout = new GridLayout();
    gLayout.numColumns = 1;/*from  w  w w.j  a v  a  2  s .co  m*/
    gLayout.marginTop = 0;
    m_top.setLayout(gLayout);

    m_viewer = new TableViewer(m_top, SWT.MULTI | SWT.BORDER);
    m_viewer.setContentProvider(new WatchVariablesContentProvider());
    m_viewer.setLabelProvider(new WatchVariablesLabelProvider());
    m_viewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    m_viewer.getTable().addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDoubleClick(MouseEvent e) {
            IStructuredSelection sel = (IStructuredSelection) m_viewer.getSelection();
            VariableData var = (VariableData) sel.getFirstElement();
            VariableDetailDialog dialog = new VariableDetailDialog(getSite().getShell(), var);
            dialog.open();
        }
    });
    new WatchVariablesMenuManager(m_viewer, this);

    createColumns();
    createOptions(m_top);

    ProcedureManager mgr = (ProcedureManager) ServiceManager.get(ProcedureManager.ID);
    IProcedure procedure = mgr.getProcedure(m_procId);

    m_viewer.setInput(procedure.getVariableManager());

    // Make cells editable
    setCellEditors();

    // Initialize this page according to the procedure status
    setStatus(procedure.getDataProvider().getExecutorStatus());

    ProcedureBridge.get().addProcedureStatusListener(this);
}

From source file:com.astra.ses.spell.gui.views.TabbedView.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {

    ConfigurationManager configurationMgr = (ConfigurationManager) ServiceManager.get(ConfigurationManager.ID);
    m_procId = (String) configurationMgr.getSelection(IConfig.ID_PROCEDURE_SELECTION);
    ProcedureManager ProcedureMgr = (ProcedureManager) ServiceManager.get(ProcedureManager.ID);

    // Get the AsRun file
    ServerFileType fileType = ServerFileType.EXECUTOR_LOG;
    if (getViewSite().getSecondaryId().matches(".* - AS-RUN")) {
        fileType = ServerFileType.ASRUN;
    }//from   www .j av  a  2 s  . c om
    m_tabbedFile = ProcedureMgr.getServerFile(m_procId, fileType);

    m_viewer = new TableViewer(parent, SWT.VIRTUAL | SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL);
    String[] headerLabels = m_tabbedFile.getHeaderLabels();
    int[] headerLabelsSize = m_tabbedFile.getHeaderLabelsSize();

    Table table = m_viewer.getTable();

    for (int i = 0; i < headerLabels.length; i++) {
        TableColumn col = new TableColumn(table, SWT.LEFT);
        col.setText(headerLabels[i]);
        col.setWidth(headerLabelsSize[i]);
    }

    GridData viewerData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
    table.setLayoutData(viewerData);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    setPartName(getViewSite().getSecondaryId());
    setTitleToolTip(getViewSite().getSecondaryId());

    initContents();
}

From source file:com.astra.ses.spell.gui.watchvariables.views.controls.WatchVariablesPage.java

License:Open Source License

@Override
public void createControl(Composite parent) {
    m_top = new Composite(parent, SWT.BORDER);
    m_top.setLayoutData(new GridData(GridData.FILL_BOTH));

    GridLayout gLayout = new GridLayout();
    gLayout.numColumns = 1;// www .j  a  v a2  s. c o  m
    gLayout.marginTop = 0;
    m_top.setLayout(gLayout);

    m_viewer = new TableViewer(m_top, SWT.MULTI | SWT.BORDER);
    m_viewer.setContentProvider(new WatchVariablesContentProvider());
    m_viewer.setLabelProvider(new WatchVariablesLabelProvider());
    m_viewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    m_viewer.getTable().addMouseListener(new MouseAdapter() {
        @Override
        public void mouseDoubleClick(MouseEvent e) {
            IStructuredSelection sel = (IStructuredSelection) m_viewer.getSelection();
            VariableData var = (VariableData) sel.getFirstElement();
            FormatVariableValueJob job = new FormatVariableValueJob(var);
            CommandHelper.executeInProgress(job, true, true);
            if (job.result.equals(CommandResult.SUCCESS)) {
                VariableDetailDialog dialog = new VariableDetailDialog(getSite().getShell(), var.name,
                        job.details);
                dialog.open();
            }
        }
    });
    new WatchVariablesMenuManager(m_viewer, this);

    createColumns();
    createOptions(m_top);

    IWatchVariables watch = (IWatchVariables) ServiceManager.get(IWatchVariables.class);
    m_manager = watch.getVariableManager(m_proc.getProcId());

    Logger.debug("Assign variable manager", Level.PROC, this);

    m_viewer.setInput(m_manager);

    m_manager.addWatchListener(this);

    // Make cells editable
    setCellEditors();
}

From source file:com.astra.ses.spell.tabbed.ui.editor.TabularEditor.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    GridLayout parentLayout = new GridLayout(1, true);
    parentLayout.marginHeight = 0;//  w w  w.  ja v a  2  s.co m
    parentLayout.marginWidth = 0;
    parent.setLayout(parentLayout);

    /*
     * Create clipboard object
     */
    m_clipboard = new Clipboard(parent.getDisplay());

    /*
     * Composite for showing the current cell value
     */
    Composite currentCellComposite = new Composite(parent, SWT.NONE);
    GridData compositeData = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
    currentCellComposite.setLayoutData(compositeData);
    GridLayout cellLayout = new GridLayout(2, false);
    cellLayout.marginHeight = 0;
    cellLayout.marginWidth = 0;
    currentCellComposite.setLayout(cellLayout);
    // LABEL
    Label cellLabel = new Label(currentCellComposite, SWT.NONE);
    cellLabel.setText("Value: ");
    // TEXT WIDGET
    m_currentCellLabel = new Label(currentCellComposite, SWT.BORDER);
    GridData cellData = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
    m_currentCellLabel.setLayoutData(cellData);
    /*
     * Table
     */
    /* Number of columns */
    int numColumns = m_input.getColumnCount();
    /* Create table viewer */
    m_table = new TableViewer(parent,
            SWT.VIRTUAL | SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
    /* Configure table presentation */
    configureTable(m_table);
    /* Set table contents */
    m_table.setInput(m_input);

    /*
     * Filter composite
     */

    if (!filteringAllowed()) {
        return;
    }

    Composite filterComposite = new Composite(parent, SWT.NONE);
    GridLayout filterLayout = new GridLayout((numColumns * 2) + 1, false);
    filterLayout.marginHeight = 0;
    filterLayout.marginWidth = 0;
    filterComposite.setLayout(filterLayout);
    /*
     * Filter Label
     */
    Label filterLabel = new Label(filterComposite, SWT.NONE);
    filterLabel.setText("Filter columns: ");
    /*
     * Text widgets for filtering columns
     */
    for (int i = 0; i < numColumns; i++) {
        Label colLabel = new Label(filterComposite, SWT.NONE);
        colLabel.setText(m_table.getTable().getColumn(i).getText());

        Text colFilterText = new Text(filterComposite, SWT.BORDER);
        final ColumnFilter colViewerFilter = new ColumnFilter(Pattern.compile(FilterUtils.globify("")), i);
        m_table.addFilter(colViewerFilter);
        colFilterText.addModifyListener(new ModifyListener() {
            @Override
            public void modifyText(ModifyEvent e) {
                Text filterText = (Text) e.widget;
                /*
                 * Filter should be case insensitive
                 */
                final String filter = filterText.getText().toUpperCase();
                try {
                    Pattern regex = Pattern.compile(FilterUtils.globify(filter));
                    colViewerFilter.setPattern(regex);
                    m_table.refresh();
                } catch (PatternSyntaxException p) {
                    // do nothing
                }
            }
        });
    }
}

From source file:com.astra.ses.spell.tabbed.ui.views.TabularView.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    GridLayout parentLayout = new GridLayout(1, true);
    parentLayout.marginHeight = 0;/*from  w w  w .j  av  a  2s  .com*/
    parentLayout.marginWidth = 0;
    parent.setLayout(parentLayout);

    TableViewer table = new TableViewer(parent, SWT.VIRTUAL | SWT.H_SCROLL | SWT.V_SCROLL);

    TabbedFileParser parser = new TabbedFileParser(m_filePath, COMMENT);
    ArrayList<String[]> m_tabbedModel = parser.getTabbedText();
    int columns = parser.getLongestLength();

    for (int i = 0; i < columns; i++) {
        TableColumn column = new TableColumn(table.getTable(), SWT.LEFT);
        column.setText(String.valueOf(i));
        column.setWidth(350);
        column.setResizable(true);
    }
    if (m_headerNames != null) {
        table.setColumnProperties(m_headerNames);
    }
    table.setContentProvider(new TabularContentProvider(columns));
    table.setLabelProvider(new TabularLabelProvider(COMMENT));

    GridData viewerData = new GridData(GridData.FILL_BOTH | GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL);
    table.getTable().setLayoutData(viewerData);
    table.getTable().setLinesVisible(true);

    table.setInput(m_tabbedModel);
}

From source file:com.axmor.eclipse.typescript.editor.preferences.TypescriptSyntaxColoringPage.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {
    fOverlayStore.load();/*from w  w w .  j av  a 2s  .c o m*/
    fOverlayStore.start();
    Composite colorComposite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    colorComposite.setLayout(layout);

    Composite editorComposite = new Composite(colorComposite, SWT.NONE);
    layout = new GridLayout();
    layout.numColumns = 2;
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    editorComposite.setLayout(layout);
    GridData gd = new GridData(GridData.FILL_BOTH);
    editorComposite.setLayoutData(gd);

    fHighlightingColorListViewer = new TableViewer(editorComposite,
            SWT.SINGLE | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    fHighlightingColorListViewer.setLabelProvider(new ColorListLabelProvider());
    fHighlightingColorListViewer.setContentProvider(new ColorListContentProvider());
    fHighlightingColorListViewer.setComparator(new WorkbenchViewerComparator());
    gd = new GridData(GridData.FILL_BOTH);
    gd.heightHint = convertHeightInCharsToPixels(5);
    fHighlightingColorListViewer.getControl().setLayoutData(gd);

    Composite stylesComposite = new Composite(editorComposite, SWT.NONE);
    layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.numColumns = 2;
    stylesComposite.setLayout(layout);
    stylesComposite.setLayoutData(new GridData(GridData.FILL_BOTH));

    Label label = new Label(stylesComposite, SWT.LEFT);
    label.setText("Color:");
    gd = new GridData();
    gd.horizontalAlignment = GridData.BEGINNING;
    label.setLayoutData(gd);

    fEnableCheckbox = new Button(stylesComposite, SWT.CHECK);
    fEnableCheckbox.setText("Enable");
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalSpan = 2;
    fEnableCheckbox.setLayoutData(gd);

    fSyntaxForegroundColorEditor = new ColorEditor(stylesComposite);
    Button foregroundColorButton = fSyntaxForegroundColorEditor.getButton();
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    foregroundColorButton.setLayoutData(gd);

    fBoldCheckBox = new Button(stylesComposite, SWT.CHECK);
    fBoldCheckBox.setText("Bold");
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalSpan = 2;
    fBoldCheckBox.setLayoutData(gd);

    fItalicCheckBox = new Button(stylesComposite, SWT.CHECK);
    fItalicCheckBox.setText("Italic");
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.horizontalAlignment = GridData.BEGINNING;
    gd.horizontalSpan = 2;
    fItalicCheckBox.setLayoutData(gd);

    Control previewer = createPreviewer(colorComposite);
    gd = new GridData(GridData.FILL_HORIZONTAL);
    gd.widthHint = convertWidthInCharsToPixels(20);
    previewer.setLayoutData(gd);

    fHighlightingColorListViewer.addSelectionChangedListener(new ISelectionChangedListener() {
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            handleSyntaxColorListSelection();
        }
    });

    foregroundColorButton.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            HighlightingColorListItem item = getHighlightingColorListItem();
            PreferenceConverter.setValue(getOverlayStore(), item.getColorKey(),
                    fSyntaxForegroundColorEditor.getColorValue());
        }
    });

    fBoldCheckBox.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            HighlightingColorListItem item = getHighlightingColorListItem();
            getOverlayStore().setValue(item.getBoldKey(), fBoldCheckBox.getSelection());
        }
    });

    fItalicCheckBox.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            HighlightingColorListItem item = getHighlightingColorListItem();
            getOverlayStore().setValue(item.getItalicKey(), fItalicCheckBox.getSelection());
        }
    });

    fEnableCheckbox.addSelectionListener(new SelectionListener() {
        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            // do nothing
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            HighlightingColorListItem item = getHighlightingColorListItem();
            if (item instanceof SemanticHighlightingColorListItem) {
                boolean enable = fEnableCheckbox.getSelection();
                getPreferenceStore().setValue(((SemanticHighlightingColorListItem) item).getEnableKey(),
                        enable);
                fEnableCheckbox.setSelection(enable);
                fSyntaxForegroundColorEditor.getButton().setEnabled(enable);
                fBoldCheckBox.setEnabled(enable);
                fItalicCheckBox.setEnabled(enable);
                uninstallSemanticHighlighting();
                installSemanticHighlighting();
            }
        }
    });

    initialize();

    return colorComposite;
}

From source file:com.bdaum.zoom.gps.internal.dialogs.TrackpointDialog.java

License:Open Source License

public void createViewer(Composite comp) {
    viewer = new TableViewer(comp, SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER | SWT.MULTI);
    GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, true);
    layoutData.widthHint = 410;//from   ww w.j  a  v a  2  s .c  o  m
    layoutData.heightHint = 500;
    viewer.getControl().setLayoutData(layoutData);
    viewer.getTable().setLinesVisible(true);
    viewer.getTable().setHeaderVisible(true);
    viewer.setContentProvider(ArrayContentProvider.getInstance());
    TableViewerColumn col1 = new TableViewerColumn(viewer, SWT.NONE);
    col1.getColumn().setWidth(170);
    col1.getColumn().setText(Messages.TrackpointDialog_start);
    col1.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof SubTrack)
                return formatDate(((SubTrack) element).getStart());
            return super.getText(element);
        }
    });
    TableViewerColumn col2 = new TableViewerColumn(viewer, SWT.NONE);
    col2.getColumn().setWidth(170);
    col2.getColumn().setText(Messages.TrackpointDialog_end);
    col2.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof SubTrack)
                return formatDate(((SubTrack) element).getEnd());
            return super.getText(element);
        }
    });
    TableViewerColumn col3 = new TableViewerColumn(viewer, SWT.NONE);
    col3.getColumn().setWidth(70);
    col3.getColumn().setAlignment(SWT.RIGHT);
    col3.getColumn().setText(Messages.TrackpointDialog_duration);
    col3.setLabelProvider(new ColumnLabelProvider() {
        @Override
        public String getText(Object element) {
            if (element instanceof SubTrack) {
                SubTrack subTrack = (SubTrack) element;
                return formatTime((subTrack.getEnd() - subTrack.getStart() + 30000L) / 60000L);
            }
            return super.getText(element);
        }
    });
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            updateButtons();
            updateMap();
        }
    });
    viewer.setInput(subtracks);
}