Search in sources :

Example 11 with ArrayContentProvider

use of org.eclipse.jface.viewers.ArrayContentProvider in project translationstudio8 by heartsome.

the class XmlConverterConfigurationDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite tparent = (Composite) super.createDialogArea(parent);
    GridDataFactory.fillDefaults().grab(true, true).hint(400, 450).minSize(400, 450).applyTo(tparent);
    tableViewer = new TableViewer(tparent, SWT.FULL_SELECTION | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER);
    table = tableViewer.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(table);
    tableViewer.setLabelProvider(new TableViewerLabelProvider());
    tableViewer.setContentProvider(new ArrayContentProvider());
    String[] columnNames = new String[] { Messages.getString("dialogs.XmlConverterConfigurationDialog.columnNames1"), Messages.getString("dialogs.XmlConverterConfigurationDialog.columnNames2") };
    int[] columnAlignments = new int[] { SWT.LEFT, SWT.LEFT };
    for (int i = 0; i < columnNames.length; i++) {
        TableColumn tableColumn = new TableColumn(table, columnAlignments[i]);
        tableColumn.setText(columnNames[i]);
        tableColumn.setWidth(50);
        // 处理排序的问题
        switch(i) {
            case 0:
                tableColumn.addSelectionListener(new SelectionAdapter() {

                    // 升序
                    boolean asc = true;

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        tableViewer.setSorter(asc ? XmlConvertOrder.index_ASC : XmlConvertOrder.index_DESC);
                        asc = !asc;
                    }
                });
                break;
            case 1:
                tableColumn.addSelectionListener(new SelectionAdapter() {

                    // 升序
                    boolean asc = true;

                    @Override
                    public void widgetSelected(SelectionEvent e) {
                        tableViewer.setSorter(asc ? XmlConvertOrder.xmlName_ASC : XmlConvertOrder.xmlName_DESC);
                        asc = !asc;
                    }
                });
                break;
            default:
                break;
        }
    }
    tableViewer.setInput(getXmlConfigFilesInfo());
    // 让列表列宽动态变化
    table.addListener(SWT.Resize, new Listener() {

        public void handleEvent(Event event) {
            final Table table = ((Table) event.widget);
            final TableColumn[] columns = table.getColumns();
            event.widget.getDisplay().syncExec(new Runnable() {

                public void run() {
                    double[] columnWidths = new double[] { 0.1, 0.85 };
                    for (int i = 0; i < columns.length; i++) columns[i].setWidth((int) (table.getBounds().width * columnWidths[i]));
                }
            });
        }
    });
    tableViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            editConfigXml();
        }
    });
    return tparent;
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) Listener(org.eclipse.swt.widgets.Listener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) TableViewerLabelProvider(net.heartsome.cat.ts.ui.advanced.TableViewerLabelProvider) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) DisposeEvent(org.eclipse.swt.events.DisposeEvent) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 12 with ArrayContentProvider

use of org.eclipse.jface.viewers.ArrayContentProvider in project translationstudio8 by heartsome.

the class SrxLanguageRulesManageDialog method createTable.

