Search in sources :

Example 1 with IAttribute

use of org.eclipse.wst.xsl.jaxp.launching.IAttribute in project webtools.sourceediting by eclipse.

the class AttributeDialog method createDialogArea.

@Override
protected Control createDialogArea(Composite parent) {
    Composite comp = new Composite(parent, SWT.NONE);
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.widthHint = 400;
    comp.setLayoutData(gd);
    comp.setLayout(new GridLayout());
    Label label = new Label(comp, SWT.NONE);
    // $NON-NLS-1$
    label.setText(Messages.getString("AttributeDialog_1"));
    table = new Table(comp, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.MULTI);
    table.setHeaderVisible(false);
    gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    gd.verticalIndent = 10;
    gd.heightHint = 200;
    table.setLayoutData(gd);
    tViewer = new TableViewer(table);
    tViewer.setContentProvider(new IStructuredContentProvider() {

        public Object[] getElements(Object inputElement) {
            return attributes.toArray(new IAttribute[0]);
        }

        public void dispose() {
        }

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

        @Override
        public String getText(Object element) {
            IAttribute attribute = (IAttribute) element;
            return attribute.getURI();
        }
    });
    tViewer.setSorter(new ViewerSorter() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            IAttribute a1 = (IAttribute) e1;
            IAttribute a2 = (IAttribute) e2;
            return a1.getURI().compareTo(a2.getURI());
        }
    });
    tViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            IStructuredSelection sel = (IStructuredSelection) event.getSelection();
            selectedAttributes = sel.toList();
            if (sel.isEmpty())
                // $NON-NLS-1$
                text.setText(Messages.getString("AttributeDialog_2"));
            else {
                IAttribute attribute = (IAttribute) sel.getFirstElement();
                text.setText(attribute.getDescription());
            }
        }
    });
    tViewer.addDoubleClickListener(new IDoubleClickListener() {

        public void doubleClick(DoubleClickEvent event) {
            buttonPressed(IDialogConstants.OK_ID);
        }
    });
    tViewer.setInput(attributes);
    text = new Text(comp, SWT.BORDER | SWT.WRAP | SWT.READ_ONLY | SWT.V_SCROLL);
    text.setEditable(false);
    gd = new GridData(SWT.FILL, SWT.FILL, true, false);
    gd.heightHint = 80;
    text.setLayoutData(gd);
    if (attributes.size() > 0) {
        tViewer.setSelection(new StructuredSelection(tViewer.getElementAt(0)), true);
    }
    return comp;
}
Also used : Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) DoubleClickEvent(org.eclipse.jface.viewers.DoubleClickEvent) Text(org.eclipse.swt.widgets.Text) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) IDoubleClickListener(org.eclipse.jface.viewers.IDoubleClickListener) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) IAttribute(org.eclipse.wst.xsl.jaxp.launching.IAttribute) TableViewer(org.eclipse.jface.viewers.TableViewer) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Example 2 with IAttribute

use of org.eclipse.wst.xsl.jaxp.launching.IAttribute in project webtools.sourceediting by eclipse.

the class AttributesBlock method createControl.

