Search in sources :

Example 6 with ViewerFilter

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

the class ImportDocxDialog method initListener.

/**
	 * 初始化按钮监听 ;
	 */
private void initListener() {
    browseXLIFFBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            FileFolderSelectionDialog dialog = new FileFolderSelectionDialog(getShell(), false, IResource.FILE) {

                // 打开对话框时展开树形目录
                public void create() {
                    super.create();
                    super.getTreeViewer().expandAll();
                }
            };
            dialog.setTitle(Messages.getString("ImportDocxDialog.browseXLIFFBtn.msg0"));
            dialog.setMessage(Messages.getString("ImportDocxDialog.browseXLIFFBtn.msg1"));
            dialog.setDoubleClickSelects(true);
            dialog.setAllowMultiple(false);
            try {
                dialog.setInput(EFS.getStore(root.getLocationURI()));
            } catch (CoreException e1) {
                LOGGER.error(Messages.getString("ImportDocxDialog.LOGGER.logger1"), e1);
            }
            dialog.addFilter(new ViewerFilter() {

                @SuppressWarnings("restriction")
                @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")) {
                            return false;
                        }
                        if (lstProject.contains(folder.toString())) {
                            return true;
                        }
                        String xliffFolderPath = folder.toString();
                        for (String projectPath : lstProject) {
                            String path1 = projectPath + System.getProperty("file.separator") + Constant.FOLDER_XLIFF;
                            if (xliffFolderPath.startsWith(path1)) {
                                return true;
                            }
                        }
                    }
                    return false;
                }
            });
            dialog.create();
            dialog.open();
            if (dialog.getResult() != null) {
                Object obj = dialog.getFirstResult();
                IFile file = root.getFileForLocation(Path.fromOSString(obj.toString()));
                xliffPathTxt.setText(file.getFullPath().toOSString());
                xliffFullPath = ResourceUtils.iFileToOSPath(file);
            }
        }
    });
    browseDocxBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(getShell());
            dialog.setText(Messages.getString("ImportDocxDialog.browseDocx.title"));
            dialog.setFilterExtensions(new String[] { "*.docx", "*.*" });
            dialog.setFilterNames(new String[] { Messages.getString(Messages.getString("ImportDocxDialog.browseDocx.filter")) });
            String fileSep = System.getProperty("file.separator");
            if (docxPathTxt.getText() != null && !docxPathTxt.getText().trim().equals("")) {
                dialog.setFilterPath(docxPathTxt.getText().substring(0, docxPathTxt.getText().lastIndexOf(fileSep)));
                dialog.setFileName(docxPathTxt.getText().substring(docxPathTxt.getText().lastIndexOf(fileSep) + 1));
            } else {
                dialog.setFilterPath(System.getProperty("user.home"));
            }
            String path = dialog.open();
            if (path != null) {
                docxPathTxt.setText(path);
            }
        }
    });
}
Also used : LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) SelectionEvent(org.eclipse.swt.events.SelectionEvent) Viewer(org.eclipse.jface.viewers.Viewer) FileFolderSelectionDialog(net.heartsome.cat.common.ui.dialog.FileFolderSelectionDialog) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 7 with ViewerFilter

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