private void createTable(Composite tparent) {
    tableViewer = new TableViewer(tparent, SWT.FULL_SELECTION | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI);
    table = tableViewer.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    GridDataFactory.fillDefaults().span(4, SWT.DEFAULT).grab(true, true).applyTo(table);
    tableViewer.setLabelProvider(new TViewerLabelProvider());
    tableViewer.setContentProvider(new ArrayContentProvider());
    String[] columnNames = new String[] { Messages.getString("srx.SrxLanguageRulesManageDialog.columnNames1"), Messages.getString("srx.SrxLanguageRulesManageDialog.columnNames2"), Messages.getString("srx.SrxLanguageRulesManageDialog.columnNames3") };
    int[] columnAlignments = new int[] { SWT.LEFT, SWT.LEFT, SWT.LEFT };
    for (int i = 0; i < columnNames.length; i++) {
        TableColumn tableColumn = new TableColumn(table, columnAlignments[i]);
        tableColumn.setText(columnNames[i]);
        tableColumn.setWidth(50);
    }
    // 让列表列宽动态变化
    table.addListener(SWT.Resize, new Listener() {

        public void handleEvent(Event event) {
            final Table table = ((Table) event.widget);
            final TableColumn[] columns = table.getColumns();
            event.widget.getDisplay().syncExec(new Runnable() {

                public void run() {
                    double[] columnWidths = new double[] { 0.2, 0.37, 0.37 };
                    for (int i = 0; i < columns.length; i++) columns[i].setWidth((int) (table.getBounds().width * columnWidths[i]));
                }
            });
        }
    });
    tableViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            editLangRule();
        }
    });
}
Also used : Listener(org.eclipse.swt.widgets.Listener) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) Table(org.eclipse.swt.widgets.Table) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 13 with ArrayContentProvider

use of org.eclipse.jface.viewers.ArrayContentProvider in project translationstudio8 by heartsome.

the class ExportExternalDialog method createDialogArea.

