Search in sources :

Example 21 with IStructuredContentProvider

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

the class MDMXSDSchemaEntryDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    parent.getShell().setText(this.title);
    Composite composite = (Composite) super.createDialogArea(parent);
    GridLayout layout = (GridLayout) composite.getLayout();
    layout.numColumns = 1;
    wcListViewer = new ListViewer(composite, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
    wcListViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    ((GridData) wcListViewer.getControl().getLayoutData()).minimumHeight = 200;
    wcListViewer.setContentProvider(new IStructuredContentProvider() {

        public void dispose() {
        }

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

        public Object[] getElements(Object inputElement) {
            return ((ArrayList) inputElement).toArray(new String[] {});
        }
    });
    wcListViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            importedUrls.clear();
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            Iterator iter = selection.iterator();
            while (iter.hasNext()) {
                String url = (String) iter.next();
                importedUrls.add(url);
            }
            getButton(IDialogConstants.OK_ID).setEnabled(!selection.isEmpty());
        }
    });
    wcListViewer.setLabelProvider(new ILabelProvider() {

        public void addListener(ILabelProviderListener listener) {
        }

        public void dispose() {
        }

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

        public void removeListener(ILabelProviderListener listener) {
        }

        public Image getImage(Object element) {
            return null;
        }

        public String getText(Object element) {
            return element.toString();
        }
    });
    wcListViewer.setSorter(new ViewerSorter());
    wcListViewer.setInput(urls);
    return composite;
}
Also used : ListViewer(org.eclipse.jface.viewers.ListViewer) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) Viewer(org.eclipse.jface.viewers.Viewer) ListViewer(org.eclipse.jface.viewers.ListViewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ILabelProvider(org.eclipse.jface.viewers.ILabelProvider) Image(org.eclipse.swt.graphics.Image) GridLayout(org.eclipse.swt.layout.GridLayout) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) Iterator(java.util.Iterator)

Example 22 with IStructuredContentProvider

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

the class AnnotationLanguageLabelsDialog method createDialogArea.

