Search in sources :

Example 6 with LaunchAttribute

use of org.eclipse.wst.xsl.launching.config.LaunchAttribute in project webtools.sourceediting by eclipse.

the class ParametersContentProvider method removeParameters.

public void removeParameters(LaunchAttribute[] entries) {
    for (LaunchAttribute parameter : entries) {
        stylesheetEntry.getParameters().remove(parameter);
    }
    TableItem[] items = parameterViewer.getTable().getItems();
    List<LaunchAttribute> entryList = Arrays.asList(entries);
    Object sel = null;
    for (int i = items.length - 1; i >= 0; i--) {
        TableItem item = items[i];
        if (!entryList.contains(item.getData())) {
            sel = item.getData();
            break;
        }
    }
    parameterViewer.remove(entries);
    if (sel != null)
        parameterViewer.setSelection(new StructuredSelection(sel), true);
}
Also used : TableItem(org.eclipse.swt.widgets.TableItem) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) LaunchAttribute(org.eclipse.wst.xsl.launching.config.LaunchAttribute)

Example 7 with LaunchAttribute

use of org.eclipse.wst.xsl.launching.config.LaunchAttribute in project webtools.sourceediting by eclipse.

the class ParametersBlock method createControl.

public void createControl(Composite parent) {
    Font font = parent.getFont();
    Group group = new Group(parent, SWT.NONE);
    group.setText(getName());
    GridData gd = new GridData(SWT.FILL, SWT.FILL, true, true);
    group.setLayoutData(gd);
    GridLayout layout = new GridLayout();
    layout.numColumns = 3;
    group.setLayout(layout);
    group.setFont(font);
    setControl(group);
    fTable = new Table(group, SWT.BORDER | SWT.MULTI | SWT.FULL_SELECTION);
    GridData data = new GridData(SWT.FILL, SWT.FILL, true, true);
    // data.heightHint = 100;
    fTable.setLayoutData(data);
    fTable.setFont(font);
    fTable.setHeaderVisible(true);
    fTable.setLinesVisible(true);
    TableColumn column1 = new TableColumn(fTable, SWT.NONE);
    column1.setWidth(150);
    column1.setResizable(true);
    column1.setText(Messages.ParametersBlock_0);
    TableColumn column3 = new TableColumn(fTable, SWT.NONE);
    column3.setWidth(250);
    column3.setResizable(true);
    column3.setText(Messages.ParametersBlock_2);
    parametersViewer = new ParameterViewer(fTable);
    parametersViewer.getViewer().setLabelProvider(new ParametersLabelProvider());
    parametersViewer.getViewer().setContentProvider(new ParametersContentProvider());
    parametersViewer.addParametersChangedListener(new IParametersChangedListener() {

        public void parametersChanged(ParameterViewer viewer) {
            updateLaunchConfigurationDialog();
        }
    });
    parametersViewer.getViewer().getTable().addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent event) {
            if (event.character == SWT.DEL && event.stateMask == 0) {
                RemoveParameterAction ra = new RemoveParameterAction(parametersViewer);
                ra.run();
                updateLaunchConfigurationDialog();
            }
        }
    });
    parametersViewer.getViewer().setColumnProperties(// $NON-NLS-1$ //$NON-NLS-2$
    new String[] { "name", "value" });
    TextCellEditor textEditor = new TextCellEditor(fTable);
    CellEditor[] editors = new CellEditor[] { null, textEditor };
    parametersViewer.getViewer().setCellEditors(editors);
    parametersViewer.getViewer().setCellModifier(new ICellModifier() {

        public boolean canModify(Object element, String property) {
            // $NON-NLS-1$
            return "value".equals(property);
        }

        public Object getValue(Object element, String property) {
            LaunchAttribute att = (LaunchAttribute) element;
            // $NON-NLS-1$
            return att.value == null ? "" : att.value;
        }

        public void modify(Object element, String property, Object value) {
            Item item = (Item) element;
            LaunchAttribute att = (LaunchAttribute) item.getData();
            att.value = (String) value;
            parametersViewer.getViewer().update(att, null);
            updateLaunchConfigurationDialog();
        }
    });
    Composite parameterButtonComp = new Composite(group, SWT.NONE);
    GridLayout parameterButtonCompLayout = new GridLayout();
    parameterButtonCompLayout.marginHeight = 0;
    parameterButtonCompLayout.marginWidth = 0;
    parameterButtonComp.setLayout(parameterButtonCompLayout);
    gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING | GridData.HORIZONTAL_ALIGN_FILL);
    gd.horizontalSpan = 2;
    parameterButtonComp.setLayoutData(gd);
    parameterButtonComp.setFont(font);
    addParameterButton = createButton(parameterButtonComp, new AddParameterAction(parametersViewer));
    removeParameterButton = createButton(parameterButtonComp, new RemoveParameterAction(parametersViewer));
    transformsBlock.getStylesheetViewer().addSelectionChangedListener(selectionListener);
    restoreColumnSettings();
}
Also used : Group(org.eclipse.swt.widgets.Group) Table(org.eclipse.swt.widgets.Table) Composite(org.eclipse.swt.widgets.Composite) CellEditor(org.eclipse.jface.viewers.CellEditor) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor) KeyAdapter(org.eclipse.swt.events.KeyAdapter) TableColumn(org.eclipse.swt.widgets.TableColumn) LaunchAttribute(org.eclipse.wst.xsl.launching.config.LaunchAttribute) Font(org.eclipse.swt.graphics.Font) AddParameterAction(org.eclipse.wst.xsl.internal.debug.ui.actions.AddParameterAction) KeyEvent(org.eclipse.swt.events.KeyEvent) Item(org.eclipse.swt.widgets.Item) GridLayout(org.eclipse.swt.layout.GridLayout) RemoveParameterAction(org.eclipse.wst.xsl.internal.debug.ui.actions.RemoveParameterAction) GridData(org.eclipse.swt.layout.GridData) ICellModifier(org.eclipse.jface.viewers.ICellModifier) TextCellEditor(org.eclipse.jface.viewers.TextCellEditor)

