Search in sources :

Example 1 with ArrayContentProvider

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

the class ProjectSettingTBPage method createContents.

/**
	 * Create contents of the preference page.
	 * @param parent
	 */
@Override
public Control createContents(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);
    container.setLayout(new GridLayout(1, false));
    tableViewer = new TableViewer(container, SWT.BORDER | SWT.FULL_SELECTION | SWT.SINGLE);
    Table table = tableViewer.getTable();
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    tableViewer.setContentProvider(new ArrayContentProvider());
    createColumn(tableViewer);
    tableViewer.setInput(curDbList);
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            DatabaseModelBean dbModel = (DatabaseModelBean) selection.getFirstElement();
            if (null == dbModel) {
                return;
            }
            if (Constants.DBTYPE_SQLITE.equals(dbModel.getDbType())) {
                String path = dbModel.getItlDBLocation() + File.separator + dbModel.getDbName();
                File file = new File(path);
                if (!file.exists()) {
                    setMessage(Messages.getString("projectsetting.ProjectSettingTBPage.FileNotFoundMsg"));
                    return;
                } else {
                    setMessage(Messages.getString("projectsetting.ProjectSettingTBPage.title"));
                }
            }
            if (dbModel != null && !dbModel.isHasMatch()) {
                setMessage(Messages.getString("projectsetting.ProjectSettingTBPage.msg1"));
            }
        }
    });
    Composite composite = new Composite(container, SWT.NONE);
    composite.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    composite.setLayout(new GridLayout(5, false));
    new Label(composite, SWT.NONE);
    HSDropDownButton addBtn = new HSDropDownButton(composite, SWT.NONE);
    addBtn.setText(Messages.getString("projectsetting.ProjectSettingTBPage.addBtn"));
    Menu addMenu = addBtn.getMenu();
    MenuItem item = new MenuItem(addMenu, SWT.PUSH);
    item.setText(Messages.getString("tb.dialog.addTb.DropDownButton.AddFileTb"));
    item.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            FileDialog fileDialg = new FileDialog(getShell());
            fileDialg.setFilterExtensions(new String[] { "*.hstb", "*.*" });
            String result = fileDialg.open();
            if (result == null) {
                return;
            }
            File f = new File(result);
            if (!f.exists()) {
                return;
            }
            Map<DatabaseModelBean, String> r = null;
            try {
                r = Utils.convertFile2TbModel(f, false);
            } catch (Exception e1) {
                MessageDialog.openError(getShell(), Messages.getString("tb.dialog.addFileTb.errorTitle"), e1.getMessage());
            }
            if (r == null) {
                return;
            }
            Iterator<DatabaseModelBean> it = r.keySet().iterator();
            if (it.hasNext()) {
                DatabaseModelBean selectedVal = it.next();
                List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>();
                dbList.add(selectedVal);
                addToCurrDbList(dbList);
            }
        }
    });
    MenuItem serverItem = new MenuItem(addMenu, SWT.PUSH);
    serverItem.setText(Messages.getString("tb.dialog.addTb.DropDownButton.AddServerTb"));
    serverItem.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            TermDbManagerDialog dialog = new TermDbManagerDialog(getShell());
            dialog.setDialogUseFor(TermDbManagerDialog.TYPE_DBSELECTED);
            if (dialog.open() == Window.OK) {
                Iterator<DatabaseModelBean> it = dialog.getHasSelectedDatabase().keySet().iterator();
                List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>();
                while (it.hasNext()) {
                    dbList.add(it.next());
                }
                addToCurrDbList(dbList);
            }
        }
    });
    Button createBtn = new Button(composite, SWT.NONE);
    createBtn.setText(Messages.getString("projectsetting.ProjectSettingTBPage.createBtn"));
    createBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            NewTermDbWizard wizard = new NewTermDbWizard();
            TermDbManagerImportWizardDialog dlg = new TermDbManagerImportWizardDialog(getShell(), wizard);
            if (dlg.open() == 0) {
                DatabaseModelBean dbModel = wizard.getCreateDb();
                List<DatabaseModelBean> dbList = new ArrayList<DatabaseModelBean>();
                dbList.add(dbModel);
                addToCurrDbList(dbList);
            }
        }
    });
    Button removeBtn = new Button(composite, SWT.NONE);
    removeBtn.setText(Messages.getString("projectsetting.ProjectSettingTBPage.removeBtn"));
    removeBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            removeForCurrDbList((IStructuredSelection) tableViewer.getSelection());
        }
    });
    Button importTmxBtn = new Button(composite, SWT.NONE);
    importTmxBtn.setText(Messages.getString("projectsetting.ProjectSettingTBPage.importTmxBtn"));
    importTmxBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            IStructuredSelection selection = (IStructuredSelection) tableViewer.getSelection();
            Iterator<?> it = selection.iterator();
            if (it.hasNext()) {
                DatabaseModelBean dbModel = (DatabaseModelBean) it.next();
                TbxImportWizard wizard = new TbxImportWizard(dbModel);
                TermDbManagerImportWizardDialog dlg = new TermDbManagerImportWizardDialog(getShell(), wizard);
                if (dlg.open() == 0) {
                    checkDbHashMatch(dbModel);
                    tableViewer.refresh();
                }
                // 刷新项目
                ResourceUtils.refreshCurentSelectProject();
            } else {
                MessageDialog.openInformation(getShell(), Messages.getString("projectsetting.ProjectSettingTBPage.msgTitle"), Messages.getString("projectsetting.ProjectSettingTBPage.msg2"));
            }
        }
    });
    addBtn.setFocus();
    Point addPoint = addBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point createPoint = createBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point remPoint = removeBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    Point importPoint = importTmxBtn.computeSize(SWT.DEFAULT, SWT.DEFAULT, true);
    int width = Math.max(importPoint.x, Math.max(remPoint.x, Math.max(addPoint.x, createPoint.x)));
    GridData btnData = new GridData();
    btnData.widthHint = width + 10;
    addBtn.setLayoutData(btnData);
    createBtn.setLayoutData(btnData);
    removeBtn.setLayoutData(btnData);
    importTmxBtn.setLayoutData(btnData);
    return container;
}
Also used : DatabaseModelBean(net.heartsome.cat.common.bean.DatabaseModelBean) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TbxImportWizard(net.heartsome.cat.database.ui.tb.wizard.TbxImportWizard) TermDbManagerDialog(net.heartsome.cat.database.ui.tb.dialog.TermDbManagerDialog) GridLayout(org.eclipse.swt.layout.GridLayout) HSDropDownButton(net.heartsome.cat.common.ui.HSDropDownButton) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) Menu(org.eclipse.swt.widgets.Menu) HSDropDownButton(net.heartsome.cat.common.ui.HSDropDownButton) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) TermDbManagerImportWizardDialog(net.heartsome.cat.database.ui.tb.wizard.TermDbManagerImportWizardDialog) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) MenuItem(org.eclipse.swt.widgets.MenuItem) Point(org.eclipse.swt.graphics.Point) SQLException(java.sql.SQLException) Point(org.eclipse.swt.graphics.Point) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer) File(java.io.File) FileDialog(org.eclipse.swt.widgets.FileDialog) Map(java.util.Map) NewTermDbWizard(net.heartsome.cat.database.ui.tb.wizard.NewTermDbWizard)

