Search in sources :

Example 1 with ViewerSorter

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

the class LoginProjectPage method instantiateControl.

@Override
public void instantiateControl(Composite container) {
    /**
         * 1. Create all the control first
         */
    //$NON-NLS-1$
    String execute = Messages.getString("LoginProjectPage.execute");
    // Image openImage = ImageProvider.getImage(ERepositoryImages.OPEN_PROJECT_ICON);
    // Connection Area
    title = new Label(container, SWT.NONE);
    title.setFont(LoginDialogV2.fixedFont);
    //$NON-NLS-1$
    title.setText(Messages.getString("LoginProjectPage.title"));
    connectionManageArea = new Composite(container, SWT.NONE);
    connectionsViewer = new ComboViewer(connectionManageArea, SWT.READ_ONLY);
    connectionsViewer.getControl().setFont(LoginDialogV2.fixedFont);
    manageButton = new Button(connectionManageArea, SWT.NONE);
    manageButton.setFont(LoginDialogV2.fixedFont);
    manageButton.setBackground(backgroundColor);
    //$NON-NLS-1$
    manageButton.setText(Messages.getString("LoginProjectPage.manage"));
    // Project Operation Area
    projectOperationArea = new Composite(container, SWT.NONE);
    // Existing Project Area
    selectExistingProject = new Button(projectOperationArea, SWT.RADIO);
    selectExistingProject.setFont(LoginDialogV2.fixedFont);
    selectExistingProject.setBackground(backgroundColor);
    //$NON-NLS-1$
    selectExistingProject.setText(Messages.getString("LoginProjectPage.selectProject"));
    projectListArea = new Composite(projectOperationArea, SWT.NONE);
    projectViewer = new ListViewer(projectListArea, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL);
    projectViewer.getControl().setFont(LoginDialogV2.fixedFont);
    projectViewer.setContentProvider(ArrayContentProvider.getInstance());
    projectViewer.setLabelProvider(new ProjectLabelProvider());
    projectViewer.setSorter(new ViewerSorter());
    // Branch Area
    branchArea = new Composite(projectListArea, SWT.NONE);
    branchLabel = new Label(branchArea, SWT.NONE);
    branchLabel.setFont(LoginDialogV2.fixedFont);
    //$NON-NLS-1$
    branchLabel.setText(Messages.getString("LoginProjectPage.Branch"));
    branchesViewer = new ComboViewer(branchArea, SWT.READ_ONLY);
    branchesViewer.getControl().setFont(LoginDialogV2.fixedFont);
    branchesViewer.setContentProvider(ArrayContentProvider.getInstance());
    branchesViewer.setLabelProvider(new LabelProvider());
    refreshProjectButton = new Button(branchArea, SWT.NONE);
    refreshProjectButton.setFont(LoginDialogV2.fixedFont);
    refreshProjectButton.setBackground(backgroundColor);
    refreshProjectButton.setImage(ImageProvider.getImage(EImage.REFRESH_ICON));
    // Create New Project
    createNewProject = new Button(projectOperationArea, SWT.RADIO);
    createNewProject.setFont(LoginDialogV2.fixedFont);
    createNewProject.setBackground(backgroundColor);
    //$NON-NLS-1$
    createNewProject.setText(Messages.getString("LoginProjectPage.createNewProject"));
    newProjectName = new Text(projectOperationArea, SWT.BORDER);
    newProjectName.setFont(LoginDialogV2.fixedFont);
    newProjectName.setBackground(backgroundColor);
    executeCreateNewProject = new Button(projectOperationArea, SWT.NONE);
    executeCreateNewProject.setFont(LoginDialogV2.fixedFont);
    //$NON-NLS-1$
    executeCreateNewProject.setText(Messages.getString("LoginProjectPage.create"));
    executeCreateNewProject.setBackground(backgroundColor);
    // Import Demo Project
    importDemoProject = new Button(projectOperationArea, SWT.RADIO);
    importDemoProject.setFont(LoginDialogV2.fixedFont);
    importDemoProject.setBackground(backgroundColor);
    //$NON-NLS-1$
    importDemoProject.setText(Messages.getString("LoginProjectPage.importDemoProject"));
    executeImportDemoProject = new Button(projectOperationArea, SWT.NONE);
    executeImportDemoProject.setFont(LoginDialogV2.fixedFont);
    // executeImportDemoProject.setImage(openImage);
    executeImportDemoProject.setText(execute);
    executeImportDemoProject.setBackground(backgroundColor);
    // Import Local Project
    importLocalProject = new Button(projectOperationArea, SWT.RADIO);
    importLocalProject.setFont(LoginDialogV2.fixedFont);
    importLocalProject.setBackground(backgroundColor);
    //$NON-NLS-1$
    importLocalProject.setText(Messages.getString("LoginProjectPage.importLocalProject"));
    executeImportLocalProject = new Button(projectOperationArea, SWT.NONE);
    executeImportLocalProject.setFont(LoginDialogV2.fixedFont);
    // executeImportLocalProject.setImage(openImage);
    executeImportLocalProject.setText(execute);
    executeImportLocalProject.setBackground(backgroundColor);
    // Create SandBox Project
    createSandBoxProject = new Button(projectOperationArea, SWT.RADIO);
    createSandBoxProject.setFont(LoginDialogV2.fixedFont);
    createSandBoxProject.setBackground(backgroundColor);
    //$NON-NLS-1$
    createSandBoxProject.setText(Messages.getString("LoginProjectPage.createSandBoxProject.title"));
    executeCreateSandBoxProject = new Button(projectOperationArea, SWT.NONE);
    executeCreateSandBoxProject.setFont(LoginDialogV2.fixedFont);
    // executeCreateSandBoxProject.setImage(openImage);
    executeCreateSandBoxProject.setText(execute);
    executeCreateSandBoxProject.setBackground(backgroundColor);
    super.instantiateControl(container);
}
Also used : ListViewer(org.eclipse.jface.viewers.ListViewer) Composite(org.eclipse.swt.widgets.Composite) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) Label(org.eclipse.swt.widgets.Label) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) Text(org.eclipse.swt.widgets.Text) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 2 with ViewerSorter

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

