Search in sources :

Example 1 with FileSelectWidget

use of com.amalto.workbench.widgets.FileSelectWidget in project tmdm-studio-se by Talend.

the class MenuEntryDialog method createDialogArea.

@Override
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;
    Label idLabel = new Label(composite, SWT.NONE);
    idLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    idLabel.setText(Messages.MenuEntryDialog_Id);
    if (this.isChanged) {
        idText = new Text(composite, SWT.NONE);
    } else {
        idText = new Text(composite, SWT.NONE | SWT.READ_ONLY);
    }
    idText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    ((GridData) idText.getLayoutData()).widthHint = 300;
    idText.setDoubleClickEnabled(false);
    Label contextLabel = new Label(composite, SWT.NONE);
    contextLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    contextLabel.setText(Messages.MenuEntryDialog_Context);
    contextText = new Text(composite, SWT.NONE);
    contextText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    contextText.setDoubleClickEnabled(false);
    Label applicationNameLabel = new Label(composite, SWT.NONE);
    applicationNameLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    applicationNameLabel.setText(Messages.MenuEntryDialog_Application);
    applicationNameText = new Text(composite, SWT.NONE);
    applicationNameText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
    Label iconPathLabel = new Label(composite, SWT.NONE);
    iconPathLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    iconPathLabel.setText(Messages.MenuEntryDialog_IconPath);
    // $NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ //$NON-NLS-5$
    iconPathText = new FileSelectWidget(composite, "", new String[] { "*.png", "*.gif", "*.jpg" }, "", true);
    // Labels
    descriptionsComposite = new Composite(composite, SWT.BORDER);
    descriptionsComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
    descriptionsComposite.setLayout(new GridLayout(3, false));
    Label descriptionsLabel = new Label(descriptionsComposite, SWT.NULL);
    descriptionsLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 1));
    descriptionsLabel.setText(Messages.MenuEntryDialog_MenuEntryLabels);
    languagesCombo = new Combo(descriptionsComposite, 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 (Object element : languages) {
        String language = (String) element;
        languagesCombo.add(language);
    }
    languagesCombo.addModifyListener(new ModifyListener() {

        public void modifyText(ModifyEvent e) {
        }
    });
    languagesCombo.select(0);
    labelText = new Text(descriptionsComposite, SWT.BORDER | SWT.SINGLE);
    labelText.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
    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(descriptionsComposite, 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.MenuEntryDialog_Add);
    addLabelButton.addSelectionListener(new SelectionListener() {

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

        public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            String isoCode = Util.lang2iso.get(languagesCombo.getText());
            descriptionsMap.put(isoCode, labelText.getText());
            descriptionsViewer.refresh();
        }
    });
    final String LANGUAGE = Messages.MenuEntryDialog_Language;
    final String LABEL = Messages.MenuEntryDialog_Label;
    descriptionsViewer = new TableViewer(descriptionsComposite, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.FULL_SELECTION);
    descriptionsViewer.getControl().setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 3, 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);
    // Create the cell editors --> We actually discard those later: not natural for an user
    CellEditor[] editors = new CellEditor[2];
    editors[0] = new TextCellEditor(table);
    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 (Object element : languages) {
                String language = (String) element;
                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 false;
        }

        public void modify(Object element, String property, Object value) {
        // System.out.println("modify() "+element.getClass().getName()+": "+property+": "+value);
        // DescriptionLine line =
        // (DescriptionLine)((IStructuredSelection)instancesViewer.getSelection()).getFirstElement();
        // deactivated: editing in places is not natural for users
        }

        public Object getValue(Object element, String property) {
            // System.out.println("getValue() "+property);
            DescriptionLine line = (DescriptionLine) element;
            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)) {
                DescriptionLine line = (DescriptionLine) ((IStructuredSelection) descriptionsViewer.getSelection()).getFirstElement();
                String isoCode = Util.lang2iso.get(line.getLanguage());
                LinkedHashMap<String, String> descs = (LinkedHashMap<String, String>) descriptionsViewer.getInput();
                descs.remove(isoCode);
                descriptionsViewer.refresh();
            }
        }
    });
    descriptionsViewer.refresh();
    if (wsMenuEntry != null) {
        // $NON-NLS-1$
        idText.setText(wsMenuEntry.getId() == null ? "" : wsMenuEntry.getId());
        // $NON-NLS-1$
        contextText.setText(wsMenuEntry.getContext() == null ? "" : wsMenuEntry.getContext());
        // $NON-NLS-1$
        applicationNameText.setText(wsMenuEntry.getApplication() == null ? "" : wsMenuEntry.getApplication());
        // $NON-NLS-1$
        iconPathText.setFilename(wsMenuEntry.getIcon() == null ? "" : wsMenuEntry.getIcon());
        descriptionsViewer.setInput(descriptionsMap);
    }
    idText.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) Label(org.eclipse.swt.widgets.Label) 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) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) 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) ICellModifier(org.eclipse.jface.viewers.ICellModifier) FileSelectWidget(com.amalto.workbench.widgets.FileSelectWidget) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) 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) TreeObject(com.amalto.workbench.models.TreeObject) KeyListener(org.eclipse.swt.events.KeyListener) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

EImage (com.amalto.workbench.image.EImage)1 TreeObject (com.amalto.workbench.models.TreeObject)1 FileSelectWidget (com.amalto.workbench.widgets.FileSelectWidget)1 ArrayList (java.util.ArrayList)1 LinkedHashMap (java.util.LinkedHashMap)1 Set (java.util.Set)1 CellEditor (org.eclipse.jface.viewers.CellEditor)1 ICellModifier (org.eclipse.jface.viewers.ICellModifier)1 ILabelProviderListener (org.eclipse.jface.viewers.ILabelProviderListener)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 ITableLabelProvider (org.eclipse.jface.viewers.ITableLabelProvider)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 TableViewer (org.eclipse.jface.viewers.TableViewer)1 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)1 Viewer (org.eclipse.jface.viewers.Viewer)1 KeyEvent (org.eclipse.swt.events.KeyEvent)1 KeyListener (org.eclipse.swt.events.KeyListener)1 ModifyEvent (org.eclipse.swt.events.ModifyEvent)1