public void createControl(Composite parent) {
    TabItem item = new TabItem((TabFolder) parent, SWT.NONE);
    // $NON-NLS-1$
    item.setText(Messages.getString("AttributesBlock.0"));
    Composite composite = new Composite(parent, SWT.NONE);
    GridLayout layout = new GridLayout(2, false);
    layout.marginBottom = 0;
    layout.marginWidth = 0;
    composite.setLayout(layout);
    item.setControl(composite);
    table = new Table(composite, SWT.BORDER | SWT.FULL_SELECTION | SWT.V_SCROLL | SWT.MULTI);
    table.setHeaderVisible(true);
    table.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    table.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if (event.character == SWT.DEL && event.stateMask == 0) {
                performRemove();
            }
        }
    });
    TableColumn tc1 = new TableColumn(table, SWT.NONE);
    // $NON-NLS-1$
    tc1.setText(Messages.getString("AttributesBlock.2"));
    tc1.setWidth(350);
    tc1.setResizable(true);
    TableColumn tc2 = new TableColumn(table, SWT.NONE);
    // $NON-NLS-1$
    tc2.setText(Messages.getString("AttributesBlock.7"));
    tc2.setWidth(50);
    tc2.setResizable(true);
    Composite buttonComp = new Composite(composite, SWT.FILL);
    buttonComp.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    GridLayout gl = new GridLayout();
    gl.marginWidth = 0;
    buttonComp.setLayout(gl);
    Button addButton = new Button(buttonComp, SWT.PUSH);
    // $NON-NLS-1$
    addButton.setText(Messages.getString("AttributesBlock.8"));
    addButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    addButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            AttributeDialog dialog = new AttributeDialog(getShell(), attributes);
            if (dialog.open() == Window.OK) {
                List<IAttribute> newAttributes = dialog.getAttributes();
                LaunchAttribute first = null;
                for (IAttribute attribute : newAttributes) {
                    // $NON-NLS-1$
                    LaunchAttribute att = new LaunchAttribute(attribute.getURI(), "string", null);
                    if (first == null)
                        first = att;
                    attributes.addAttribute(att);
                }
                if (newAttributes.size() > 0) {
                    tViewer.refresh();
                    tViewer.setSelection(new StructuredSelection(first), true);
                    tViewer.editElement(first, 1);
                    updateLaunchConfigurationDialog();
                }
            }
        }
    });
    removeButton = new Button(buttonComp, SWT.PUSH);
    // $NON-NLS-1$
    removeButton.setText(Messages.getString("AttributesBlock.14"));
    removeButton.setLayoutData(new GridData(SWT.FILL, SWT.TOP, false, false));
    removeButton.addSelectionListener(new SelectionListener() {

        public void widgetDefaultSelected(SelectionEvent e) {
        }

        public void widgetSelected(SelectionEvent e) {
            performRemove();
        }
    });
    setControl(table);
    tViewer = new TableViewer(table);
    tViewer.setContentProvider(new IStructuredContentProvider() {

        public Object[] getElements(Object inputElement) {
            return attributes.getAttributes().toArray(new LaunchAttribute[0]);
        }

        public void dispose() {
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
            attributes = (LaunchAttributes) newInput;
        }
    });
    tViewer.setSorter(new ViewerSorter() {

        @Override
        public int compare(Viewer viewer, Object e1, Object e2) {
            LaunchAttribute a1 = (LaunchAttribute) e1;
            LaunchAttribute a2 = (LaunchAttribute) e2;
            return a1.uri.compareTo(a2.uri);
        }
    });
    tViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            updateRemoveButton();
        }
    });
    TableViewerColumn tvc1 = new TableViewerColumn(tViewer, tc1);
    tvc1.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            LaunchAttribute tv = (LaunchAttribute) cell.getElement();
            cell.setText(tv.uri);
        }

        @Override
        public int getToolTipTimeDisplayed(Object object) {
            return 5000;
        }

        @Override
        public String getToolTipText(Object element) {
            LaunchAttribute tv = (LaunchAttribute) element;
            return attributeUris.get(tv.uri).getDescription();
        }
    });
    // ColumnViewerToolTipSupport.enableFor(tViewer);
    TableViewerColumn tvc2 = new TableViewerColumn(tViewer, tc2);
    tvc2.setLabelProvider(new CellLabelProvider() {

        @Override
        public void update(ViewerCell cell) {
            LaunchAttribute tv = (LaunchAttribute) cell.getElement();
            cell.setText(tv.value);
        }
    });
    tvc2.setEditingSupport(new EditingSupport(tViewer) {

        @Override
        protected boolean canEdit(Object element) {
            return true;
        }

        @Override
        protected CellEditor getCellEditor(Object element) {
            return new TextCellEditor(table);
        }

        @Override
        protected Object getValue(Object element) {
            LaunchAttribute tv = (LaunchAttribute) element;
            // $NON-NLS-1$
            return tv.value == null ? "" : tv.value;
        }

        @Override
        protected void setValue(Object element, Object value) {
            LaunchAttribute tv = (LaunchAttribute) element;
            tv.setValue((String) value);
            updateLaunchConfigurationDialog();
            tViewer.update(tv, null);
        }
    });
    restoreColumnSettings();
}
Also used : CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) KeyAdapter(org.eclipse.swt.events.KeyAdapter) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) ViewerSorter(org.eclipse.jface.viewers.ViewerSorter) EditingSupport(org.eclipse.jface.viewers.EditingSupport) TableViewer(org.eclipse.jface.viewers.TableViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) KeyEvent(org.eclipse.swt.events.KeyEvent) GridLayout(org.eclipse.swt.layout.GridLayout) Button(org.eclipse.swt.widgets.Button) SelectionEvent(org.eclipse.swt.events.SelectionEvent) List(java.util.List) TableViewerColumn(org.eclipse.jface.viewers.TableViewerColumn) CellLabelProvider(org.eclipse.jface.viewers.CellLabelProvider) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TableColumn(org.eclipse.swt.widgets.TableColumn) LaunchAttribute(org.eclipse.wst.xsl.launching.config.LaunchAttribute) ViewerCell(org.eclipse.jface.viewers.ViewerCell) TabItem(org.eclipse.swt.widgets.TabItem) GridData(org.eclipse.swt.layout.GridData) IAttribute(org.eclipse.wst.xsl.jaxp.launching.IAttribute) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) LaunchAttributes(org.eclipse.wst.xsl.jaxp.launching.LaunchAttributes) TableViewer(org.eclipse.jface.viewers.TableViewer) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 3 with IAttribute