the class ImportItemWizardPage method createErrorsList.

private void createErrorsList(Composite workArea) {
    Composite composite = new Composite(workArea, SWT.NONE);
    GridLayout layout = new GridLayout();
    layout.makeColumnsEqualWidth = false;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    GridData gridData = new GridData(GridData.GRAB_HORIZONTAL | GridData.GRAB_VERTICAL | GridData.FILL_BOTH);
    gridData.heightHint = 100;
    composite.setLayoutData(gridData);
    Label title = new Label(composite, SWT.NONE);
    //$NON-NLS-1$
    title.setText(Messages.getString("ImportItemWizardPage.ErrorsAndWarnings"));
    title.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    errorsList = new TableViewer(composite, SWT.BORDER);
    errorsList.getControl().setLayoutData(gridData);
    errorsList.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void dispose() {
        }

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }

        @Override
        public Object[] getElements(Object inputElement) {
            return errors.toArray();
        }
    });
    errorsList.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            return element.toString();
        }
    });
    errorsList.setInput(this);
    errorsList.setSorter(new ViewerSorter());
}
Also used : GridLayout(org.eclipse.swt.layout.GridLayout) Composite(org.eclipse.swt.widgets.Composite) GridData(org.eclipse.swt.layout.GridData) Label(org.eclipse.swt.widgets.Label) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) TableViewer(org.eclipse.jface.viewers.TableViewer) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) CheckboxTreeViewer(org.eclipse.jface.viewers.CheckboxTreeViewer) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) TableViewer(org.eclipse.jface.viewers.TableViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 3 with ViewerSorter

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

the class PaletteSettingPage method addTreeViewer.

/**
     * qwei Comment method "addViewer".
     * 
     * @param parent
     */
private void addTreeViewer(ThreeCompositesSashForm parent) {
    ViewerSorter sorter = new ViewerSorter() {

        /*
             * (non-Javadoc)
             * 
             * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer,
             * java.lang.Object, java.lang.Object)
             */
        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            if (e1 instanceof ComponentPaletteItem && e2 instanceof ComponentPaletteItem) {
                return super.compare(viewer, ((IPaletteItem) e1).getLabel(), ((IPaletteItem) e2).getLabel());
            } else if (e1 instanceof FolderPaletteItem && e2 instanceof FolderPaletteItem) {
                return super.compare(viewer, ((IPaletteItem) e1).getLabel(), ((IPaletteItem) e2).getLabel());
            } else if (e1 instanceof ComponentPaletteItem && e2 instanceof FolderPaletteItem) {
                return 1;
            } else if (e1 instanceof FolderPaletteItem && e2 instanceof ComponentPaletteItem) {
                return -1;
            } else if (e1 instanceof RootPaletteItem && e2 instanceof RootPaletteItem) {
                if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_DI) {
                    // up
                    return -1;
                } else if (((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_DI) {
                    // down
                    return 1;
                } else if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_CAMEL && ((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_MAPREDUCE) {
                    // up
                    return -1;
                } else if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_MAPREDUCE && ((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_CAMEL) {
                    // down
                    return 1;
                } else if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_MAPREDUCE && ((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_STORM) {
                    // up
                    return -1;
                } else if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_STORM && ((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_MAPREDUCE) {
                    // down
                    return 1;
                } else if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_CAMEL && ((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_STORM) {
                    // up
                    return -1;
                } else if (((IPaletteItem) e1).getPaletteType() == ComponentCategory.CATEGORY_4_STORM && ((IPaletteItem) e2).getPaletteType() == ComponentCategory.CATEGORY_4_CAMEL) {
                    // down
                    return 1;
                }
            }
            return super.compare(viewer, e1, e2);
        }
    };
    List<IPaletteItem> input = getViewerInput();
    Composite leftComposite = parent.getLeftComposite();
    Label label = new Label(leftComposite, SWT.NONE);
    label.setText("Hide");
    hiddenViewer = new TreeViewer(leftComposite);
    hiddenViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    hiddenViewer.setContentProvider(new TalendPaletteTreeProvider());
    hiddenViewer.setLabelProvider(new TalendPaletteLabelProvider());
    hiddenViewer.addFilter(getFilterForComponent(false));
    hiddenViewer.setSorter(sorter);
    hiddenViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            displayComponentsButton.setEnabled(!event.getSelection().isEmpty());
        }
    });
    createButtons(parent.getMidComposite());
    Composite rightComposite = parent.getRightComposite();
    label = new Label(rightComposite, SWT.NONE);
    label.setText("Show");
    displayViewer = new TreeViewer(rightComposite);
    displayViewer.getControl().setLayoutData(new GridData(GridData.FILL_BOTH));
    displayViewer.setContentProvider(new TalendPaletteTreeProvider());
    displayViewer.setLabelProvider(new TalendPaletteLabelProvider());
    displayViewer.addFilter(getFilterForComponent(true));
    displayViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            hideCompnentsButton.setEnabled(!event.getSelection().isEmpty());
        }
    });
    displayViewer.setSorter(sorter);
    getComponentsFromProject(project);
    hiddenViewer.setInput(input);
    displayViewer.setInput(input);
    if (!input.isEmpty()) {
        displayViewer.expandToLevel(input.get(0), 1);
    }
    if (!input.isEmpty()) {
        hiddenViewer.expandToLevel(input.get(0), 1);
    }
}
Also used : ComponentPaletteItem(org.talend.repository.preference.palettesettings.ComponentPaletteItem) Composite(org.eclipse.swt.widgets.Composite) IPaletteItem(org.talend.core.ui.component.preference.provider.IPaletteItem) TreeViewer(org.eclipse.jface.viewers.TreeViewer) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) Label(org.eclipse.swt.widgets.Label) TreeViewer(org.eclipse.jface.viewers.TreeViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FolderPaletteItem(org.talend.repository.preference.palettesettings.FolderPaletteItem) TalendPaletteTreeProvider(org.talend.core.ui.component.preference.provider.TalendPaletteTreeProvider) RootPaletteItem(org.talend.repository.preference.palettesettings.RootPaletteItem) GridData(org.eclipse.swt.layout.GridData) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) TalendPaletteLabelProvider(org.talend.core.ui.component.preference.provider.TalendPaletteLabelProvider)