Example 2 with ArrayContentProvider

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

the class ExportFilterComposite method createContent.

/** 创建控件 */
private void createContent() {
    setBackground(Display.getDefault().getSystemColor(SWT.COLOR_WHITE));
    GridLayout gridLayout = new GridLayout(5, false);
    gridLayout.horizontalSpacing = 2;
    gridLayout.marginWidth = 0;
    gridLayout.marginHeight = 0;
    setLayout(gridLayout);
    conditionComboViewer = new ComboViewer(this, SWT.NONE | SWT.READ_ONLY);
    Combo conditionCombo = conditionComboViewer.getCombo();
    GridData gdConditionCombo = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gdConditionCombo.widthHint = 200;
    conditionCombo.setLayoutData(gdConditionCombo);
    conditionComboViewer.setContentProvider(new ArrayContentProvider());
    conditionComboViewer.setInput(filterNames);
    conditionComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            if (sel.isEmpty()) {
                return;
            }
            baseDataBean.setOptionName((String) sel.getFirstElement());
            handlerFilterChangedEvent();
            opratorComboViewer.setInput(baseDataBean.getCurrentFilterExpressions());
            // 默认选中第一个
            opratorComboViewer.getCombo().select(0);
            baseDataBean.setCurrentExpression(opratorComboViewer.getCombo().getText());
        }
    });
    opratorComboViewer = new ComboViewer(this, SWT.NONE | SWT.READ_ONLY);
    Combo opratorCombo = opratorComboViewer.getCombo();
    GridData gd_opratorCombo = new GridData(SWT.FILL, SWT.CENTER, false, false, 1, 1);
    gd_opratorCombo.widthHint = 100;
    opratorCombo.setLayoutData(gd_opratorCombo);
    opratorComboViewer.setContentProvider(new ArrayContentProvider());
    opratorComboViewer.setInput(this.baseDataBean.getCurrentFilterExpressions());
    opratorComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            if (sel.isEmpty()) {
                return;
            }
            baseDataBean.setCurrentExpression((String) sel.getFirstElement());
        }
    });
    dynaComposite = new Composite(this, SWT.NONE);
    dynaComposite.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    GridLayout gldynaComposite = new GridLayout(1, false);
    gldynaComposite.marginWidth = 0;
    gldynaComposite.marginHeight = 0;
    dynaComposite.setLayout(gldynaComposite);
    valueText = new Text(dynaComposite, SWT.BORDER);
    valueText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));
    addButton = new Button(this, SWT.NONE);
    GridData gdAddButton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gdAddButton.widthHint = 25;
    addButton.setLayoutData(gdAddButton);
    addButton.setText("+");
    addButton.addListener(SWT.Selection, this);
    deleteButton = new Button(this, SWT.NONE);
    GridData gdDeletebutton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1);
    gdDeletebutton.widthHint = 25;
    deleteButton.setLayoutData(gdDeletebutton);
    deleteButton.setText("-");
    deleteButton.addListener(SWT.Selection, this);
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Combo(org.eclipse.swt.widgets.Combo) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Text(org.eclipse.swt.widgets.Text) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 3 with ArrayContentProvider

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

