Search in sources :

Example 1 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider 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 2 with IStructuredContentProvider

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

the class ImportDemoProjectItemsPage method initializeViewer.

/**
     * initializeViewer.
     */
private void initializeViewer() {
    wizardSelectionViewer.setContentProvider(new IStructuredContentProvider() {

        @Override
        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        // TODO Auto-generated method stub
        }

        @Override
        public void dispose() {
        // TODO Auto-generated method stub
        }

        @Override
        public Object[] getElements(Object inputElement) {
            if (inputElement instanceof List) {
                return ((List) inputElement).toArray();
            }
            return null;
        }
    });
    wizardSelectionViewer.setLabelProvider(new ITableLabelProvider() {

        @Override
        public void removeListener(ILabelProviderListener listener) {
        }

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

        @Override
        public void dispose() {
        }

        @Override
        public void addListener(ILabelProviderListener listener) {
        }

        @Override
        public String getColumnText(Object element, int columnIndex) {
            if (element instanceof DemoProjectBean) {
                DemoProjectBean field = (DemoProjectBean) element;
                return field.getDemoDesc();
            }
            return "";
        }

        @Override
        public Image getColumnImage(Object element, int columnIndex) {
            if (element instanceof DemoProjectBean) {
                return getFullImagePath((DemoProjectBean) element);
            }
            return null;
        }
    });
    wizardSelectionViewer.setInput(this.demoProjectList);
}
Also used : ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) CheckboxTableViewer(org.eclipse.jface.viewers.CheckboxTableViewer) Viewer(org.eclipse.jface.viewers.Viewer) RepositoryViewObject(org.talend.core.model.repository.RepositoryViewObject) List(java.util.List) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image)

Example 3 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider 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)

Example 4 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider in project hale by halestudio.

the class ChooseHaleConnectProjectWizardPage method createContent.

/**
 * @see eu.esdihumboldt.hale.ui.util.wizard.ConfigurationWizardPage#createContent(org.eclipse.swt.widgets.Composite)
 */
