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:cc.warlock.rcp.prefs.MacrosPreferencePage.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {

    createProfileDropDown(parent);/*from ww w. j ava2 s  .  c o m*/

    Composite main = new Composite(parent, SWT.NONE);
    main.setLayout(new GridLayout(2, false));

    Composite filterComposite = new Composite(main, SWT.NONE);
    GridLayout layout = new GridLayout(3, false);
    layout.marginWidth = layout.marginHeight = 0;
    filterComposite.setLayout(layout);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, false);
    //      data.horizontalSpan = 2;
    filterComposite.setLayoutData(data);

    new Label(filterComposite, SWT.NONE).setText("Filter: ");

    filterBook = new PageBook(filterComposite, SWT.NONE);
    filterBook.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    commandText = new Text(filterBook, SWT.BORDER);
    commandText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            macroTableView.refresh();
        }
    });

    keyComboText = new KeyStrokeText(filterBook, SWT.BORDER);
    keyComboText.addKeyStrokeLockListener(new KeyStrokeLockListener() {
        public void keyStrokeLocked() {
            macroTableView.refresh();
        }

        public void keyStrokeUnlocked() {
            macroTableView.refresh();
        }
    });

    filterBook.showPage(commandText);

    Button filterButton = new Button(filterComposite, SWT.ARROW | SWT.DOWN);
    filterMenu = new Menu(filterButton);
    filterButton.addListener(SWT.Selection, new Listener() {
        public void handleEvent(Event event) {
            filterMenu.setVisible(true);
        }
    });

    MenuItem filterByCommand = new MenuItem(filterMenu, SWT.RADIO);
    filterByCommand.setText("Filter by command");
    filterByCommand.setSelection(true);
    filterByCommand.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            MacrosPreferencePage.this.filterByCommand = true;
            filterBook.showPage(commandText);
            macroTableView.refresh();
        }
    });

    MenuItem filterByKeyCombo = new MenuItem(filterMenu, SWT.RADIO);
    filterByKeyCombo.setText("Filter by key combo");
    filterByKeyCombo.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            MacrosPreferencePage.this.filterByCommand = false;
            filterBook.showPage(keyComboText.getText());
            macroTableView.refresh();
        }
    });
    filterButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.FILL, false, false));

    new Label(main, SWT.NONE);
    macroTableView = new TableViewer(main, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL);
    TableViewerColumn commandColumn = new TableViewerColumn(macroTableView, SWT.NONE, 0);
    commandColumn.getColumn().setText("Command");
    commandColumn.getColumn().setWidth(225);
    commandColumn.setEditingSupport(new CommandEditingSupport(macroTableView));

    TableViewerColumn keyColumn = new TableViewerColumn(macroTableView, SWT.NONE, 1);
    keyColumn.getColumn().setText("Key Combination");
    keyColumn.getColumn().setWidth(125);
    keyColumn.setEditingSupport(new KeyStrokeEditingSupport(macroTableView));

    macroTableView.setUseHashlookup(true);
    macroTableView.setColumnProperties(new String[] { COLUMN_COMMAND, COLUMN_KEY });
    macroTableView.setContentProvider(ArrayContentProvider.getInstance());
    macroTableView.setLabelProvider(new LabelProvider());
    macroTableView.addFilter(new ViewerFilter() {
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            IMacro macro = (IMacro) element;
            IMacroHandler handler = macro.getHandler();

            if (handler != null && handler instanceof CommandMacroHandler)
                return true;
            else
                return false;
        }
    });
    macroTableView.addFilter(new MacroFilter());

    macroTableView.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            if (macroTableView.getSelection().isEmpty()) {
                removeMacroButton.setEnabled(false);
            } else {
                selectedMacro = (IMacro) ((IStructuredSelection) macroTableView.getSelection())
                        .getFirstElement();
                removeMacroButton.setEnabled(true);
            }
        }
    });

    //macroTableView.setInput(getSettings().getMacros());
    macroTableView.getTable().setHeaderVisible(true);
    int listHeight = macroTableView.getTable().getItemHeight() * 8;
    Rectangle trim = macroTableView.getTable().computeTrim(0, 0, 0, listHeight);
    data = new GridData(GridData.FILL, GridData.FILL, true, true);
    data.heightHint = trim.height;

    macroTableView.getTable().setLayoutData(data);

    Composite macroButtons = new Composite(main, SWT.NONE);
    macroButtons.setLayout(new GridLayout(1, true));
    macroButtons.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));

    addMacroButton = new Button(macroButtons, SWT.PUSH);
    addMacroButton.setText("Add Macro");
    addMacroButton.setImage(WarlockSharedImages.getImage(WarlockSharedImages.IMG_ADD));
    addMacroButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            addMacroSelected();
        }
    });
    addMacroButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    removeMacroButton = new Button(macroButtons, SWT.PUSH);
    removeMacroButton.setText("Remove Macro");
    removeMacroButton.setImage(WarlockSharedImages.getImage(WarlockSharedImages.IMG_REMOVE));
    removeMacroButton.setEnabled(false);
    removeMacroButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            removeMacroSelected();
        }
    });
    removeMacroButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    Label filler = new Label(macroButtons, SWT.NONE);
    filler.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    clearMacrosButton = new Button(macroButtons, SWT.PUSH);
    clearMacrosButton.setText("Clear Macros");
    clearMacrosButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            clearMacros();
        }
    });
    clearMacrosButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    defaultMacrosButton = new Button(macroButtons, SWT.PUSH);
    defaultMacrosButton.setText("Reset to Defaults");
    defaultMacrosButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            setupDefaultMacros();
        }
    });
    defaultMacrosButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    updateData();

    return main;
}