the class MergeXliffWizardPage method createMergeXlfGroup.

public void createMergeXlfGroup(Composite tparent) {
    final Group xliffDataGroup = new Group(tparent, SWT.NONE);
    GridLayoutFactory.fillDefaults().numColumns(2).margins(8, 8).applyTo(xliffDataGroup);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(xliffDataGroup);
    xliffDataGroup.setText(Messages.getString("wizard.MergeXliffWizardPage.xliffDataGroup"));
    tableViewer = new TableViewer(xliffDataGroup, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
    final Table table = tableViewer.getTable();
    GridData tableData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
    tableData.heightHint = 50;
    table.setLayoutData(tableData);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    String[] columnNames = new String[] { Messages.getString("wizard.MergeXliffWizardPage.columnNames1"), Messages.getString("wizard.MergeXliffWizardPage.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]);
    }
    tableViewer.setLabelProvider(new TableViewerLabelProvider());
    tableViewer.setContentProvider(new ArrayContentProvider());
    tableViewer.setInput(getSplitTableInfos());
    validXlf();
    // 让列表列宽动态变化
    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.15, 0.75 };
                    for (int i = 0; i < columns.length; i++) columns[i].setWidth((int) (table.getBounds().width * columnWidths[i]));
                }
            });
        }
    });
    Composite buttonComp = new Composite(xliffDataGroup, SWT.None);
    GridLayoutFactory.fillDefaults().numColumns(1).margins(8, 8).applyTo(buttonComp);
    GridDataFactory.fillDefaults().grab(false, true).hint(100, SWT.DEFAULT).applyTo(buttonComp);
    Button addbutton = new Button(buttonComp, SWT.NONE);
    addbutton.setText(Messages.getString("wizard.MergeXliffWizardPage.addbutton"));
    addbutton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    addbutton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            FileFolderSelectionDialog dialog = new FileFolderSelectionDialog(xliffDataGroup.getShell(), true, IResource.FILE);
            dialog.setMessage(Messages.getString("wizard.MergeXliffWizardPage.dialogMsg"));
            dialog.setTitle(Messages.getString("wizard.MergeXliffWizardPage.dialogTitle"));
            dialog.setDoubleClickSelects(true);
            try {
                dialog.setInput(EFS.getStore(root.getLocationURI()));
            } catch (CoreException e1) {
                LOGGER.error("", e1);
                e1.printStackTrace();
            }
            dialog.addFilter(new ViewerFilter() {

                @Override
                public boolean select(Viewer viewer, Object parentElement, Object element) {
                    if (element instanceof LocalFile) {
                        LocalFile folder = (LocalFile) element;
                        if (folder.getName().equalsIgnoreCase(".hsConfig") || folder.getName().equalsIgnoreCase(".metadata") || folder.getName().equalsIgnoreCase(".config") || folder.getName().equalsIgnoreCase(".nonTransElement")) {
                            return false;
                        }
                        if (projectPath.equals(folder.toString())) {
                            return true;
                        }
                        String xliffFolderPath = folder.toString();
                        String tempPath = projectPath + System.getProperty("file.separator") + ".TEMP";
                        String configPath = projectPath + System.getProperty("file.separator") + ".config";
                        String projectFilePath = projectPath + System.getProperty("file.separator") + ".project";
                        if (xliffFolderPath.startsWith(tempPath) || xliffFolderPath.startsWith(configPath) || xliffFolderPath.startsWith(projectFilePath)) {
                            return false;
                        } else if (xliffFolderPath.startsWith(projectPath)) {
                            return xliffFolderPath.substring(projectPath.length()).startsWith(System.getProperty("file.separator"));
                        }
                    }
                    return false;
                }
            });
            dialog.create();
            dialog.open();
            if (dialog.getResult() != null) {
                Object[] selectFiles = dialog.getResult();
                XLFValidator.resetFlag();
                for (int i = 0; i < selectFiles.length; i++) {
                    IFile iFile = root.getFileForLocation(Path.fromOSString(selectFiles[i].toString()));
                    if (XLFValidator.validateXliffFile(iFile)) {
                        // 如果该文件已经存在于列表中,就向添加到重复集合中
                        if (model.getMergeXliffFile().indexOf(iFile) >= 0) {
                            exsistFileList.add(iFile);
                        }
                        model.getMergeXliffFile().add(iFile);
                    }
                }
                XLFValidator.resetFlag();
                tableViewer.setInput(getSplitTableInfos());
                if (!validIsRepeate()) {
                    validXlf();
                }
            //					for (int i = 0; i < selectFiles.length; i++) {
            //						IFile file = root.getFileForLocation(Path.fromOSString(selectFiles[i].toString()));
            //						// 如果该文件已经存在于列表中,就向添加到重复集合中
            //						if (model.getMergeXliffFile().indexOf(file) >= 0) {
            //							exsistFileList.add(file);
            //						}
            //						model.getMergeXliffFile().add(file);
            //					}
            //					tableViewer.setInput(getSplitTableInfos());
            //					if (!validIsRepeate()) {
            //						validXlf();
            //					}
            }
        }
    });
    Button deleteButton = new Button(buttonComp, SWT.NONE);
    deleteButton.setText(Messages.getString("wizard.MergeXliffWizardPage.deleteButton"));
    deleteButton.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    deleteButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            ISelection selection = tableViewer.getSelection();
            Table table = tableViewer.getTable();
            if (selection != null && !selection.isEmpty()) {
                int[] indices = table.getSelectionIndices();
                for (int index : indices) {
                    String fileFullPath = table.getItem(index).getText(1);
                    for (int i = 0; i < model.getMergeXliffFile().size(); i++) {
                        if (model.getMergeXliffFile().get(i).getFullPath().toOSString().equals(fileFullPath)) {
                            model.getMergeXliffFile().remove(i);
                            break;
                        }
                    }
                    // 如果该文件存在于重复集合中,则从该集合中删除
                    for (int j = 0; j < exsistFileList.size(); j++) {
                        if (exsistFileList.get(j).getFullPath().toOSString().equals(fileFullPath)) {
                            exsistFileList.remove(j);
                            break;
                        }
                    }
                }
                tableViewer.setInput(getSplitTableInfos());
            }
            if (!validIsRepeate()) {
                validXlf();
            }
        }
    });
}
Also used : Group(org.eclipse.swt.widgets.Group) Listener(org.eclipse.swt.widgets.Listener) IFile(org.eclipse.core.resources.IFile) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ISelection(org.eclipse.jface.viewers.ISelection) FileFolderSelectionDialog(net.heartsome.cat.common.ui.dialog.FileFolderSelectionDialog) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) TableColumn(org.eclipse.swt.widgets.TableColumn) LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) CoreException(org.eclipse.core.runtime.CoreException) TableViewerLabelProvider(net.heartsome.cat.ts.handlexlf.split.TableViewerLabelProvider) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Event(org.eclipse.swt.widgets.Event) SelectionEvent(org.eclipse.swt.events.SelectionEvent) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 4 with ArrayContentProvider

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