protected Control createDialogArea(Composite parent) {
    // Should not really be here but well,....
    parent.getShell().setText(this.title);
    Composite composite = (Composite) super.createDialogArea(parent);
    GridLayout layout = (GridLayout) composite.getLayout();
    layout.numColumns = 3;
    // layout.verticalSpacing = 10;
    languagesCombo = new Combo(composite, SWT.READ_ONLY | SWT.DROP_DOWN | SWT.SINGLE);
    languagesCombo.setLayoutData(new GridData(SWT.BEGINNING, SWT.NONE, false, false, 1, 1));
    Set<String> languages = Util.lang2iso.keySet();
    for (Iterator iter = languages.iterator(); iter.hasNext(); ) {
        String language = (String) iter.next();
        languagesCombo.add(language);
    }
    languagesCombo.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
        }
    });
    languagesCombo.select(0);
    labelText = new Text(composite, SWT.BORDER | SWT.SINGLE);
    labelText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    ((GridData) labelText.getLayoutData()).minimumWidth = 150;
    labelText.addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
        }

        public void keyReleased(KeyEvent e) {
            if ((e.stateMask == 0) && (e.character == SWT.CR)) {
                String isoCode = Util.lang2iso.get(languagesCombo.getText());
                descriptionsMap.put(isoCode, labelText.getText());
                descriptionsViewer.refresh();
            }
        }
    });
    Button addLabelButton = new Button(composite, SWT.PUSH);
    addLabelButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, true, 1, 1));
    addLabelButton.setImage(ImageCache.getCreatedImage(EImage.ADD_OBJ.getPath()));
    addLabelButton.setToolTipText(Messages.AnnotationLanguageLabelsDialog_Add);
    addLabelButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
        }

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            String code = Util.lang2iso.get(languagesCombo.getText());
            descriptionsMap.put(code, labelText.getText());
            descriptionsViewer.refresh();
        }
    });
    final String LANGUAGE = Messages.AnnotationLanguageLabelsDialog_Language;
    final String LABEL = Messages.AnnotationLanguageLabelsDialog_Label;
    descriptionsViewer = new TableViewer(composite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    descriptionsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    ((GridData) descriptionsViewer.getControl().getLayoutData()).heightHint = 100;
    // Set up the underlying table
    Table table = descriptionsViewer.getTable();
    // table.setLayoutData(new GridData(GridData.FILL_BOTH));
    new TableColumn(table, SWT.LEFT).setText(LANGUAGE);
    new TableColumn(table, SWT.CENTER).setText(LABEL);
    table.getColumn(0).setWidth(150);
    table.getColumn(1).setWidth(150);
    for (int i = 2, n = table.getColumnCount(); i < n; i++) {
        table.getColumn(i).pack();
    }
    table.setHeaderVisible(true);
    table.setLinesVisible(true);
    Button delLabelButton = new Button(composite, SWT.PUSH);
    delLabelButton.setLayoutData(new GridData(SWT.NONE, SWT.NONE, false, false, 1, 1));
    delLabelButton.setImage(ImageCache.getCreatedImage(EImage.DELETE_OBJ.getPath()));
    delLabelButton.setToolTipText(Messages.AnnotationLanguageLabelsDialog_Del);
    delLabelButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(org.eclipse.swt.events.SelectionEvent e) {
        }

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            deleteItem();
        }
    });
    // Create the cell editors --> We actually discard those later: not natural for an user
    CellEditor[] editors = new CellEditor[2];
    editors[0] = new ComboBoxCellEditor(table, Util.lang2iso.keySet().toArray(new String[] {}), SWT.READ_ONLY);
    editors[1] = new TextCellEditor(table);
    descriptionsViewer.setCellEditors(editors);
    // set the content provider
    descriptionsViewer.setContentProvider(new IStructuredContentProvider() {

        public void dispose() {
        }

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

        public Object[] getElements(Object inputElement) {
            // System.out.println("getElements() ");
            LinkedHashMap<String, String> descs = (LinkedHashMap<String, String>) inputElement;
            Set<String> languages = descs.keySet();
            ArrayList<DescriptionLine> lines = new ArrayList<DescriptionLine>();
            for (Iterator iter = languages.iterator(); iter.hasNext(); ) {
                String language = ((String) iter.next());
                DescriptionLine line = new DescriptionLine(Util.iso2lang.get(language), descs.get(language));
                lines.add(line);
            }
            // we return an instance line made of a Sring and a boolean
            return lines.toArray(new DescriptionLine[lines.size()]);
        }
    });
    // set the label provider
    descriptionsViewer.setLabelProvider(new ITableLabelProvider() {

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

        public void dispose() {
        }

        public void addListener(ILabelProviderListener listener) {
        }

        public void removeListener(ILabelProviderListener listener) {
        }

        public String getColumnText(Object element, int columnIndex) {
            // System.out.println("getColumnText() "+columnIndex);
            DescriptionLine line = (DescriptionLine) element;
            switch(columnIndex) {
                case 0:
                    return line.getLanguage();
                case 1:
                    return line.getLabel();
            }
            // $NON-NLS-1$
            return "";
        }

        public Image getColumnImage(Object element, int columnIndex) {
            return null;
        }
    });
    // Set the column properties
    descriptionsViewer.setColumnProperties(new String[] { LANGUAGE, LABEL });
    // set the Cell Modifier
    descriptionsViewer.setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            // if (INSTANCE_ACCESS.equals(property)) return true; Deactivated
            return true;
        }

        public void modify(Object element, String property, Object value) {
            TableItem item = (TableItem) element;
            int columnIndex = Arrays.asList(descriptionsViewer.getColumnProperties()).indexOf(property);
            DescriptionLine line = (DescriptionLine) item.getData();
            if (columnIndex == 0) {
                String[] attrs = Util.lang2iso.keySet().toArray(new String[] {});
                int orgIndx = Arrays.asList(attrs).indexOf(line.getLanguage());
                if (orgIndx != Integer.parseInt(value.toString())) {
                    String newLang = attrs[Integer.parseInt(value.toString())];
                    if (descriptionsMap.containsKey(Util.lang2iso.get(newLang))) {
                        MessageDialog.openInformation(null, Messages.Warnning, Messages.AnnotationLanguageLabelsDialog_InforContent);
                        return;
                    }
                    descriptionsMap.remove(Util.lang2iso.get(line.getLanguage()));
                    line.setLanguage(newLang);
                    descriptionsMap.put(Util.lang2iso.get(newLang), line.getLabel());
                }
            } else // column label
            {
                line.setLabel(value.toString());
                descriptionsMap.put(Util.lang2iso.get(line.getLanguage()), line.getLabel());
            }
            descriptionsViewer.update(line, null);
        }

        public Object getValue(Object element, String property) {
            int columnIndex = Arrays.asList(descriptionsViewer.getColumnProperties()).indexOf(property);
            DescriptionLine line = (DescriptionLine) element;
            if (columnIndex == 0) {
                String[] attrs = Util.lang2iso.keySet().toArray(new String[] {});
                return Arrays.asList(attrs).indexOf(line.getLanguage());
            } else {
                if (LANGUAGE.equals(property)) {
                    return line.getLanguage();
                }
                if (LABEL.equals(property)) {
                    return line.getLabel();
                }
            }
            return null;
        }
    });
    // Listen for changes in the selection of the viewer to display additional parameters
    descriptionsViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
        }
    });
    // display for Delete Key events to delete an instance
    descriptionsViewer.getTable().addKeyListener(new KeyListener() {

        public void keyPressed(KeyEvent e) {
        }

        public void keyReleased(KeyEvent e) {
            // System.out.println("Table keyReleased() ");
            if ((e.stateMask == 0) && (e.character == SWT.DEL) && (descriptionsViewer.getSelection() != null)) {
                deleteItem();
            }
        }
    });
    descriptionsViewer.setInput(descriptionsMap);
    descriptionsViewer.refresh();
    labelText.setFocus();
    return composite;
}
Also used : Set(java.util.Set) ModifyListener(org.eclipse.swt.events.ModifyListener) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) TableItem(org.eclipse.swt.widgets.TableItem) ArrayList(java.util.ArrayList) Combo(org.eclipse.swt.widgets.Combo) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Image(org.eclipse.swt.graphics.Image) EImage(com.amalto.workbench.image.EImage) LinkedHashMap(java.util.LinkedHashMap) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) ModifyEvent(org.eclipse.swt.events.ModifyEvent) ITableLabelProvider(org.eclipse.jface.viewers.ITableLabelProvider) Button(org.eclipse.swt.widgets.Button) Iterator(java.util.Iterator) ICellModifier(org.eclipse.jface.viewers.ICellModifier) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ComboBoxCellEditor(org.eclipse.jface.viewers.ComboBoxCellEditor) Text(org.eclipse.swt.widgets.Text) TableColumn(org.eclipse.swt.widgets.TableColumn) ILabelProviderListener(org.eclipse.jface.viewers.ILabelProviderListener) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) KeyListener(org.eclipse.swt.events.KeyListener) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 23 with IStructuredContentProvider

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