the class ImportExternalDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite composite = (Composite) super.createDialogArea(parent);
    composite.setLayout(new GridLayout(1, false));
    GridDataFactory.fillDefaults().hint(500, 180).grab(true, true).applyTo(composite);
    Group groupXLIFF = new Group(composite, SWT.None);
    groupXLIFF.setLayoutData(new GridData(GridData.FILL_BOTH));
    groupXLIFF.setLayout(new GridLayout(3, false));
    groupXLIFF.setText(Messages.getString("ImportDocxDialog.XLIFFgroup"));
    Label lblXLIFF = new Label(groupXLIFF, SWT.None);
    lblXLIFF.setText(Messages.getString("ImportDocxDialog.lable.xliff"));
    xliffPathTxt = new Text(groupXLIFF, SWT.BORDER);
    xliffPathTxt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    xliffPathTxt.setEditable(false);
    if (xliffRelativePath != null) {
        xliffPathTxt.setText(xliffRelativePath);
    }
    browseXLIFFBtn = new Button(groupXLIFF, SWT.None);
    browseXLIFFBtn.setText(Messages.getString("ImportDocxDialog.browseXLIFFBtn"));
    browseXLIFFBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent event) {
            FileFolderSelectionDialog dialog = new FileFolderSelectionDialog(getShell(), false, IResource.FILE) {

                // 打开对话框时展开树形目录
                public void create() {
                    super.create();
                    super.getTreeViewer().expandAll();
                }
            };
            dialog.setTitle(Messages.getString("ImportDocxDialog.browseXLIFFBtn.msg0"));
            dialog.setMessage(Messages.getString("ImportDocxDialog.browseXLIFFBtn.msg1"));
            dialog.setDoubleClickSelects(true);
            dialog.setAllowMultiple(false);
            try {
                dialog.setInput(EFS.getStore(root.getLocationURI()));
            } catch (CoreException e1) {
                LOGGER.error(Messages.getString("ImportDocxDialog.LOGGER.logger1"), e1);
            }
            dialog.addFilter(new ViewerFilter() {

                @SuppressWarnings("restriction")
                @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")) {
                            return false;
                        }
                        if (lstProject.contains(folder.toString())) {
                            return true;
                        }
                        String xliffFolderPath = folder.toString();
                        for (String projectPath : lstProject) {
                            String path1 = projectPath + System.getProperty("file.separator") + Constant.FOLDER_XLIFF;
                            if (xliffFolderPath.startsWith(path1)) {
                                return true;
                            }
                        }
                    }
                    return false;
                }
            });
            dialog.create();
            if (Window.OK == dialog.open()) {
                if (dialog.getResult() != null) {
                    Object obj = dialog.getFirstResult();
                    IFile file = root.getFileForLocation(Path.fromOSString(obj.toString()));
                    xliffPathTxt.setText(file.getFullPath().toOSString());
                    xliffFullPath = ResourceUtils.iFileToOSPath(file);
                }
                getButton(IDialogConstants.OK_ID).setEnabled(!docxPathTxt.getText().isEmpty());
            }
        }
    });
    Group groupExternal = new Group(composite, SWT.NONE);
    groupExternal.setText(Messages.getString("ImportDocxDialog.label.docx.title"));
    groupExternal.setLayout(new GridLayout(3, false));
    groupExternal.setLayoutData(new GridData(GridData.FILL_BOTH));
    Label lblRTF = new Label(groupExternal, SWT.None);
    lblRTF.setText(Messages.getString("ImportDocxDialog.label.docx"));
    GridDataFactory.swtDefaults().align(SWT.RIGHT, SWT.CENTER).grab(false, false).applyTo(lblRTF);
    docxPathTxt = new Text(groupExternal, SWT.BORDER);
    docxPathTxt.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    docxPathTxt.setEditable(false);
    browseDocxBtn = new Button(groupExternal, SWT.None);
    browseDocxBtn.setText(Messages.getString("ImportDocxDialog.browseDocxBtn"));
    browseDocxBtn.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            FileDialog dialog = new FileDialog(getShell());
            dialog.setText(Messages.getString("ImportDocxDialog.browseDocx.title"));
            dialog.setFilterExtensions(new String[] { "*.docx;", "*.*" });
            dialog.setFilterPath(dialogSetting.get("defaultPath"));
            String path = dialog.open();
            if (path != null) {
                if (testFileType(path)) {
                    dialogSetting.put("defaultPath", path.substring(0, path.lastIndexOf(File.separator)));
                    docxPathTxt.setText(path);
                    getButton(IDialogConstants.OK_ID).setEnabled(true && (!xliffPathTxt.getText().isEmpty()));
                } else {
                    getButton(IDialogConstants.OK_ID).setEnabled(false);
                }
            }
        }
    });
    txtImportType = new Label(composite, SWT.READ_ONLY);
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BOTTOM).span(1, 3).grab(true, true).applyTo(txtImportType);
    return composite;
}
Also used : Group(org.eclipse.swt.widgets.Group) IFile(org.eclipse.core.resources.IFile) Composite(org.eclipse.swt.widgets.Composite) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Text(org.eclipse.swt.widgets.Text) Viewer(org.eclipse.jface.viewers.Viewer) GridLayout(org.eclipse.swt.layout.GridLayout) LocalFile(org.eclipse.core.internal.filesystem.local.LocalFile) CoreException(org.eclipse.core.runtime.CoreException) Button(org.eclipse.swt.widgets.Button) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) FileFolderSelectionDialog(net.heartsome.cat.common.ui.dialog.FileFolderSelectionDialog) FileDialog(org.eclipse.swt.widgets.FileDialog)

Example 8 with ViewerFilter

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

the class WorkingSetActionProvider method setWorkingSetFilter.