From source file:cc.warlock.rcp.prefs.VariablesPreferencePage.java

License:Open Source License

@Override
protected Control createContents(Composite parent) {
    createProfileDropDown(parent);/*from   www .ja v a 2s.com*/

    Composite main = new Composite(parent, SWT.NONE);
    main.setLayout(new GridLayout(2, false));

    Composite filterComposite = new Composite(main, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginWidth = layout.marginHeight = 0;
    filterComposite.setLayout(layout);
    filterComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    new Label(filterComposite, SWT.NONE).setText("Filter: ");
    filterText = new Text(filterComposite, SWT.BORDER);
    filterText.addModifyListener(new ModifyListener() {
        public void modifyText(ModifyEvent e) {
            variableTable.refresh();
        }
    });
    filterText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    new Label(main, SWT.NONE);

    variableTable = new TableViewer(main, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL);

    TableViewerColumn varName = new TableViewerColumn(variableTable, SWT.NONE);
    varName.getColumn().setWidth(200);
    varName.getColumn().setText("Variable Name");
    varName.setEditingSupport(new TextEditingSupport(variableTable) {
        protected Object getValue(Object element) {
            return ((Variable) element).getIdentifier();
        }

        protected void setValue(Object element, Object value) {
            ((Variable) element).setIdentifier(value.toString());
            variableTable.refresh(element);
        }
    });

    TableViewerColumn value = new TableViewerColumn(variableTable, SWT.NONE);
    value.getColumn().setWidth(150);
    value.getColumn().setText("Value");
    value.setEditingSupport(new TextEditingSupport(variableTable) {
        protected Object getValue(Object element) {
            return ((Variable) element).getValue();
        }

        protected void setValue(Object element, Object value) {
            ((Variable) element).setValue(value.toString());
            variableTable.refresh(element);
        }
    });
    variableTable.getTable().setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
    variableTable.getTable().setHeaderVisible(true);
    variableTable.setUseHashlookup(true);
    variableTable.setContentProvider(ArrayContentProvider.getInstance());
    variableTable.setLabelProvider(new VariableLabelProvider());
    variableTable.addFilter(new ViewerFilter() {
        public boolean select(Viewer viewer, Object parentElement, Object element) {
            Variable var = (Variable) element;

            if (filterText.getText().equals(""))
                return true;

            return (var.getIdentifier().toLowerCase().contains(filterText.getText().toLowerCase())
                    || var.getValue().toLowerCase().contains(filterText.getText().toLowerCase()));
        }
    });
    variableTable.setComparator(new ViewerComparator() {
        public int compare(Viewer viewer, Object e1, Object e2) {
            Variable v1 = (Variable) e1;
            Variable v2 = (Variable) e2;
            return v1.getIdentifier().compareTo(v2.getIdentifier());
        }
    });

    variableTable.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            if (variableTable.getSelection().isEmpty()) {
                currentVariable = null;
                removeButton.setEnabled(false);
            } else {
                currentVariable = (Variable) ((IStructuredSelection) variableTable.getSelection())
                        .getFirstElement();
                removeButton.setEnabled(true);
            }
        }
    });

    int listHeight = variableTable.getTable().getItemHeight() * 8;
    Rectangle trim = variableTable.getTable().computeTrim(0, 0, 0, listHeight);
    GridData data = new GridData(GridData.FILL, GridData.FILL, true, true);
    data.heightHint = trim.height;

    variableTable.getTable().setLayoutData(data);

    Composite buttonsComposite = new Composite(main, SWT.NONE);
    buttonsComposite.setLayout(new GridLayout(1, true));
    buttonsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));

    Button addButton = new Button(buttonsComposite, SWT.PUSH);
    addButton.setText("Add Variable");
    addButton.setImage(WarlockSharedImages.getImage(WarlockSharedImages.IMG_ADD));
    addButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            addVariableSelected();
        }
    });
    addButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    removeButton = new Button(buttonsComposite, SWT.PUSH);
    removeButton.setText("Remove Variable");
    removeButton.setImage(WarlockSharedImages.getImage(WarlockSharedImages.IMG_REMOVE));
    removeButton.setEnabled(false);
    removeButton.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent e) {
            removeVariableSelected();
        }
    });
    removeButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));

    /*for (IVariable var : settings.getAllVariables())
    {
       if (var instanceof Variable) {
    variables.add(new Variable((Variable)var));
       }
    }*/

    updateData();

    return main;
}