the class LockRepeatedSegmentDialog method createFileDataGroup.

/**
	 * @param parent
	 */
public void createFileDataGroup(Composite parent) {
    Composite parentCmp = new Composite(parent, SWT.NONE);
    GridLayoutFactory.fillDefaults().extendedMargins(9, 9, 0, 0).numColumns(1).applyTo(parentCmp);
    GridDataFactory.fillDefaults().grab(true, true).applyTo(parentCmp);
    tableViewer = new TableViewer(parentCmp, SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
    final Table table = tableViewer.getTable();
    GridData tableData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
    tableData.heightHint = 50;
    table.setLayoutData(tableData);
    table.setLinesVisible(true);
    table.setHeaderVisible(true);
    String[] columnNames = new String[] { Messages.getString("dialog.LockRepeatedSegmentDialog.columnNames1"), Messages.getString("dialog.LockRepeatedSegmentDialog.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());
    tableViewer.setInput(getTableData());
    // 让列表列宽动态变化
    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.8 };
                    for (int i = 0; i < columns.length; i++) columns[i].setWidth((int) (table.getBounds().width * columnWidths[i]));
                }
            });
        }
    });
    tableViewer.getTable().setFocus();
    btnLockInnerRepeat = new Button(parentCmp, SWT.CHECK);
    btnLockInnerRepeat.setText(Messages.getString("dialog.LockRepeatedSegmentDialog.btnLockInnerRepeat"));
    btnLockInnerRepeat.setSelection(true);
    btnLockTM100 = new Button(parentCmp, SWT.CHECK);
    btnLockTM100.setText(Messages.getString("dialog.LockRepeatedSegmentDialog.btnLockTM100"));
    btnLockTM100.setSelection(true);
    if (CommonFunction.checkEdition("U")) {
        btnLockTM101 = new Button(parentCmp, SWT.CHECK);
        btnLockTM101.setText(Messages.getString("dialog.LockRepeatedSegmentDialog.btnLockTM101"));
        btnLockTM101.setSelection(true);
    }
}
Also used : Table(org.eclipse.swt.widgets.Table) Listener(org.eclipse.swt.widgets.Listener) Composite(org.eclipse.swt.widgets.Composite) TableColumn(org.eclipse.swt.widgets.TableColumn) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) Event(org.eclipse.swt.widgets.Event) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 5 with ArrayContentProvider

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