protected Control createDialogArea(Composite parent) {
    Composite tparent = (Composite) super.createDialogArea(parent);
    GridDataFactory.createFrom(new GridData(GridData.FILL_BOTH)).hint(600, SWT.DEFAULT).applyTo(tparent);
    final Group groupFile = new Group(tparent, SWT.NONE);
    groupFile.setText(Messages.getString("ExportDocxDialog.lable.xliff"));
    groupFile.setLayout(new GridLayout(1, false));
    groupFile.setLayoutData(new GridData(GridData.FILL_BOTH));
    final TableViewer tbv = new TableViewer(groupFile, SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
    final Table table = tbv.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    TableLayout tableLayout = new TableLayout();
    table.setLayout(tableLayout);
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).hint(SWT.DEFAULT, 90).applyTo(table);
    tableLayout.addColumnData(new ColumnWeightData(1));
    new TableColumn(table, SWT.NONE).setText(Messages.getString("ExportDocxDialog.lable.nodot"));
    tableLayout.addColumnData(new ColumnWeightData(10));
    new TableColumn(table, SWT.NONE).setText(Messages.getString("ExportDocxDialog.lable.fullPath"));
    tableLayout.addColumnData(new ColumnWeightData(2));
    new TableColumn(table, SWT.NONE).setText(Messages.getString("ExportDocxDialog.lable.srcLang"));
    tableLayout.addColumnData(new ColumnWeightData(2));
    new TableColumn(table, SWT.NONE).setText(Messages.getString("ExportDocxDialog.lable.tgtLang"));
    tbv.setLabelProvider(new TableViewLabelProvider());
    tbv.setContentProvider(new ArrayContentProvider());
    tbv.setInput(xlfBeans);
    final Group groupExportType = new Group(tparent, SWT.NONE);
    groupExportType.setText(Messages.getString("ExportDocxDialog.lable.exporttype"));
    groupExportType.setLayout(new GridLayout(3, false));
    groupExportType.setLayoutData(new GridData(GridData.FILL_BOTH));
    final Label lblExportType = new Label(groupExportType, SWT.NONE);
    lblExportType.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblExportType.setText(Messages.getString("ExportDocxDialog.lable.exportchoose"));
    cmb = new Combo(groupExportType, SWT.NONE | SWT.READ_ONLY);
    GridDataFactory.swtDefaults().span(2, 1).grab(true, false).align(SWT.FILL, SWT.FILL).applyTo(cmb);
    for (String type : ExportExternal.getExportTypes()) {
        cmb.add(type);
    }
    cmb.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            final int exportCode = ExportExternal.getExportTypeCode(cmb.getSelectionIndex());
            btnHsproofNote.setEnabled(exportCode == ExportExternal.EXPORT_HSPROOF);
            btnHsproofState.setEnabled(btnHsproofNote.getEnabled());
            btnNotrans.setEnabled(exportCode != ExportExternal.EXPORT_TMX && btnFilterWhenState.getSelection());
            if (ExportExternal.EXPORT_TMX == exportCode && btnFilterWhenState.getSelection()) {
                btnNotrans.setSelection(false);
            }
        }
    });
    final Label lblR8State = new Label(groupExportType, SWT.NONE);
    lblR8State.setText(Messages.getString("ExportDocxDialog.lable.hsproof"));
    btnHsproofState = new Button(groupExportType, SWT.CHECK);
    btnHsproofState.setText(Messages.getString("ExportDocxDialog.statusBtn"));
    btnHsproofNote = new Button(groupExportType, SWT.CHECK);
    btnHsproofNote.setText(Messages.getString("ExportDocxDialog.commentBtn"));
    final Group groupFilter = new Group(tparent, SWT.NONE);
    groupFilter.setText(Messages.getString("ExportDocxDialog.lable.filter"));
    groupFilter.setLayout(new GridLayout(3, false));
    groupFilter.setLayoutData(new GridData(GridData.FILL_BOTH));
    // 过滤大类
    btnAllTrans = new Button(groupFilter, SWT.RADIO);
    btnAllTrans.setText(Messages.getString("ExportDocxDialog.lable.filterAll"));
    btnAllTrans.setSelection(true);
    btnAllTrans.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (btnAllTrans.getSelection()) {
                setFilterDefaultValue();
            }
        }
    });
    btnOnlySpecial = new Button(groupFilter, SWT.RADIO);
    btnOnlySpecial.setText(Messages.getString("ExportDocxDialog.onlyExportBtn"));
    btnOnlySpecial.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (btnOnlySpecial.getSelection()) {
                setFilterDefaultValue();
            }
        }

        ;
    });
    btnFilterWhenState = new Button(groupFilter, SWT.RADIO);
    btnFilterWhenState.setText(Messages.getString("ExportDocxDialog.lable.hasState"));
    btnFilterWhenState.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            if (btnFilterWhenState.getSelection()) {
                setFilterDefaultValue();
            }
        }

        ;
    });
    // 大类细节
    cmpFilterAllTrans = new Composite(groupFilter, SWT.NONE);
    cmpFilterAllTrans.setLayout(new GridLayout(1, false));
    cmpFilterAllTrans.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    btnExceptLocked = new Button(cmpFilterAllTrans, SWT.CHECK);
    btnExceptLocked.setText(Messages.getString("ExportDocxDialog.lable.exceptLock"));
    btnExceptLocked.setEnabled(true);
    btnExceptContextMatch = new Button(cmpFilterAllTrans, SWT.CHECK);
    btnExceptContextMatch.setText(Messages.getString("ExportDocxDialog.lable.exceptCxtMatch"));
    btnExceptContextMatch.setEnabled(true);
    btnExceptFullMatch = new Button(cmpFilterAllTrans, SWT.CHECK);
    btnExceptFullMatch.setText(Messages.getString("ExportDocxDialog.lable.exceptFullMatch"));
    cmpFilterOnlySpecial = new Composite(groupFilter, SWT.NONE);
    cmpFilterOnlySpecial.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    cmpFilterOnlySpecial.setLayout(new GridLayout(1, false));
    btnHasNote = new Button(cmpFilterOnlySpecial, SWT.CHECK);
    btnHasNote.setText(Messages.getString("ExportDocxDialog.onlyExportNoteBtn"));
    btnNeedReview = new Button(cmpFilterOnlySpecial, SWT.CHECK);
    btnNeedReview.setText(Messages.getString("ExportDocxDialog.onlyExportReviewBtn"));
    cmpFilterWhenState = new Composite(groupFilter, SWT.NONE);
    cmpFilterWhenState.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    cmpFilterWhenState.setLayout(new GridLayout(1, false));
    btnNotrans = new Button(cmpFilterWhenState, SWT.CHECK);
    btnNotrans.setText(Messages.getString("ExportDocxDialog.lable.state.noTrans"));
    btnNotrans.setText(Messages.getString("ExportDocxDialog.lable.state.noTrans"));
    btnNewtrans = new Button(cmpFilterWhenState, SWT.CHECK);
    btnNewtrans.setText(Messages.getString("ExportDocxDialog.lable.state.new"));
    btnNewtrans.setText(Messages.getString("ExportDocxDialog.lable.state.new"));
    btnTransed = new Button(cmpFilterWhenState, SWT.CHECK);
    btnTransed.setText(Messages.getString("ExportDocxDialog.lable.state.hasTrans"));
    btnApproved = new Button(cmpFilterWhenState, SWT.CHECK);
    btnApproved.setText(Messages.getString("ExportDocxDialog.lable.state.hasApprove"));
    Composite cmpSaveas = new Composite(tparent, SWT.NONE);
    cmpSaveas.setLayout(GridLayoutFactory.swtDefaults().numColumns(3).create());
    cmpSaveas.setLayoutData(new GridData(GridData.FILL_BOTH));
    Label lblSaveas = new Label(cmpSaveas, SWT.NONE);
    lblSaveas.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    lblSaveas.setText(Messages.getString("ExportDocxDialog.lable.saveas"));
    txtSaveas = new Text(cmpSaveas, SWT.BORDER | SWT.READ_ONLY);
    txtSaveas.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    txtSaveas.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            getButton(IDialogConstants.OK_ID).setEnabled(!txtSaveas.getText().isEmpty());
        }
    });
    Button btnSaveas = new Button(cmpSaveas, SWT.NONE);
    btnSaveas.setText(Messages.getString("ExportDocxDialog.browseDocxBtn"));
    btnSaveas.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            DirectoryDialog dialog = new DirectoryDialog(getShell());
            dialog.setFilterPath(dialogSetting.get("defaultPath"));
            String path = dialog.open();
            if (path != null) {
                txtSaveas.setText(path);
                dialogSetting.put("defaultPath", path);
            }
        }
    });
    setDefaultValue();
    return parent;
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Group(org.eclipse.swt.widgets.Group) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ModifyListener(org.eclipse.swt.events.ModifyListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) Text(org.eclipse.swt.widgets.Text) TableColumn(org.eclipse.swt.widgets.TableColumn) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) TableLayout(org.eclipse.jface.viewers.TableLayout) DirectoryDialog(org.eclipse.swt.widgets.DirectoryDialog)