From source file:cc.warlock.rcp.stormfront.ui.prefs.PresetsPreferencePage.java

License:Open Source License

private Composite createPresetsTable(Composite main) {
    Group presetsGroup = new Group(main, SWT.NONE);
    presetsGroup.setLayout(new GridLayout(3, false));
    presetsGroup.setText("Presets");

    bgToggle = new Button(presetsGroup, SWT.CHECK);
    if (currentStyle != null)
        bgToggle.setSelection(!currentStyle.getForegroundColor().isDefault());
    bgToggle.addSelectionListener(new SelectionAdapter() {
        @Override/* w  w  w .  java2  s . c om*/
        public void widgetSelected(SelectionEvent e) {
            if (currentStyle != null) {
                currentStyle.setBackgroundColor(new WarlockColor());
            }
            updatePreview();
        }
    });
    bgSelector = colorSelectorWithLabel(presetsGroup, "Background color:");

    fgToggle = new Button(presetsGroup, SWT.CHECK);
    if (currentStyle != null)
        fgToggle.setSelection(!currentStyle.getForegroundColor().isDefault());
    fgToggle.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            if (currentStyle != null) {
                currentStyle.setForegroundColor(new WarlockColor());
            }
            updatePreview();
        }
    });
    fgSelector = colorSelectorWithLabel(presetsGroup, "Foreground color:");

    stylesTable = new TableViewer(presetsGroup, SWT.SINGLE | SWT.BORDER | SWT.NO_SCROLL);
    TableColumn column = new TableColumn(stylesTable.getTable(), SWT.NONE, 0);
    column.setWidth(200);

    stylesTable.setUseHashlookup(true);
    stylesTable.setColumnProperties(new String[] { "preset" });
    stylesTable.setContentProvider(ArrayContentProvider.getInstance());
    stylesTable.setLabelProvider(new PresetsLabelProvider());
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
    data.horizontalSpan = 3;
    stylesTable.getTable().setLayoutData(data);

    stylesTable.addSelectionChangedListener(new ISelectionChangedListener() {
        public void selectionChanged(SelectionChangedEvent event) {
            presetSelected((IStructuredSelection) stylesTable.getSelection());
        }
    });
    // TODO: select the first element

    return presetsGroup;
}