use of org.eclipse.wst.xsl.jaxp.launching.IAttribute in project webtools.sourceediting by eclipse.

the class ProcessorType method loadAttributes.

private IAttribute[] loadAttributes() {
    BufferedInputStream is = null;
    List<Attribute> attributesList = new ArrayList<Attribute>();
    try {
        is = new BufferedInputStream(attributePropertiesURL.openStream());
        Properties props = new Properties();
        props.load(is);
        for (Object element : props.keySet()) {
            String key = (String) element;
            if (!key.endsWith(DESC_SUFFIX) && !key.endsWith(TYPE_SUFFIX)) {
                String uri = props.getProperty(key);
                String type = props.getProperty(key + TYPE_SUFFIX);
                String desc = props.getProperty(key + DESC_SUFFIX);
                if (uri != null && type != null && desc != null) {
                    Attribute attribute = new Attribute(uri.trim(), type.trim(), desc);
                    attributesList.add(attribute);
                } else {
                    JAXPLaunchingPlugin.log(new CoreException(new Status(IStatus.WARNING, JAXPLaunchingPlugin.PLUGIN_ID, Messages.ProcessorType_4 + attributePropertiesURL + Messages.ProcessorType_5 + key)));
                }
            }
        }
    } catch (IOException e) {
        JAXPLaunchingPlugin.log(e);
    } finally {
        if (is != null) {
            try {
                is.close();
            } catch (IOException e) {
                JAXPLaunchingPlugin.log(e);
            }
        }
    }
    IAttribute[] attributes = attributesList.toArray(new IAttribute[0]);
    Arrays.sort(attributes);
    return attributes;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException) BufferedInputStream(java.io.BufferedInputStream) IAttribute(org.eclipse.wst.xsl.jaxp.launching.IAttribute) ArrayList(java.util.ArrayList) IAttribute(org.eclipse.wst.xsl.jaxp.launching.IAttribute) IOException(java.io.IOException) Properties(java.util.Properties)

Aggregations

IAttribute (org.eclipse.wst.xsl.jaxp.launching.IAttribute)3 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)2 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)2 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)2 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 TableViewer (org.eclipse.jface.viewers.TableViewer)2 Viewer (org.eclipse.jface.viewers.Viewer)2 ViewerSorter (org.eclipse.jface.viewers.ViewerSorter)2 GridData (org.eclipse.swt.layout.GridData)2 GridLayout (org.eclipse.swt.layout.GridLayout)2 Composite (org.eclipse.swt.widgets.Composite)2 Table (org.eclipse.swt.widgets.Table)2 BufferedInputStream (java.io.BufferedInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Properties (java.util.Properties)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1