the class AddOrEditSrxConfigDialog method createMapGroup.

/**
	 * 创建映身
	 * @param tparent
	 *            ;
	 */
private void createMapGroup(Composite tparent, GridData groupData, GridLayout groupLayout) {
    Group group = new Group(tparent, SWT.BORDER);
    group.setLayoutData(groupData);
    group.setLayout(groupLayout);
    group.setText(Messages.getString("srx.AddOrEditSrxConfigDialog.group"));
    mapTableViewer = new TableViewer(group, SWT.FULL_SELECTION | SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI);
    mapTable = mapTableViewer.getTable();
    mapTable.setLinesVisible(true);
    mapTable.setHeaderVisible(true);
    GridDataFactory.fillDefaults().span(4, SWT.DEFAULT).grab(true, true).applyTo(mapTable);
    mapTableViewer.setLabelProvider(new TableViewerLabelProvider());
    mapTableViewer.setContentProvider(new ArrayContentProvider());
    String[] columnNames = new String[] { Messages.getString("srx.AddOrEditSrxConfigDialog.columnNames1"), Messages.getString("srx.AddOrEditSrxConfigDialog.columnNames2") };
    int[] columnAlignments = new int[] { SWT.LEFT, SWT.LEFT };
    for (int i = 0; i < columnNames.length; i++) {
        TableColumn tableColumn = new TableColumn(mapTable, columnAlignments[i]);
        tableColumn.setText(columnNames[i]);
        tableColumn.setWidth(50);
    }
    refreshTableWidth(mapTable);
    mapAddBtn = new Button(group, SWT.NONE);
    mapAddBtn.setText(Messages.getString("srx.AddOrEditSrxConfigDialog.mapAddBtn"));
    setButtonLayoutData(mapAddBtn);
    mapEditBtn = new Button(group, SWT.NONE);
    mapEditBtn.setText(Messages.getString("srx.AddOrEditSrxConfigDialog.mapEditBtn"));
    setButtonLayoutData(mapEditBtn);
    mapDeleteBtn = new Button(group, SWT.NONE);
    mapDeleteBtn.setText(Messages.getString("srx.AddOrEditSrxConfigDialog.mapDeleteBtn"));
    setButtonLayoutData(mapDeleteBtn);
    new Label(group, SWT.NONE);
    mapTableViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            editMapRules();
        }
    });
}
Also used : Group(org.eclipse.swt.widgets.Group) Label(org.eclipse.swt.widgets.Label) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) TableColumn(org.eclipse.swt.widgets.TableColumn) Button(org.eclipse.swt.widgets.Button) TableViewerLabelProvider(net.heartsome.cat.ts.ui.advanced.TableViewerLabelProvider) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)65 GridData (org.eclipse.swt.layout.GridData)51 TableViewer (org.eclipse.jface.viewers.TableViewer)44 Composite (org.eclipse.swt.widgets.Composite)44 SelectionEvent (org.eclipse.swt.events.SelectionEvent)39 Table (org.eclipse.swt.widgets.Table)38 GridLayout (org.eclipse.swt.layout.GridLayout)35 Button (org.eclipse.swt.widgets.Button)29 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)27 Label (org.eclipse.swt.widgets.Label)26 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)24 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)22 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)22 TableColumn (org.eclipse.swt.widgets.TableColumn)20 Group (org.eclipse.swt.widgets.Group)19 Event (org.eclipse.swt.widgets.Event)16 Listener (org.eclipse.swt.widgets.Listener)16 ArrayList (java.util.ArrayList)14 Point (org.eclipse.swt.graphics.Point)13 Text (org.eclipse.swt.widgets.Text)13