Example 14 with ArrayContentProvider

use of org.eclipse.jface.viewers.ArrayContentProvider in project translationstudio8 by heartsome.

the class CSVSettingDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite tparent = (Composite) super.createDialogArea(parent);
    GridLayoutFactory.fillDefaults().numColumns(1).extendedMargins(5, 5, 5, 5).applyTo(tparent);
    int height = 160;
    if (isTBXConverter) {
        height = 230;
    }
    GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).hint(320, height).grab(true, true).applyTo(tparent);
    Composite cmpSelFile = new Composite(tparent, SWT.None);
    GridLayoutFactory.fillDefaults().numColumns(3).equalWidth(false).extendedMargins(0, 0, 0, 0).applyTo(cmpSelFile);
    GridDataFactory.fillDefaults().applyTo(cmpSelFile);
    new Label(cmpSelFile, SWT.None).setText(Messages.getString("dialog.CSVSettingDialog.lblFile"));
    txtCSV = new Text(cmpSelFile, SWT.BORDER);
    txtCSV.setEditable(false);
    txtCSV.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    btnBrowse = new Button(cmpSelFile, SWT.None);
    btnBrowse.setText(Messages.getString("dialog.CSVSettingDialog.btnBrowse"));
    btnBrowse.addSelectionListener(new SelectionListener() {

        public void widgetSelected(SelectionEvent arg0) {
            FileDialog dialog = new FileDialog(getShell(), SWT.OPEN);
            dialog.setText(Messages.getString("dialog.CSVSettingDialog.dialogTitle"));
            String[] extensions = { "*.csv", "*.txt", "*" };
            String[] filters = { Messages.getString("dialog.CSVSettingDialog.filters1"), Messages.getString("dialog.CSVSettingDialog.filters2"), Messages.getString("dialog.CSVSettingDialog.filters3") };
            dialog.setFilterExtensions(extensions);
            dialog.setFilterNames(filters);
            String fileSep = System.getProperty("file.separator");
            if (txtCSV.getText() != null && !txtCSV.getText().trim().equals("")) {
                dialog.setFilterPath(txtCSV.getText().substring(0, txtCSV.getText().lastIndexOf(fileSep)));
                dialog.setFileName(txtCSV.getText().substring(txtCSV.getText().lastIndexOf(fileSep) + 1));
            } else {
                dialog.setFilterPath(System.getProperty("user.home"));
            }
            String name = dialog.open();
            if (name != null) {
                txtCSV.setText(name);
            }
        }

        public void widgetDefaultSelected(SelectionEvent arg0) {
        }
    });
    Composite cmpContent = new Composite(tparent, SWT.NONE);
    cmpContent.setLayout(new GridLayout(2, false));
    cmpContent.setLayoutData(new GridData(GridData.FILL_BOTH));
    createLabel(cmpContent, Messages.getString("dialog.CSVSettingDialog.cmbColSeparator"));
    cmbColSeparator = new Combo(cmpContent, SWT.NONE);
    cmbColSeparator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    cmbColSeparator.setItems(arrColSeparator);
    cmbColSeparator.select(1);
    createLabel(cmpContent, Messages.getString("dialog.CSVSettingDialog.cmbTextDelimiter"));
    cmbTextDelimiter = new Combo(cmpContent, SWT.NONE);
    cmbTextDelimiter.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    cmbTextDelimiter.setItems(arrTextDelimiter);
    cmbTextDelimiter.setText("\"");
    cmbTextDelimiter.setTextLimit(1);
    createLabel(cmpContent, Messages.getString("dialog.CSVSettingDialog.cmbEncoding"));
    cmbEncoding = new Combo(cmpContent, SWT.READ_ONLY);
    cmbEncoding.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    String[] arrEncoding = LocaleService.getPageCodes();
    cmbEncoding.setItems(arrEncoding);
    cmbEncoding.select(indexOf(arrEncoding, "UTF-8"));
    if (isTBXConverter) {
        createLabel(cmpContent, Messages.getString("dialog.CSVSettingDialog.cmbLang"));
        cmbLang = new TableComboViewer(cmpContent, SWT.READ_ONLY | SWT.BORDER);
        TableCombo tableCombo = cmbLang.getTableCombo();
        tableCombo.setShowTableLines(false);
        tableCombo.setShowTableHeader(false);
        tableCombo.setDisplayColumnIndex(-1);
        tableCombo.setShowImageWithinSelection(true);
        tableCombo.setShowColorWithinSelection(false);
        tableCombo.setShowFontWithinSelection(false);
        tableCombo.setVisibleItemCount(20);
        cmbLang.getTableCombo().setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
        ArrayList<Language> languages = new ArrayList<Language>(LocaleService.getDefaultLanguage().values());
        Collections.sort(languages, new Comparator<Language>() {

            public int compare(Language o1, Language o2) {
                return o1.toString().compareTo(o2.toString());
            }
        });
        cmbLang.setContentProvider(new ArrayContentProvider());
        cmbLang.setLabelProvider(new LanguageLabelProvider());
        cmbLang.setInput(languages);
        cmbLang.getTableCombo().select(0);
        createLabel(cmpContent, Messages.getString("dialog.CSVSettingDialog.cmbXCSTemplate"));
        cmbXCSTemplate = new Combo(cmpContent, SWT.READ_ONLY);
        cmbXCSTemplate.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        if (xcsTemplates.length > 0) {
            cmbXCSTemplate.setItems(xcsTemplates);
            cmbXCSTemplate.select(0);
        }
    }
    return tparent;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) LanguageLabelProvider(net.heartsome.cat.ts.ui.composite.LanguageLabelProvider) Label(org.eclipse.swt.widgets.Label) ArrayList(java.util.ArrayList) Text(org.eclipse.swt.widgets.Text) TableCombo(org.eclipse.nebula.widgets.tablecombo.TableCombo) Combo(org.eclipse.swt.widgets.Combo) TableComboViewer(org.eclipse.nebula.jface.tablecomboviewer.TableComboViewer) GridLayout(org.eclipse.swt.layout.GridLayout) Language(net.heartsome.cat.common.locale.Language) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TableCombo(org.eclipse.nebula.widgets.tablecombo.TableCombo) FileDialog(org.eclipse.swt.widgets.FileDialog) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 15 with ArrayContentProvider