From source file:cc.warlock.rcp.views.ScriptManager.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    main = parent;//from  w w w .j av a  2  s. c  o m
    GridLayout layout = new GridLayout();
    layout.numColumns = 1;
    layout.horizontalSpacing = 0;
    layout.marginBottom = 0;
    layout.marginHeight = 0;
    layout.marginLeft = 0;
    layout.marginRight = 0;
    layout.marginTop = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;

    parent.setLayout(layout);

    scriptsTable = new TableViewer(parent, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.FILL);
    scriptsTable.getTable().setLayoutData(new GridData(GridData.FILL_BOTH));
    scriptsTable.setUseHashlookup(true);
    scriptsTable.setColumnProperties(new String[] { "name", "pause", "stop" });
    scriptsTable.getTable().setLinesVisible(true);
    //scriptsTable.getTable().setHeaderVisible(true);

    CellEditor editors[] = new CellEditor[] { new TextCellEditor(scriptsTable.getTable()),
            new CheckboxCellEditor(scriptsTable.getTable()), new CheckboxCellEditor(scriptsTable.getTable()) };
    scriptsTable.setCellEditors(editors);

    scriptsTable.setCellModifier(new ICellModifier() {
        public boolean canModify(Object element, String property) {
            return false;
        }

        public Object getValue(Object element, String property) {
            return ((ScriptRow) element).getName();
        }

        public void modify(Object element, String property, Object value) {
            return;
        }
    });

    nameColumn = new TableColumn(scriptsTable.getTable(), SWT.LEFT, 0);
    nameColumn.setText("Name");
    pauseColumn = new TableColumn(scriptsTable.getTable(), SWT.RIGHT, 1);
    pauseColumn.setWidth(30);
    pauseColumn.setText("Pause");
    stopColumn = new TableColumn(scriptsTable.getTable(), SWT.RIGHT, 2);
    stopColumn.setWidth(30);
    stopColumn.setText("Stop");
    scriptsTable.setLabelProvider(new ScriptsLabelProvider());
    scriptsTable.setContentProvider(ArrayContentProvider.getInstance());
    scriptsTable.setInput(new ScriptRow[] { new ScriptRow("sfhunter.cmd", false),
            new ScriptRow("train.cmd", true), new ScriptRow("do.wiz", false), new ScriptRow("go.wsl", true) });

    main.addControlListener(new ControlAdapter() {
        public void controlResized(ControlEvent e) {
            Rectangle area = main.getClientArea();
            Table table = scriptsTable.getTable();
            Point size = table.computeSize(SWT.DEFAULT, SWT.DEFAULT);
            ScrollBar vBar = table.getVerticalBar();
            int width = area.width - table.computeTrim(0, 0, 0, 0).width - vBar.getSize().x;
            if (size.y > area.height + table.getHeaderHeight()) {
                // Subtract the scrollbar width from the total column width
                // if a vertical scrollbar will be required
                Point vBarSize = vBar.getSize();
                width -= vBarSize.x;
            }
            Point oldSize = table.getSize();
            if (oldSize.x > area.width) {
                // table is getting smaller so make the columns 
                // smaller first and then resize the table to
                // match the client area width
                nameColumn.setWidth(width - 60);
                stopColumn.setWidth(30);
                pauseColumn.setWidth(30);
                table.setSize(area.width, area.height);
            } else {
                // table is getting bigger so make the table 
                // bigger first and then make the columns wider
                // to match the client area width
                table.setSize(area.width, area.height);
                nameColumn.setWidth(width - 60);
                stopColumn.setWidth(30);
                pauseColumn.setWidth(30);
            }
        }
    });
}