Example 8 with LaunchAttribute

use of org.eclipse.wst.xsl.launching.config.LaunchAttribute in project webtools.sourceediting by eclipse.

the class LaunchHelper method hydrateAttributes.

private static LaunchAttributes hydrateAttributes(ILaunchConfiguration configuration) throws CoreException {
    LaunchAttributes attributes = new LaunchAttributes();
    // configuration.getAttribute(JAXPLaunchConfigurationConstants.ATTR_USE_FEATURES_FROM_PREFERENCES,
    boolean useDefaultAttributes = false;
    // true);
    if (useDefaultAttributes) {
        IProcessorType pt = getProcessorInstall(configuration).getProcessorType();
        Map<String, String> fvals = pt.getAttributeValues();
        for (Map.Entry<String, String> entry : fvals.entrySet()) {
            String uri = entry.getKey();
            getAttribute(pt.getAttributes(), uri);
            attributes.addAttribute(new LaunchAttribute(uri, "string", // $NON-NLS-1$
            entry.getValue()));
        }
    } else {
        String s = configuration.getAttribute(JAXPLaunchConfigurationConstants.ATTR_ATTRIBUTES, (String) null);
        if (s != null && s.length() > 0) {
            ByteArrayInputStream inputStream = new ByteArrayInputStream(s.getBytes());
            attributes = LaunchAttributes.fromXML(inputStream);
        }
    }
    return attributes;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) IProcessorType(org.eclipse.wst.xsl.jaxp.launching.IProcessorType) LaunchAttributes(org.eclipse.wst.xsl.jaxp.launching.LaunchAttributes) Map(java.util.Map) LaunchAttribute(org.eclipse.wst.xsl.launching.config.LaunchAttribute)

Example 9 with LaunchAttribute

use of org.eclipse.wst.xsl.launching.config.LaunchAttribute in project webtools.sourceediting by eclipse.

the class AttributesBlock method performRemove.

private void performRemove() {
    IStructuredSelection sel = (IStructuredSelection) tViewer.getSelection();
    for (Iterator<LaunchAttribute> iterator = sel.iterator(); iterator.hasNext(); ) {
        LaunchAttribute att = iterator.next();
        attributes.removeAtribute(att.uri);
    }
    tViewer.refresh();
    updateLaunchConfigurationDialog();
}
Also used : IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) LaunchAttribute(org.eclipse.wst.xsl.launching.config.LaunchAttribute)

Example 10 with LaunchAttribute

use of org.eclipse.wst.xsl.launching.config.LaunchAttribute 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)

Aggregations

LaunchAttribute (org.eclipse.wst.xsl.launching.config.LaunchAttribute)10 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)3 Document (org.w3c.dom.Document)3 Map (java.util.Map)2 CellEditor (org.eclipse.jface.viewers.CellEditor)2 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)2 TextCellEditor (org.eclipse.jface.viewers.TextCellEditor)2 KeyAdapter (org.eclipse.swt.events.KeyAdapter)2 KeyEvent (org.eclipse.swt.events.KeyEvent)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 TableColumn (org.eclipse.swt.widgets.TableColumn)2 LaunchAttributes (org.eclipse.wst.xsl.jaxp.launching.LaunchAttributes)2 Element (org.w3c.dom.Element)2 BufferedWriter (java.io.BufferedWriter)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileWriter (java.io.FileWriter)1