Search in sources :

Example 1 with TableViewerLabelProvider

use of net.heartsome.cat.ts.handlexlf.split.TableViewerLabelProvider 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 2 with TableViewerLabelProvider

use of net.heartsome.cat.ts.handlexlf.split.TableViewerLabelProvider in project translationstudio8 by heartsome.

the class SplitXliffWizardPage method createSplitInfo.

/**
	 * 创建分割文件段的相关信息
	 * @param tparent
	 */
public void createSplitInfo(Composite tparent) {
    tableViewer = new TableViewer(tparent, 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.SplitXliffWizardPage.columnNames1"), Messages.getString("wizard.SplitXliffWizardPage.columnNames2"), Messages.getString("wizard.SplitXliffWizardPage.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]);
    }
    tableViewer.setLabelProvider(new TableViewerLabelProvider());
    tableViewer.setContentProvider(new ArrayContentProvider());
    tableViewer.setInput(splitXliff.getSplitTableInfos());
    // 让列表列宽动态变化
    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.5, 0.29 };
                    for (int i = 0; i < columns.length; i++) columns[i].setWidth((int) (table.getBounds().width * columnWidths[i]));
                }
            });
        }
    });
}
Also used : Table(org.eclipse.swt.widgets.Table) Listener(org.eclipse.swt.widgets.Listener) TableColumn(org.eclipse.swt.widgets.TableColumn) 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) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

TableViewerLabelProvider (net.heartsome.cat.ts.handlexlf.split.TableViewerLabelProvider)2 ArrayContentProvider (org.eclipse.jface.viewers.ArrayContentProvider)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 GridData (org.eclipse.swt.layout.GridData)2 Event (org.eclipse.swt.widgets.Event)2 Listener (org.eclipse.swt.widgets.Listener)2 Table (org.eclipse.swt.widgets.Table)2 TableColumn (org.eclipse.swt.widgets.TableColumn)2 FileFolderSelectionDialog (net.heartsome.cat.common.ui.dialog.FileFolderSelectionDialog)1 LocalFile (org.eclipse.core.internal.filesystem.local.LocalFile)1 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 ISelection (org.eclipse.jface.viewers.ISelection)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Button (org.eclipse.swt.widgets.Button)1 Composite (org.eclipse.swt.widgets.Composite)1 Group (org.eclipse.swt.widgets.Group)1