From source file:cc.warlock.scribe.ui.views.ScriptsView.java

License:Open Source License

@Override
public void createPartControl(Composite parent) {
    scriptList = new TableViewer(parent, SWT.SINGLE | SWT.FULL_SELECTION);
    scriptList.setContentProvider(ArrayContentProvider.getInstance());
    scriptList.setLabelProvider(new ITableLabelProvider() {
        public Image getColumnImage(Object element, int columnIndex) {
            if (columnIndex == 0)
                return ScribeSharedImages.getImage(ScribeSharedImages.IMG_SCRIPT);

            return null;
        }/*from ww w .j av a  2s  . co  m*/

        public String getColumnText(Object element, int columnIndex) {
            if (columnIndex == 1) {
                return ((IScriptInfo) element).getScriptName();
            }
            return "";
        }

        public void addListener(ILabelProviderListener listener) {
        }

        public void dispose() {
        }

        public boolean isLabelProperty(Object element, String property) {
            return true;
        }

        public void removeListener(ILabelProviderListener listener) {
        }
    });

    scriptList.setSorter(new ViewerSorter() {
        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            return ((IScriptInfo) e1).getScriptName().compareTo(((IScriptInfo) e2).getScriptName());
        }
    });

    scriptList.addDoubleClickListener(new IDoubleClickListener() {
        public void doubleClick(DoubleClickEvent event) {
            openScript((IStructuredSelection) scriptList.getSelection());
        }
    });

    TableColumn image = new TableColumn(scriptList.getTable(), SWT.NONE, 0);
    image.setWidth(16);

    TableColumn name = new TableColumn(scriptList.getTable(), SWT.NONE, 1);
    name.setWidth(200);

    //      for (IWarlockClient client : WarlockClientRegistry.getActiveClients())
    //      {
    //         if (client instanceof IStormFrontClient)
    //         {
    //            serverSettingsLoaded(((IStormFrontClient)client).getServerSettings());
    //         }
    //      }
    //      WarlockClientRegistry.addWarlockClientListener(new WarlockClientAdapter() {
    //         public void clientConnected(IWarlockClient client) {
    //            addListener(client);
    //         }
    //      });
}

From source file:cc.xuloo.rcputils.tables.TableViewerBuilder.java

License:Open Source License

/**
 * Creates a new TableViewerBuilder./*w ww  .j ava  2 s .com*/
 * 
 * This instantly creates a Table widget and a TableViewer. The given parent
 * Composite needs to be empty, because `TableColumnLayout` is used
 * internally.
 */
public TableViewerBuilder(Composite parent, int style) {
    // check parent
    if (parent.getChildren().length > 0) {
        throw new RuntimeException(
                "The parent composite for the table needs to be empty for TableColumnLayout.");
    }

    this.tableViewer = new TableViewer(parent, style);
    this.table = tableViewer.getTable();

    // set TableColumnLayout to table parent
    this.table.getParent().setLayout(new TableColumnLayout());

    // headers / lines visible by default
    this.table.setHeaderVisible(true);
    this.table.setLinesVisible(true);

    // sorting
    this.sortSelectionListener = new ColumnSortSelectionListener(this.tableViewer);
    tableViewer.setComparator(new SortColumnComparator());
}

From source file:ch.acanda.eclipse.pmd.wizard.AddRuleSetConfigurationWizardPage.java

License:Open Source License