the class ComplexTypeWrapper method changeTypeName.

public boolean changeTypeName() {
    if (curXSDComplexType.getName().equals(newTypeName))
        return false;
    curXSDComplexType.setName(newTypeName);
    curXSDComplexType.updateElement();
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorPart activeEditor = activePage.getActiveEditor();
    if (activeEditor instanceof XSDEditor) {
        XSDEditor editor = (XSDEditor) activeEditor;
        DataModelMainPage page = editor.getdMainPage();
        IStructuredContentProvider provider = (IStructuredContentProvider) page.getSchemaContentProvider();
        Util.updateReferenceToXSDTypeDefinition(page.getSite(), curXSDComplexType, provider);
    }
    return true;
}
Also used : XSDEditor(com.amalto.workbench.editors.xsdeditor.XSDEditor) DataModelMainPage(com.amalto.workbench.editors.DataModelMainPage) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart)

Example 24 with IStructuredContentProvider

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

the class SimpleTypeWrapper method changeTypeName.

public boolean changeTypeName() {
    if (getNewTypeName().trim().equals(getOldTypeName()))
        return false;
    xsdSimpleType.setName(getNewTypeName().trim());
    xsdSimpleType.updateElement();
    IWorkbenchPage activePage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IEditorPart activeEditor = activePage.getActiveEditor();
    if (activeEditor instanceof XSDEditor) {
        XSDEditor editor = (XSDEditor) activeEditor;
        DataModelMainPage page = editor.getdMainPage();
        IStructuredContentProvider provider = (IStructuredContentProvider) page.getSchemaContentProvider();
        Util.updateReferenceToXSDTypeDefinition(page.getSite(), xsdSimpleType, provider);
    }
    return true;
}
Also used : XSDEditor(com.amalto.workbench.editors.xsdeditor.XSDEditor) DataModelMainPage(com.amalto.workbench.editors.DataModelMainPage) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IEditorPart(org.eclipse.ui.IEditorPart)

Example 25 with IStructuredContentProvider

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

the class XSDDeleteElementAction method doAction.

public IStatus doAction() {
    try {
        // xsdElem is to support the multiple delete action on key press,
        // which each delete action on element must be explicit passed a xsdElem to
        // delete
        XSDElementDeclaration decl = xsdElem;
        if (decl == null) {
            ISelection selection = page.getTreeViewer().getSelection();
            decl = (XSDElementDeclaration) ((IStructuredSelection) selection).getFirstElement();
        }
        ArrayList<Object> objList = new ArrayList<Object>();
        IStructuredContentProvider provider = (IStructuredContentProvider) page.getTreeViewer().getContentProvider();
        Object[] all = Util.getAllObject(page.getSite(), objList, provider);
        Util.deleteReference(decl, all);
        // remove declaration
        schema.getContents().remove(decl);
        schema.update();
        xsdElem = null;
        page.refresh();
        page.markDirtyWithoutCommit();
    } catch (Exception e) {
        log.error(e.getMessage(), e);
        MessageDialog.openError(page.getSite().getShell(), Messages._Error, Messages.bind(Messages.XSDDeleteElementAction_ErrorMsg, e.getLocalizedMessage()));
        return Status.CANCEL_STATUS;
    }
    return Status.OK_STATUS;
}
Also used : XSDElementDeclaration(org.eclipse.xsd.XSDElementDeclaration) ISelection(org.eclipse.jface.viewers.ISelection) ArrayList(java.util.ArrayList) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

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