@Override
protected void createContent(Composite parent) {
    Composite page = new Composite(parent, SWT.NONE);
    page.setLayout(new GridLayout(4, false));
    keywordFilter = new Text(page, SWT.SEARCH | SWT.ICON_SEARCH | SWT.BORDER | SWT.ICON_CANCEL);
    keywordFilter.setMessage("Enter search text here...");
    GridDataFactory.fillDefaults().span(2, 1).grab(true, false).applyTo(keywordFilter);
    ownerFilter = new ComboViewer(page);
    GridDataFactory.fillDefaults().grab(false, false).applyTo(ownerFilter.getControl());
    ownerFilter.setContentProvider(new IStructuredContentProvider() {

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

        @Override
        public void dispose() {
        // 
        }

        @Override
        public Object[] getElements(Object inputElement) {
            if (inputElement instanceof List<?>) {
                List<?> elements = (List<?>) inputElement;
                return elements.toArray();
            } else if (inputElement instanceof Object[]) {
                return (Object[]) inputElement;
            }
            return new Object[] {};
        }
    });
    ownerFilter.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof OwnerFilterEntry) {
                return ((OwnerFilterEntry) element).getLabel();
            }
            return super.getText(element);
        }
    });
    List<OwnerFilterEntry> availableFilters = new ArrayList<>();
    availableFilters.add(NULL_FILTER);
    availableFilters.add(new OwnerFilterEntry(new Owner[] { new Owner(OwnerType.USER, haleConnect.getSession().getUserId()) }, "My projects"));
    List<Owner> orgs = new ArrayList<>();
    for (String orgId : haleConnect.getSession().getOrganisationIds()) {
        orgs.add(new Owner(OwnerType.ORGANISATION, orgId));
    }
    if (!orgs.isEmpty()) {
        availableFilters.add(new OwnerFilterEntry(orgs.toArray(new Owner[] {}), "My organisations' projects"));
    }
    ownerFilter.setInput(availableFilters);
    ownerFilter.setSelection(new StructuredSelection(NULL_FILTER));
    Composite tableComposite = new Composite(page, SWT.NONE);
    TableColumnLayout columnLayout = new TableColumnLayout();
    tableComposite.setLayout(columnLayout);
    projects = new TableViewer(tableComposite, SWT.V_SCROLL | SWT.BORDER | SWT.H_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION);
    projects.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            update();
        }
    });
    TableViewerColumn nameColumn = new TableViewerColumn(projects, SWT.LEAD);
    nameColumn.getColumn().setText("Project name");
    nameColumn.setLabelProvider(new ColumnLabelProvider() {

        /**
         * @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
         */
        @Override
        public String getText(Object element) {
            if (element instanceof HaleConnectProjectInfo) {
                return ((HaleConnectProjectInfo) element).getName();
            }
            return element.toString();
        }
    });
    columnLayout.setColumnData(nameColumn.getColumn(), new ColumnWeightData(45, 200, true));
    TableViewerColumn authorColumn = new TableViewerColumn(projects, SWT.LEAD);
    authorColumn.getColumn().setText("Author");
    authorColumn.setLabelProvider(new ColumnLabelProvider() {

        /**
         * @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
         */
        @Override
        public String getText(Object element) {
            if (element instanceof HaleConnectProjectInfo) {
                return ((HaleConnectProjectInfo) element).getAuthor();
            }
            return element.toString();
        }
    });
    columnLayout.setColumnData(authorColumn.getColumn(), new ColumnWeightData(20, 50, true));
    TableViewerColumn ownerColumn = new TableViewerColumn(projects, SWT.LEAD);
    ownerColumn.getColumn().setText("Owner");
    ownerColumn.setLabelProvider(new ColumnLabelProvider() {

        /**
         * @see org.eclipse.jface.viewers.ColumnLabelProvider#getText(java.lang.Object)
         */
        @Override
        public String getText(Object element) {
            if (element instanceof HaleConnectProjectInfo) {
                Owner owner = ((HaleConnectProjectInfo) element).getOwner();
                if (owner.isUser()) {
                    try {
                        HaleConnectUserInfo user = haleConnect.getUserInfo(owner.getId());
                        if (!StringUtils.isEmpty(user.getFullName())) {
                            return user.getFullName();
                        } else if (!StringUtils.isEmpty(user.getScreenName())) {
                            return user.getScreenName();
                        } else {
                            return MessageFormat.format("<user {0}>", user.getUserId());
                        }
                    } catch (HaleConnectException e) {
                        log.error(e.getMessage(), e);
                        return MessageFormat.format("<user {0}>", owner.getId());
                    }
                } else if (owner.isOrganisation()) {
                    try {
                        return haleConnect.getOrganisationInfo(owner.getId()).getName();
                    } catch (HaleConnectException e) {
                        log.error(e.getMessage(), e);
                        return MessageFormat.format("<organisation {0}>", owner.getId());
                    }
                } else {
                    return "<unknown owner type> ID: " + owner.getId();
                }
            }
            return element.toString();
        }
    });
    columnLayout.setColumnData(ownerColumn.getColumn(), new ColumnWeightData(35, 100, true));
    final Table projectsTable = projects.getTable();
    projectsTable.setHeaderVisible(true);
    projectsTable.setLinesVisible(true);
    tableComposite.setLayoutData(GridDataFactory.fillDefaults().span(4, 1).grab(true, true).create());
    projects.setContentProvider(ArrayContentProvider.getInstance());
    populateProjects();
    final ProjectFilter projectFilter = new ProjectFilter(projects);
    projects.addFilter(projectFilter);
    ownerFilter.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            if (event.getSelection() instanceof StructuredSelection) {
                StructuredSelection selection = (StructuredSelection) event.getSelection();
                if (selection.getFirstElement() instanceof OwnerFilterEntry) {
                    OwnerFilterEntry selectedFilter = (OwnerFilterEntry) selection.getFirstElement();
                    if (selectedFilter.equals(NULL_FILTER)) {
                        projectFilter.clearOwnerFilter();
                    } else {
                        projectFilter.filterByOwners(Arrays.asList(selectedFilter.getOwner()));
                    }
                }
            }
        }
    });
    keywordFilter.addModifyListener(new ModifyListener() {

        @Override
        public void modifyText(ModifyEvent e) {
            projectFilter.setSearchText(keywordFilter.getText());
        }
    });
    final Button refresh = new Button(page, SWT.FLAT);
    refresh.setText("Refresh");
    GridDataFactory.fillDefaults().span(1, 1).grab(false, false).applyTo(refresh);
    refresh.addSelectionListener(new SelectionAdapter() {

        /**
         * @see org.eclipse.swt.events.SelectionAdapter#widgetSelected(org.eclipse.swt.events.SelectionEvent)
         */
        @Override
        public void widgetSelected(SelectionEvent e) {
            populateProjects();
        }
    });
    ownerFilter.getControl().setFocus();
    setControl(page);
    update();
}
Also used : ColumnWeightData(org.eclipse.jface.viewers.ColumnWeightData) Owner(eu.esdihumboldt.hale.io.haleconnect.Owner) ModifyListener(org.eclipse.swt.events.ModifyListener) ArrayList(java.util.ArrayList) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) HaleConnectUserInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectUserInfo) TableViewer(org.eclipse.jface.viewers.TableViewer) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) TableColumnLayout(org.eclipse.jface.layout.TableColumnLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Text(org.eclipse.swt.widgets.Text) HaleConnectProjectInfo(eu.esdihumboldt.hale.io.haleconnect.HaleConnectProjectInfo) HaleConnectException(eu.esdihumboldt.hale.io.haleconnect.HaleConnectException) ComboViewer(org.eclipse.jface.viewers.ComboViewer) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) TableViewer(org.eclipse.jface.viewers.TableViewer)