use of org.eclipse.jface.viewers.ArrayContentProvider in project translationstudio8 by heartsome.

the class JavaPropertiesViewerDialog method createTableViewer.

private void createTableViewer(Composite tparent) {
    tableViewer = new TableViewer(tparent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.MULTI | SWT.BORDER);
    table = tableViewer.getTable();
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(table);
    String[] columnNames = new String[] { Messages.getString("dialog.JavaPropertiesViewerDialog.columnNames1"), Messages.getString("dialog.JavaPropertiesViewerDialog.columnNames2") };
    int[] columnAlignments = new int[] { SWT.LEFT, SWT.LEFT };
    for (int i = 0; i < columnNames.length; i++) {
        TableColumn tableColumn = new TableColumn(table, columnAlignments[i]);
        tableColumn.setText(columnNames[i]);
        tableColumn.setWidth(50);
    }
    tableViewer.setLabelProvider(new TableViewerLabelProvider());
    tableViewer.setContentProvider(new ArrayContentProvider());
    // 让列表列宽动态变化
    table.addListener(SWT.Resize, new Listener() {

        public void handleEvent(Event event) {
            final Table table = ((Table) event.widget);
            final TableColumn[] columns = table.getColumns();
            event.widget.getDisplay().syncExec(new Runnable() {

                public void run() {
                    double[] columnWidths = new double[] { 0.48, 0.48 };
                    for (int i = 0; i < columns.length; i++) columns[i].setWidth((int) (table.getBounds().width * columnWidths[i]));
                }
            });
        }
    });
}
Also used : Listener(org.eclipse.swt.widgets.Listener) SelectionListener(org.eclipse.swt.events.SelectionListener) Table(org.eclipse.swt.widgets.Table) TableColumn(org.eclipse.swt.widgets.TableColumn) TableViewerLabelProvider(net.heartsome.cat.ts.ui.plugin.TableViewerLabelProvider) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)92 GridData (org.eclipse.swt.layout.GridData)67 Composite (org.eclipse.swt.widgets.Composite)59 TableViewer (org.eclipse.jface.viewers.TableViewer)56 SelectionEvent (org.eclipse.swt.events.SelectionEvent)45 Table (org.eclipse.swt.widgets.Table)43 GridLayout (org.eclipse.swt.layout.GridLayout)41 Button (org.eclipse.swt.widgets.Button)37 Label (org.eclipse.swt.widgets.Label)36 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)32 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)32 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)30 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)30 Group (org.eclipse.swt.widgets.Group)23 ComboViewer (org.eclipse.jface.viewers.ComboViewer)21 TableColumn (org.eclipse.swt.widgets.TableColumn)21 LabelProvider (org.eclipse.jface.viewers.LabelProvider)19 Combo (org.eclipse.swt.widgets.Combo)19 Text (org.eclipse.swt.widgets.Text)19 Point (org.eclipse.swt.graphics.Point)18