Example 4 with ViewerSorter

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

the class ProcessVersionComposite method addSortListener.

/**
     * DOC Administrator Comment method "addSortListener".
     * 
     * @param table
     * @param column1
     * @param column2
     * @param column3
     */
private void addSortListener(final Table table, final TableColumn column1, final TableColumn column2, final TableColumn column3, final TableColumn column4) {
    Listener sortListener = new Listener() {

        private int direction = 1;

        @Override
        public void handleEvent(Event e) {
            final TableColumn column = (TableColumn) e.widget;
            if (column == table.getSortColumn()) {
                direction = -direction;
            }
            if (direction == 1) {
                table.setSortDirection(SWT.DOWN);
            } else {
                table.setSortDirection(SWT.UP);
            }
            table.setSortColumn(column);
            tableViewer.setSorter(new ViewerSorter() {

                int index = 0;

                @Override
                public void sort(Viewer viewer, Object[] elements) {
                    while (index < table.getColumns().length && table.getColumn(index) != column) {
                        index++;
                    }
                    super.sort(viewer, elements);
                }

                @Override
                public int compare(Viewer viewer, Object e1, Object e2) {
                    ITableLabelProvider labelProvider = (ITableLabelProvider) tableViewer.getLabelProvider();
                    String columnText = labelProvider.getColumnText(e1, index) != null ? labelProvider.getColumnText(e1, index) : //$NON-NLS-1$
                    "";
                    String columnText2 = labelProvider.getColumnText(e2, index) != null ? labelProvider.getColumnText(e2, index) : //$NON-NLS-1$
                    "";
                    return getComparator().compare(columnText, columnText2) * direction;
                }
            });
        }
    };
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        /*
             * (non-Javadoc)
             * 
             * @seeorg.eclipse.jface.viewers.ISelectionChangedListener#selectionChanged(org.eclipse.jface.viewers.
             * SelectionChangedEvent)
             */
        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            ProcessVersionComposite.this.selection = event.getSelection();
            if (getParentWizard() != null) {
                ((WizardPage) getParentWizard()).setPageComplete(true);
            }
        }
    });
    column1.addListener(SWT.Selection, sortListener);
    column2.addListener(SWT.Selection, sortListener);
    column3.addListener(SWT.Selection, sortListener);
    column4.addListener(SWT.Selection, sortListener);
    table.setSortColumn(column1);
    table.setSortDirection(SWT.DOWN);
    tableViewer.addDoubleClickListener(new IDoubleClickListener() {

        @Override
        public void doubleClick(DoubleClickEvent event) {
            if (getParentWizard() == null) {
                ITreeContextualAction editPropertiesAction = getEditPropertiesAction(EditPropertiesAction.class);
                if (editPropertiesAction != null) {
                    editPropertiesAction.run();
                }
            }
        }
    });
}
Also used : IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) IMenuListener(org.eclipse.jface.action.IMenuListener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Listener(org.eclipse.swt.widgets.Listener) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) ITreeContextualAction(org.talend.commons.ui.swt.actions.ITreeContextualAction) TableColumn(org.eclipse.swt.widgets.TableColumn) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) EditPropertiesAction(org.talend.repository.ui.actions.EditPropertiesAction) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Event(org.eclipse.swt.widgets.Event) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IRepositoryObject(org.talend.core.model.repository.IRepositoryObject)