@Override
public void createControl(final Composite parent) {
    final Composite container = new Composite(parent, SWT.NULL);
    setControl(container);/* www . j  a v a 2  s  . c o m*/
    container.setLayout(new GridLayout(3, false));

    final Label lblLocation = new Label(container, SWT.NONE);
    lblLocation.setText("Location:");

    location = new Text(container, SWT.BORDER);
    location.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    SWTBotID.set(location, SWTBotID.LOCATION);

    browse = new Button(container, SWT.NONE);
    browse.setText("Browse...");
    SWTBotID.set(browse, SWTBotID.BROWSE);
    browse.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(final SelectionEvent e) {
            controller.browse(((Control) e.widget).getShell());
        }
    });

    final Label lblName = new Label(container, SWT.NONE);
    lblName.setText("Name:");

    name = new Text(container, SWT.BORDER);
    name.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    SWTBotID.set(name, SWTBotID.NAME);

    // This button is only here to make this row the same height as the previous row.
    // Without this button the distance between the text of this row and the text of
    // the previous row is much larger than the distance between the text of this row
    // and the table of the next row.
    final Button button = new Button(container, SWT.NONE);
    button.setEnabled(false);
    button.setVisible(false);

    final Label lblRules = new Label(container, SWT.NONE);
    final GridData lblRulesGridData = new GridData(SWT.LEFT, SWT.TOP, false, false);
    lblRulesGridData.verticalIndent = 3;
    lblRules.setLayoutData(lblRulesGridData);
    lblRules.setText("Rules:");

    final Composite tableComposite = new Composite(container, SWT.NONE);
    tableComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    final TableColumnLayout tableCompositeTableColumnLayout = new TableColumnLayout();
    tableComposite.setLayout(tableCompositeTableColumnLayout);

    tableViewer = new TableViewer(tableComposite, SWT.BORDER | SWT.FULL_SELECTION | SWT.HIDE_SELECTION);
    final Table table = tableViewer.getTable();
    table.setLinesVisible(true);
    SWTBotID.set(table, SWTBotID.RULES);

    final TableViewerColumn tableViewerColumn = new TableViewerColumn(tableViewer, SWT.NONE);
    final TableColumn tblclmnName = tableViewerColumn.getColumn();
    tableCompositeTableColumnLayout.setColumnData(tblclmnName, new ColumnWeightData(1, 200, false));
    tblclmnName.setText("Name");
    new Label(container, SWT.NONE);
    new Label(container, SWT.NONE);
    new Label(container, SWT.NONE);
    new Label(container, SWT.NONE);

    initDataBindings();
}

From source file:ch.allon.redskin.internal.ui.custom.PriceCategoryDialog.java

License:Open Source License

@Override
protected Control createDialogArea(Composite parent) {
    Composite container = (Composite) super.createDialogArea(parent);

    viewer = new TableViewer(container,
            SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    PricesTableProvider provider = new PricesTableProvider();
    viewer.setContentProvider(provider);
    viewer.setLabelProvider(provider);//from w w  w  .  j  a v a 2s.  com
    viewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    viewer.setColumnProperties(new String[] { Messages.NewPriceCategoryAction_Column_Day,
            Messages.NewPriceCategoryAction_Column_Price });

    Table table = viewer.getTable();
    TableLayout layout = new TableLayout();
    table.setLayout(layout);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);

    TableColumn c = new TableColumn(table, SWT.NONE);
    layout.addColumnData(new ColumnWeightData(3, 100, true));
    c.setText(Messages.NewPriceCategoryAction_Column_Day);
    c.setResizable(true);

    c = new TableColumn(table, SWT.NONE);
    layout.addColumnData(new ColumnWeightData(3, 100, true));
    c.setText(Messages.NewPriceCategoryAction_Column_Price);
    c.setResizable(true);

    // Column 4 : Percent complete (Text with digits only)
    TextCellEditor textEditor = new TextCellEditor(table);
    ((Text) textEditor.getControl()).addVerifyListener(

            new VerifyListener() {
                public void verifyText(VerifyEvent e) {
                    e.doit = "0123456789.".indexOf(e.text) >= 0; //$NON-NLS-1$
                }
            });
    viewer.setCellEditors(new CellEditor[] { new TextCellEditor(table), textEditor });
    viewer.setCellModifier(new ICellModifier() {

        @Override
        public void modify(Object element, String property, Object value) {
            final IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
            final Row row = (Row) selection.getFirstElement();
            if (row == null || value == null || value.toString().length() == 0)
                return;
            row.price = Double.parseDouble((String) value);
            viewer.refresh(row);
        }

        @Override
        public Object getValue(Object element, String property) {
            if (property.equals(Messages.NewPriceCategoryAction_Column_Day))
                return "" + ((Row) element).pos; //$NON-NLS-1$
            else if (property.equals(Messages.NewPriceCategoryAction_Column_Price))
                return "" + ((Row) element).price; //$NON-NLS-1$
            return null;
        }

        @Override
        public boolean canModify(Object element, String property) {
            return property.equals(Messages.NewPriceCategoryAction_Column_Price);
        }
    });

    viewer.setInput(getNewObject());

    return container;
}