private void setWorkingSetFilter(IWorkingSet workingSet, boolean firstTime) {
    ResourceWorkingSetFilter workingSetFilter = null;
    ViewerFilter[] filters = viewer.getFilters();
    for (int i = 0; i < filters.length; i++) {
        if (filters[i] instanceof ResourceWorkingSetFilter) {
            workingSetFilter = (ResourceWorkingSetFilter) filters[i];
            break;
        }
    }
    if (workingSetFilter == null) {
        if (firstTime) {
            filterService.addActiveFilterIds(new String[] { WORKING_SET_FILTER_ID });
            filterService.updateViewer();
            setWorkingSetFilter(workingSet, !FIRST_TIME);
            return;
        }
        WorkbenchNavigatorPlugin.log(//$NON-NLS-1$
        "Required filter " + WORKING_SET_FILTER_ID + //$NON-NLS-1$
        " is not present. Working set support will not function correctly.", //$NON-NLS-1$
        new Status(IStatus.ERROR, WorkbenchNavigatorPlugin.PLUGIN_ID, ""));
        return;
    }
    workingSetFilter.setWorkingSet(emptyWorkingSet ? null : workingSet);
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ResourceWorkingSetFilter(org.eclipse.ui.ResourceWorkingSetFilter)

Example 9 with ViewerFilter

use of org.eclipse.jface.viewers.ViewerFilter in project AutoRefactor by JnRouvignac.

the class ChooseRefactoringWizardPage method createRefactoringsTable.

private void createRefactoringsTable(Composite parent) {
    tableViewer = newCheckList(parent, BORDER | H_SCROLL | CHECK | NO_FOCUS | HIDE_SELECTION);
    createColumns(tableViewer);
    tableViewer.setContentProvider(new ArrayContentProvider());
    final List<RefactoringRule> refactorings = AllRefactoringRules.getAllRefactoringRules();
    tableViewer.setInput(refactorings);
    tableViewer.setCheckStateProvider(new CheckStateProvider(refactorings));
    tableViewer.setComparator(new ViewerComparator() {

        @Override
        public int compare(Viewer viewer, Object o1, Object o2) {
            return ((RefactoringRule) o1).getName().compareTo(((RefactoringRule) o2).getName());
        }
    });
    tableViewer.addFilter(new ViewerFilter() {

        @Override
        public boolean select(Viewer viewer, Object parentElement, Object refactoring) {
            final String filter = filterText.getText().toLowerCase();
            final RefactoringRule rule = (RefactoringRule) refactoring;
            final String description = rule.getDescription().toLowerCase();
            final String name = rule.getName().toLowerCase();
            return description.contains(filter) || name.contains(filter);
        }
    });
    ColumnViewerToolTipSupport.enableFor(tableViewer, ToolTip.NO_RECREATE);
    tableViewer.setLabelProvider(new StyledCellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            final String filter = filterText.getText().toLowerCase();
            final String name = ((RefactoringRule) cell.getElement()).getName();
            cell.setText(name);
            cell.setStyleRanges(getStyleRanges(name, filter));
        }

        private StyleRange[] getStyleRanges(String text, String filter) {
            final int matchIndex = text.toLowerCase().indexOf(filter);
            final int matchLength = filter.length();
            if (matchIndex != -1 && matchLength != 0) {
                final StyledString styledString = new StyledString(text, defaultStyler);
                styledString.setStyle(matchIndex, matchLength, underlineStyler);
                return styledString.getStyleRanges();
            }
            return null;
        }

        @Override
        public String getToolTipText(Object refactoring) {
            return ((RefactoringRule) refactoring).getDescription();
        }

        @Override
        public Point getToolTipShift(Object object) {
            return new Point(10, 20);
        }
    });
    final Table table = tableViewer.getTable();
    table.setLinesVisible(true);
    tableViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true));
    packColumns(table);
    table.setFocus();
}
Also used : StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) Table(org.eclipse.swt.widgets.Table) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) TableViewer(org.eclipse.jface.viewers.TableViewer) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) StructuredViewer(org.eclipse.jface.viewers.StructuredViewer) Viewer(org.eclipse.jface.viewers.Viewer) ICheckStateProvider(org.eclipse.jface.viewers.ICheckStateProvider) StyledString(org.eclipse.jface.viewers.StyledString) StyledString(org.eclipse.jface.viewers.StyledString) Point(org.eclipse.swt.graphics.Point) ViewerCell(org.eclipse.jface.viewers.ViewerCell) RefactoringRule(org.autorefactor.refactoring.RefactoringRule) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) GridData(org.eclipse.swt.layout.GridData)

Example 10 with ViewerFilter

use of org.eclipse.jface.viewers.ViewerFilter in project tdi-studio-se by Talend.

the class DatabaseTypeFilter method createDialogArea.