Example 5 with ViewerSorter

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

the class VersionSection method createControls.

@Override
public void createControls(Composite parent, TabbedPropertySheetPage aTabbedPropertySheetPage) {
    super.createControls(parent, aTabbedPropertySheetPage);
    composite = getWidgetFactory().createFlatFormComposite(parent);
    tableViewer = new TableViewer(composite, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    final Table table = tableViewer.getTable();
    TableLayout tableLayout = new TableLayout();
    table.setLayout(tableLayout);
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    final String[] columnProperties = new String[] { //$NON-NLS-1$
    Messages.getString("VersionSection.Version"), //$NON-NLS-1$
    Messages.getString("VersionSection.CreationDate"), Messages.getString("VersionSection.ModificationDate"), //$NON-NLS-1$ //$NON-NLS-2$ 
    Messages.getString("VersionSection.Status") };
    final TableColumn column1 = new TableColumn(table, SWT.NONE);
    tableLayout.addColumnData(new ColumnPixelData(125, true));
    column1.setText(columnProperties[0]);
    final TableColumn column2 = new TableColumn(table, SWT.NONE);
    tableLayout.addColumnData(new ColumnPixelData(125, true));
    column2.setText(columnProperties[1]);
    final TableColumn column3 = new TableColumn(table, SWT.NONE);
    tableLayout.addColumnData(new ColumnPixelData(125, true));
    column3.setText(columnProperties[2]);
    final TableColumn column4 = new TableColumn(table, SWT.NONE);
    tableLayout.addColumnData(new ColumnWeightData(1, 150, true));
    column4.setText(columnProperties[3]);
    tableViewer.setColumnProperties(columnProperties);
    Object layoutData = parent.getLayoutData();
    if (layoutData instanceof GridData) {
        GridData gridData = (GridData) layoutData;
        gridData.grabExcessVerticalSpace = true;
        gridData.verticalAlignment = SWT.FILL;
    }
    FormData formData = new FormData();
    formData.left = new FormAttachment(0);
    formData.top = new FormAttachment(0);
    formData.right = new FormAttachment(100);
    formData.bottom = new FormAttachment(100);
    table.setLayoutData(formData);
    tableViewer.setContentProvider(new IStructuredContentProvider() {

        public Object[] getElements(Object inputElement) {
            IRepositoryViewObject repositoryObject = ((IRepositoryViewObject) inputElement);
            if (repositoryObject.getProperty() == null) {
                return null;
            }
            RepositoryNode parentRepositoryNode = RepositoryNodeUtilities.getParentRepositoryNodeFromSelection(repositoryObject);
            try {
                List<IRepositoryViewObject> allVersion = ProxyRepositoryFactory.getInstance().getAllVersion(repositoryObject.getId());
                Collections.sort(allVersion, new IRepositoryObjectComparator());
                Object[] objects = new Object[allVersion.size()];
                for (int i = 0; i < objects.length; i++) {
                    IRepositoryViewObject repositoryObjectVersion = allVersion.get(i);
                    RepositoryNode repositoryNode = createRepositoryNode(parentRepositoryNode, repositoryObjectVersion);
                    objects[i] = repositoryNode;
                }
                return objects;
            } catch (PersistenceException e) {
                return null;
            }
        }

        private RepositoryNode createRepositoryNode(RepositoryNode parentRepositoryNode, IRepositoryViewObject repositoryObjectVersion) {
            ERepositoryObjectType itemType = ERepositoryObjectType.getItemType(repositoryObjectVersion.getProperty().getItem());
            RepositoryNode repositoryNode = new RepositoryNode(repositoryObjectVersion, parentRepositoryNode, ENodeType.REPOSITORY_ELEMENT);
            repositoryNode.setProperties(EProperties.CONTENT_TYPE, itemType);
            repositoryNode.setProperties(EProperties.LABEL, repositoryObjectVersion.getLabel());
            return repositoryNode;
        }

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    tableViewer.setLabelProvider(new ITableLabelProvider() {

        public Image getColumnImage(Object element, int columnIndex) {
            return null;
        }

        public String getColumnText(Object element, int columnIndex) {
            RepositoryNode repositoryNode = (RepositoryNode) element;
            switch(columnIndex) {
                case 0:
                    return repositoryNode.getObject().getVersion();
                case 1:
                    if (repositoryNode.getObject().getCreationDate() != null) {
                        return FORMATTER.format(repositoryNode.getObject().getCreationDate());
                    } else {
                        return null;
                    }
                case 2:
                    if (repositoryNode.getObject().getModificationDate() != null) {
                        return FORMATTER.format(repositoryNode.getObject().getModificationDate());
                    } else {
                        return null;
                    }
                case 3:
                    if (repositoryNode.getObject().getStatusCode() != null) {
                        return repositoryNode.getObject().getStatusCode();
                    } else {
                        return null;
                    }
                default:
                    return null;
            }
        }

        public void addListener(ILabelProviderListener listener) {
        }

        public void dispose() {
        }

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

        public void removeListener(ILabelProviderListener listener) {
        }
    });
    //$NON-NLS-1$
    MenuManager menuMgr = new MenuManager("#PopUp");
    menuMgr.setRemoveAllWhenShown(true);
    menuMgr.addMenuListener(new IMenuListener() {

        public void menuAboutToShow(IMenuManager mgr) {
            ISelection selection = tableViewer.getSelection();
            if (selection instanceof IStructuredSelection) {
                IStructuredSelection structuredSelection = (IStructuredSelection) selection;
                List<ITreeContextualAction> contextualsActions = ActionsHelper.getRepositoryContextualsActions();
                for (ITreeContextualAction action : contextualsActions) {
                    if (action.isReadAction() || action.isEditAction() || action.isPropertiesAction()) {
                        action.init(null, structuredSelection);
                        if (action.isVisible()) {
                            mgr.add(action);
                        }
                    }
                }
            }
        }
    });
    Menu menu = menuMgr.createContextMenu(tableViewer.getControl());
    tableViewer.getControl().setMenu(menu);
    Listener sortListener = new Listener() {

        private int direction = 1;

        public void handleEvent(Event e) {
            final TableColumn column = (TableColumn) e.widget;
            if (column == table.getSortColumn()) {
                direction = -direction;
            }
            if (direction == 1) {
                table.setSortDirection(SWT.DOWN);
            } else {
                table.setSortDirection(SWT.UP);
            }
            table.setSortColumn(column);
            tableViewer.setSorter(new ViewerSorter() {

                int index = 0;

                @Override
                public void sort(Viewer viewer, Object[] elements) {
                    while (index < table.getColumns().length && table.getColumn(index) != column) {
                        index++;
                    }
                    super.sort(viewer, elements);
                }

                @Override
                public int compare(Viewer viewer, Object e1, Object e2) {
                    ITableLabelProvider labelProvider = (ITableLabelProvider) tableViewer.getLabelProvider();
                    String columnText = labelProvider.getColumnText(e1, index) != null ? labelProvider.getColumnText(e1, index) : //$NON-NLS-1$
                    "";
                    String columnText2 = labelProvider.getColumnText(e2, index) != null ? labelProvider.getColumnText(e2, index) : //$NON-NLS-1$
                    "";
                    return getComparator().compare(columnText, columnText2) * direction;
                }
            });
        }
    };
    column1.addListener(SWT.Selection, sortListener);
    column2.addListener(SWT.Selection, sortListener);
    column3.addListener(SWT.Selection, sortListener);
    column4.addListener(SWT.Selection, sortListener);
    table.setSortColumn(column1);
    table.setSortDirection(SWT.DOWN);
    aTabbedPropertySheetPage.getSite().setSelectionProvider(this);
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Listener(org.eclipse.swt.widgets.Listener) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) IMenuListener(org.eclipse.jface.action.IMenuListener) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ITreeContextualAction(org.talend.commons.ui.swt.actions.ITreeContextualAction) Image(org.eclipse.swt.graphics.Image) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) ISelection(org.eclipse.jface.viewers.ISelection) List(java.util.List) Menu(org.eclipse.swt.widgets.Menu) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) TableLayout(org.eclipse.jface.viewers.TableLayout) FormAttachment(org.eclipse.swt.layout.FormAttachment) FormData(org.eclipse.swt.layout.FormData) Table(org.eclipse.swt.widgets.Table) ColumnPixelData(org.eclipse.jface.viewers.ColumnPixelData) RepositoryNode(org.talend.repository.model.RepositoryNode) TableColumn(org.eclipse.swt.widgets.TableColumn) IMenuListener(org.eclipse.jface.action.IMenuListener) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) MenuManager(org.eclipse.jface.action.MenuManager) IMenuManager(org.eclipse.jface.action.IMenuManager) Event(org.eclipse.swt.widgets.Event) IRepositoryObject(org.talend.core.model.repository.IRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IMenuManager(org.eclipse.jface.action.IMenuManager) TableViewer(org.eclipse.jface.viewers.TableViewer)

Aggregations

ViewerSorter (org.eclipse.jface.viewers.ViewerSorter)11 GridData (org.eclipse.swt.layout.GridData)6 Composite (org.eclipse.swt.widgets.Composite)6 Label (org.eclipse.swt.widgets.Label)6 Viewer (org.eclipse.jface.viewers.Viewer)5 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)4 TableViewer (org.eclipse.jface.viewers.TableViewer)4 ILabelProviderListener (org.eclipse.jface.viewers.ILabelProviderListener)3 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)3 Image (org.eclipse.swt.graphics.Image)3 GridLayout (org.eclipse.swt.layout.GridLayout)3 Button (org.eclipse.swt.widgets.Button)3 Table (org.eclipse.swt.widgets.Table)3 TableColumn (org.eclipse.swt.widgets.TableColumn)3 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)3 SorterComparatorAdapter (bndtools.model.obr.SorterComparatorAdapter)2 IMenuListener (org.eclipse.jface.action.IMenuListener)2 CheckStateChangedEvent (org.eclipse.jface.viewers.CheckStateChangedEvent)2 CheckboxTableViewer (org.eclipse.jface.viewers.CheckboxTableViewer)2 ICheckStateListener (org.eclipse.jface.viewers.ICheckStateListener)2