From source file:ch.elexis.agenda.views.AgendaGross.java

License:Open Source License

@Override
public void create(Composite parent) {
    parent.setLayout(new GridLayout());

    cButtons = new Composite(parent, SWT.BORDER);
    RowLayout rl = new RowLayout();
    cButtons.setLayout(rl);/*  w w w.ja  v  a  2 s .  c  o  m*/
    cButtons.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));

    sash = new SashForm(parent, SWT.HORIZONTAL);
    sash.setLayout(new GridLayout());
    sash.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));

    String[] bereiche = CoreHub.globalCfg.get(PreferenceConstants.AG_BEREICHE, Messages.TagesView_14)
            .split(","); //$NON-NLS-1$
    ChangeBereichAdapter chb = new ChangeBereichAdapter();
    bChange = new Button[bereiche.length];
    for (int i = 0; i < bereiche.length; i++) {
        bChange[i] = new Button(cButtons, SWT.RADIO);
        bChange[i].setText(bereiche[i]);
        bChange[i].addSelectionListener(chb);
        if (bereiche[i].equals(agenda.getActResource())) {
            bChange[i].setSelection(true);
        }
    }

    Composite ret = new Composite(sash, SWT.NONE);
    Composite right = new Composite(sash, SWT.BORDER);

    ret.setLayout(new GridLayout());
    right.setLayout(new GridLayout());
    right.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));

    tv = new TableViewer(ret, SWT.FULL_SELECTION | SWT.SINGLE);
    tv.getControl().setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));

    calendar = new DateTime(right, SWT.CALENDAR);
    calendar.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
    calendar.setDate(agenda.getActDate().get(TimeTool.YEAR), agenda.getActDate().get(TimeTool.MONTH),
            agenda.getActDate().get(TimeTool.DAY_OF_MONTH));
    Button bToday = new Button(right, SWT.PUSH);
    bToday.setText(Messages.AgendaGross_today);
    bToday.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
    bToday.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent arg0) {
            TimeTool dat = new TimeTool();
            agenda.setActDate(dat);
            calendar.setDate(dat.get(TimeTool.YEAR), dat.get(TimeTool.MONTH), dat.get(TimeTool.DAY_OF_MONTH));
            updateDate();
        }

    });
    dayMessage = SWTHelper.createText(right, 4, SWT.V_SCROLL);

    // set text field's maximum width to the width of the calendar
    GridData gd = (GridData) dayMessage.getLayoutData();
    gd.widthHint = calendar.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;

    dayMessage.addFocusListener(new FocusAdapter() {

        @Override
        public void focusLost(FocusEvent arg0) {
            String tx = dayMessage.getText();
            TagesNachricht tn = TagesNachricht.load(agenda.getActDate());
            if (tn.exists()) {
                tn.setLangtext(tx);
            } else {
                tn = new TagesNachricht(agenda.getActDate(), " - ", tx); //$NON-NLS-1$
            }
        }

    });
    terminDetail = SWTHelper.createText(right, 5, SWT.NONE);
    terminDetail.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    lbDetails = new Label(right, SWT.WRAP);
    lbDetails.setText("-"); //$NON-NLS-1$
    lbDetails.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
    lbDayString = new Label(ret, SWT.NONE);

    tv.setLabelProvider(new AgendaLabelProvider());
    Table table = tv.getTable();
    int[] columnWidths = loadColumnWidths();
    for (int i = 0; i < columnTitles.length; i++) {
        TableColumn tc = new TableColumn(table, SWT.NONE);
        tc.setText(columnTitles[i]);
        tc.setWidth(columnWidths[i]);
    }
    table.setHeaderVisible(true);
    makePrivateActions();
    calendar.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent arg0) {
            LocalDate localDate = LocalDate.of(calendar.getYear(), calendar.getMonth() + 1, calendar.getDay());
            agenda.setActDate(new TimeTool(localDate));
            updateDate();
        }

    });

    sash.setWeights(sashWeights == null ? new int[] { 70, 30 } : sashWeights);

    // set initial widget values
    initialize();
}