Example 5 with IStructuredContentProvider

use of org.eclipse.jface.viewers.IStructuredContentProvider in project hale by halestudio.

the class RuleStylePage method createControl.

/**
 * @see IDialogPage#createControl(Composite)
 */
@Override
public void createControl(Composite parent) {
    changed = false;
    Composite page = new Composite(parent, SWT.NONE);
    page.setLayout(new GridLayout(2, false));
    // DISABLED - this method seems to change the rule order - Rule[]
    // ruleArray = SLD.rules(getParent().getStyle());
    // use list instead:
    List<Rule> ruleList;
    try {
        ruleList = getParent().getStyle().featureTypeStyles().get(0).rules();
    } catch (Exception e) {
        ruleList = new ArrayList<Rule>();
    }
    // init index
    if (ruleList.size() > 0) {
        currentIndex = 0;
    } else {
        currentIndex = -1;
    }
    currentEditor = null;
    // populate rule map
    rules = new ArrayList<RuleItem>(ruleList.size() + 5);
    for (int i = 0; i < ruleList.size(); i++) {
        Rule rule = ruleList.get(i);
        if (rule != null) {
            rules.add(new RuleItem(rule));
        }
    }
    // rule list
    Composite ruleArea = new Composite(page, SWT.NONE);
    ruleArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true));
    GridLayout leftLayout = new GridLayout(5, true);
    leftLayout.horizontalSpacing = 1;
    leftLayout.verticalSpacing = 1;
    ruleArea.setLayout(leftLayout);
    // label
    Label rulesLabel = new Label(ruleArea, SWT.NONE);
    rulesLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false, 5, 1));
    rulesLabel.setFont(JFaceResources.getFontRegistry().getBold(JFaceResources.DEFAULT_FONT));
    rulesLabel.setText(Messages.RuleStylePage_RuleLabelText);
    // viewer
    listViewer = new ListViewer(ruleArea);
    listViewer.getList().setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 5, 1));
    listViewer.setContentProvider(new IStructuredContentProvider() {

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

        @Override
        public void dispose() {
        // ignore
        }

        @SuppressWarnings("unchecked")
        @Override
        public Object[] getElements(Object inputElement) {
            try {
                List<RuleItem> rules = (List<RuleItem>) inputElement;
                return rules.toArray();
            } catch (Exception e) {
                return null;
            }
        }
    });
    listViewer.setInput(rules);
    if (currentIndex >= 0 && currentIndex < rules.size()) {
        listViewer.setSelection(new StructuredSelection(rules.get(currentIndex)));
    }
    listViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            RuleItem item = (RuleItem) ((IStructuredSelection) event.getSelection()).getFirstElement();
            int newIndex = rules.indexOf(item);
            if (currentIndex != newIndex) {
                try {
                    updateCurrentRule();
                } catch (Exception e) {
                    log.userError("Invalid editor state, could not update rule.", e);
                    return;
                }
                currentIndex = newIndex;
                updateEditor();
            }
        }
    });
    // buttons
    addButton = new Button(ruleArea, SWT.PUSH);
    addButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    addButton.setImage(addImage);
    addButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            addRule();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // ignore
        }
    });
    addButton.setToolTipText(Messages.RuleStylePage_AddRuleButtonToolTippText);
    removeButton = new Button(ruleArea, SWT.PUSH);
    removeButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    removeButton.setImage(removeImage);
    removeButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            removeCurrentRule();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // ignore
        }
    });
    removeButton.setToolTipText(Messages.RuleStylePage_RemoveRuleButtonToolTippText);
    upButton = new Button(ruleArea, SWT.PUSH);
    upButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    upButton.setImage(upImage);
    upButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveCurrentRuleUp();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // ignore
        }
    });
    upButton.setToolTipText(Messages.RuleStylePage_UpRuleButtonToolTippText);
    downButton = new Button(ruleArea, SWT.PUSH);
    downButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    downButton.setImage(downImage);
    downButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            moveCurrentRuleDown();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // ignore
        }
    });
    downButton.setToolTipText(Messages.RuleStylePage_DownRuleButtonToolTippText);
    renameButton = new Button(ruleArea, SWT.PUSH);
    renameButton.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    renameButton.setImage(renameImage);
    renameButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            renameCurrentRule();
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // ignore
        }
    });
    renameButton.setToolTipText(Messages.RuleStylePage_RenameRuleButtonToolTippText);
    // editor area
    editorArea = new Composite(page, SWT.NONE);
    editorArea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    editorArea.setLayout(new FillLayout());
    setControl(page);
    updateEditor();
}
Also used : ArrayList(java.util.ArrayList) Label(org.eclipse.swt.widgets.Label) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ListViewer(org.eclipse.jface.viewers.ListViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ArrayList(java.util.ArrayList) List(java.util.List) ListViewer(org.eclipse.jface.viewers.ListViewer) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) FillLayout(org.eclipse.swt.layout.FillLayout) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) Rule(org.geotools.styling.Rule) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)89 Viewer (org.eclipse.jface.viewers.Viewer)69 Composite (org.eclipse.swt.widgets.Composite)52 GridData (org.eclipse.swt.layout.GridData)49 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)40 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)39 TableViewer (org.eclipse.jface.viewers.TableViewer)37 GridLayout (org.eclipse.swt.layout.GridLayout)37 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)36 Label (org.eclipse.swt.widgets.Label)29 LabelProvider (org.eclipse.jface.viewers.LabelProvider)26 Button (org.eclipse.swt.widgets.Button)26 SelectionEvent (org.eclipse.swt.events.SelectionEvent)25 Image (org.eclipse.swt.graphics.Image)25 ArrayList (java.util.ArrayList)23 Table (org.eclipse.swt.widgets.Table)23 ComboViewer (org.eclipse.jface.viewers.ComboViewer)19 ILabelProviderListener (org.eclipse.jface.viewers.ILabelProviderListener)18 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)17 Text (org.eclipse.swt.widgets.Text)17