protected Control createDialogArea(Composite parent, String specifiedPId) {
    Composite container = (Composite) super.createDialogArea(parent);
    //$NON-NLS-1$
    TimeMeasure.step(RepositoryReviewDialog.class.getSimpleName(), "before createDialogArea...");
    GridData data = (GridData) container.getLayoutData();
    data.minimumHeight = 400;
    data.heightHint = 400;
    data.minimumWidth = 500;
    data.widthHint = 500;
    container.setLayoutData(data);
    createFilterField(container);
    Composite viewContainer = new Composite(container, SWT.BORDER);
    viewContainer.setLayout(new GridLayout());
    viewContainer.setLayoutData(new GridData(GridData.FILL_BOTH));
    repositoryTreeViewer = RepoCommonViewerProvider.NORMAL.createViewer(viewContainer, specifiedPId);
    //$NON-NLS-1$
    TimeMeasure.step(RepositoryReviewDialog.class.getSimpleName(), "finshed createViewer");
    repositoryTreeViewer.getTree().setLayoutData(new GridData(GridData.FILL_BOTH));
    addFilter(textFilter);
    if (dbSupportFilter != null) {
        addFilter(dbSupportFilter);
    }
    if (additionalFilters != null) {
        addFilter(additionalFilters);
    }
    ViewerFilter filter = typeProcessor.makeFilter();
    addFilter(filter);
    //$NON-NLS-1$
    TimeMeasure.step(RepositoryReviewDialog.class.getSimpleName(), "finshed add Filters");
    //$NON-NLS-1$
    TimeMeasure.step(RepositoryReviewDialog.class.getSimpleName(), "set input");
    repositoryTreeViewer.expandToLevel(2);
    //$NON-NLS-1$
    TimeMeasure.step(RepositoryReviewDialog.class.getSimpleName(), "expandAll");
    final Label label = new Label(container, SWT.NONE);
    //$NON-NLS-1$
    label.setText(Messages.getString("RepositoryReviewDialog.label"));
    label.setForeground(new Color(null, 250, 0, 0));
    label.setVisible(false);
    // see feature 0003664: tRunJob: When opening the tree dialog to select the job target, it could be useful to
    // open it on previous selected job if exists
    selectNode();
    //$NON-NLS-1$
    TimeMeasure.step(RepositoryReviewDialog.class.getSimpleName(), "selectNode");
    repositoryTreeViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            boolean highlightOKButton = isSelectionValid(event);
            getButton(IDialogConstants.OK_ID).setEnabled(highlightOKButton);
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection != null && !selection.isEmpty()) {
                RepositoryNode node = (RepositoryNode) selection.getFirstElement();
                if (!highlightOKButton && node.getType() == ENodeType.REPOSITORY_ELEMENT && node.getObjectType().equals(ERepositoryObjectType.METADATA_VALIDATION_RULES)) {
                    label.setVisible(true);
                } else {
                    label.setVisible(false);
                }
            }
        }
    });
    repositoryTreeViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            if (getButton(IDialogConstants.OK_ID).isEnabled()) {
                okPressed();
            }
        }
    });
    //$NON-NLS-1$
    TimeMeasure.step(RepositoryReviewDialog.class.getSimpleName(), "finished createDialogArea...");
    TimeMeasure.end(RepositoryReviewDialog.class.getSimpleName());
    TimeMeasure.display = false;
    TimeMeasure.displaySteps = false;
    TimeMeasure.measureActive = false;
    return container;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) Color(org.eclipse.swt.graphics.Color) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) GridLayout(org.eclipse.swt.layout.GridLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData)

Aggregations

ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)29 Viewer (org.eclipse.jface.viewers.Viewer)22 Composite (org.eclipse.swt.widgets.Composite)16 GridData (org.eclipse.swt.layout.GridData)14 IFile (org.eclipse.core.resources.IFile)8 GridLayout (org.eclipse.swt.layout.GridLayout)8 CoreException (org.eclipse.core.runtime.CoreException)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)7 TableViewer (org.eclipse.jface.viewers.TableViewer)7 SelectionEvent (org.eclipse.swt.events.SelectionEvent)7 TreeViewer (org.eclipse.jface.viewers.TreeViewer)6 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)5 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)5 RepositoryNode (org.talend.repository.model.RepositoryNode)5 FileFolderSelectionDialog (net.heartsome.cat.common.ui.dialog.FileFolderSelectionDialog)4 LocalFile (org.eclipse.core.internal.filesystem.local.LocalFile)4 IStatus (org.eclipse.core.runtime.IStatus)4 Status (org.eclipse.core.runtime.Status)4 CheckboxTreeViewer (org.eclipse.jface.viewers.CheckboxTreeViewer)4 IOpenListener (org.eclipse.jface.viewers.IOpenListener)4