From source file:ch.elexis.agenda.views.TagesView.java

License:Open Source License

@Override
public void create(Composite parent) {
    parent.setLayout(new GridLayout());
    Composite top = new Composite(parent, SWT.NONE);
    top.setLayout(new GridLayout(5, false));
    top.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
    bToday = new Button(top, SWT.CENTER | SWT.PUSH | SWT.FLAT);
    bToday.setImage(UiDesk.getImage(Activator.IMG_HOME));
    bToday.setToolTipText(Messages.TagesView_showToday);
    bToday.addSelectionListener(new SelectionAdapter() {

        @Override//w w  w  .  j  a v  a 2  s .  c om
        public void widgetSelected(SelectionEvent e) {
            TimeTool dat = new TimeTool();
            agenda.setActDate(dat);
            updateDate();
        }

    });

    Button bMinus = new Button(top, SWT.PUSH);
    bMinus.setToolTipText(Messages.TagesView_previousDay);
    bMinus.setText("<"); //$NON-NLS-1$
    bMinus.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            // TimeTool dat=Activator.getDefault().theDay;
            agenda.addDays(-1);
            updateDate();
        }
    });

    bDay = new Button(top, SWT.CENTER | SWT.PUSH | SWT.FLAT);
    bDay.setToolTipText(Messages.TagesView_selectDay);
    bDay.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
    bDay.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            DateSelectorDialog dsl = new DateSelectorDialog(bDay.getShell(), agenda.getActDate());
            // Point pt=bDay.getLocation();
            // dsl.getShell().setLocation(pt.x, pt.y);
            dsl.create();
            Point m = UiDesk.getDisplay().getCursorLocation();
            dsl.getShell().setLocation(m.x, m.y);
            if (dsl.open() == Dialog.OK) {
                TimeTool dat = dsl.getSelectedDate();
                agenda.setActDate(dat);
                updateDate();
            }
        }

    });
    bDay.setText(agenda.getActDate().toString(TimeTool.DATE_GER));

    Button bPlus = new Button(top, SWT.PUSH);
    bPlus.setToolTipText(Messages.TagesView_nextDay);

    bPlus.setText(">"); //$NON-NLS-1$
    bPlus.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            agenda.addDays(1);
            updateDate();
        }
    });

    Button bPrint = new Button(top, SWT.CENTER | SWT.PUSH | SWT.FLAT);
    bPrint.setImage(Images.IMG_PRINTER.getImage());
    bPrint.setToolTipText(Messages.TagesView_printDay);
    bPrint.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent e) {
            printAction.run();
        }
    });

    SashForm sash = new SashForm(parent, SWT.VERTICAL);
    sash.setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    tv = new TableViewer(sash, SWT.NONE);
    tv.getControl().setLayoutData(SWTHelper.getFillGridData(1, true, 1, true));
    tv.setLabelProvider(new AgendaLabelProvider());

    tDetail = new Text(sash, SWT.MULTI | SWT.BORDER | SWT.WRAP);
    lCreator = new Label(parent, SWT.NONE);
    lCreator.setFont(UiDesk.getFont(Preferences.USR_SMALLFONT));
    lCreator.setLayoutData(SWTHelper.getFillGridData(1, true, 1, false));
    lCreator.setText(" - "); //$NON-NLS-1$

    sash.setWeights(new int[] { 80, 20 });
    makePrivateActions();
}