Search in sources :

Example 91 with SelectionListener

use of org.eclipse.swt.events.SelectionListener in project eclipse.platform.swt by eclipse.

the class Test_org_eclipse_swt_widgets_Text method test_addSelectionListenerWidgetSelectedAdapterLorg_eclipse_swt_events_SelectionListener.

@Test
public void test_addSelectionListenerWidgetSelectedAdapterLorg_eclipse_swt_events_SelectionListener() {
    listenerCalled = false;
    SelectionListener listener = SelectionListener.widgetSelectedAdapter(e -> listenerCalled = true);
    text.addSelectionListener(listener);
    text.setText("12345");
    text.setSelection(1, 3);
    assertFalse(":a:", listenerCalled);
    text.removeSelectionListener(listener);
}
Also used : SelectionListener(org.eclipse.swt.events.SelectionListener) Test(org.junit.Test)

Example 92 with SelectionListener

use of org.eclipse.swt.events.SelectionListener in project hale by halestudio.

the class ClassificationMappingParameterPage method createFromFileTabControl.

private Control createFromFileTabControl(Composite tabParent) {
    // Parent composite for fromFileTab
    Composite item2Content = new Composite(tabParent, SWT.NONE);
    item2Content.setLayout(new GridLayout());
    // Label to descripe what the user should do
    Label l = new Label(item2Content, SWT.NONE);
    l.setText("Select the project lookup table resource you want to use for the classification:");
    // Get the Lookuptable Service
    final LookupService lookupService = HaleUI.getServiceProvider().getService(LookupService.class);
    // Composite for comboViewerComposite and Button
    Composite parent = new Composite(item2Content, SWT.NONE);
    parent.setLayout(new GridLayout(2, false));
    parent.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));
    // Description Label
    description = new Label(item2Content, SWT.WRAP);
    description.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    description.setText("");
    description.setVisible(false);
    // label with warning message
    Composite warnComp = new Composite(item2Content, SWT.NONE);
    GridLayoutFactory.swtDefaults().numColumns(2).applyTo(warnComp);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(warnComp);
    Label warnImage = new Label(warnComp, SWT.NONE);
    warnImage.setImage(PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
    GridDataFactory.swtDefaults().align(SWT.CENTER, SWT.BEGINNING).applyTo(warnImage);
    Label warn = new Label(warnComp, SWT.WRAP);
    warn.setText("Classifications from a file resource will not function in another project where the alignment with the classification is imported or used as a base alignment.\n" + "If unsure, use the 'Explicit' mode instead and use the option to load the classification from a file.");
    GridDataFactory.swtDefaults().align(SWT.FILL, SWT.BEGINNING).grab(true, false).hint(300, SWT.DEFAULT).applyTo(warn);
    // Composite for ComboViewer
    Composite viewerComposite = new Composite(parent, SWT.NONE);
    viewerComposite.setLayout(new FillLayout());
    GridData layoutData = new GridData(SWT.FILL, SWT.NONE, true, false);
    viewerComposite.setLayoutData(GridDataFactory.copyData(layoutData));
    // ComboViewer
    lookupTableComboViewer = new ComboViewer(viewerComposite, SWT.READ_ONLY);
    lookupTableComboViewer.setContentProvider(ArrayContentProvider.getInstance());
    lookupTableComboViewer.setLabelProvider(new LabelProvider() {

        @Override
        public String getText(Object element) {
            if (element instanceof String) {
                return lookupService.getTable((String) element).getName();
            }
            return null;
        }
    });
    lookupTableComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            // Show the description for the selected lookupTable
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            String desc = lookupService.getTable(selection.getFirstElement().toString()).getDescription();
            if (desc != null) {
                description.setText("Description: " + desc);
            } else {
                description.setText("");
            }
            if (!description.isVisible()) {
                description.setVisible(true);
            }
        }
    });
    lookupTableComboViewer.setInput(lookupService.getTableIDs());
    if (selectedLookupTableID != null) {
        lookupTableComboViewer.setSelection(new StructuredSelection(selectedLookupTableID), true);
    }
    // Button to load a lookupTable if no one is loaded
    final Button browseButton = new Button(parent, SWT.PUSH);
    browseButton.setText("Add...");
    browseButton.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            IOWizardAction action = new IOWizardAction("eu.esdihumboldt.hale.lookup.import");
            action.run();
            action.dispose();
            // Refresh the viewer
            lookupTableComboViewer.setInput(lookupService.getTableIDs());
        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
        // nothing to do here
        }
    });
    return item2Content;
}
Also used : Composite(org.eclipse.swt.widgets.Composite) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) Label(org.eclipse.swt.widgets.Label) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) FillLayout(org.eclipse.swt.layout.FillLayout) StyledString(org.eclipse.jface.viewers.StyledString) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) GridLayout(org.eclipse.swt.layout.GridLayout) LookupService(eu.esdihumboldt.hale.common.lookup.LookupService) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Button(org.eclipse.swt.widgets.Button) IOWizardAction(eu.esdihumboldt.hale.ui.io.action.IOWizardAction) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ColumnLabelProvider(org.eclipse.jface.viewers.ColumnLabelProvider) StyledCellLabelProvider(org.eclipse.jface.viewers.StyledCellLabelProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 93 with SelectionListener

use of org.eclipse.swt.events.SelectionListener in project hale by halestudio.

the class StackTraceErrorDialog method createDropDownList.

/**
 * @see ErrorDialog#createDropDownList(Composite)
 */
@Override
protected List createDropDownList(Composite parent) {
    _list = super.createDropDownList(parent);
    _list.removeAll();
    // replace context menu
    _list.getMenu().dispose();
    Menu copyMenu = new Menu(_list);
    MenuItem copyItem = new MenuItem(copyMenu, SWT.NONE);
    copyItem.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            copyToClipboard();
        }

        @Override
        public void widgetSelected(SelectionEvent e) {
            copyToClipboard();
        }
    });
    // $NON-NLS-1$
    copyItem.setText(JFaceResources.getString("copy"));
    _list.setMenu(copyMenu);
    // convert stack trace to string
    String stackTrace = stackTraceToString(_status.getException());
    if (stackTrace != null) {
        // add stack trace to list
        // $NON-NLS-1$ //$NON-NLS-2$
        stackTrace = stackTrace.replaceAll("\r", "");
        // $NON-NLS-1$ //$NON-NLS-2$
        stackTrace = stackTrace.replaceAll("\t", "    ");
        // $NON-NLS-1$
        String[] lines = stackTrace.split("\n");
        for (String l : lines) {
            _list.add(l);
        }
    }
    return _list;
}
Also used : SelectionEvent(org.eclipse.swt.events.SelectionEvent) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu) SelectionListener(org.eclipse.swt.events.SelectionListener)

Example 94 with SelectionListener

use of org.eclipse.swt.events.SelectionListener 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)

Example 95 with SelectionListener

use of org.eclipse.swt.events.SelectionListener in project pentaho-kettle by pentaho.

the class TableView method editButton.

private void editButton(TableItem row, int rownr, int colnr) {
    beforeEdit = getItemText(row);
    fieldChanged = false;
    ColumnInfo colinfo = columns[colnr - 1];
    if (colinfo.isReadOnly()) {
        return;
    }
    if (colinfo.getDisabledListener() != null) {
        boolean disabled = colinfo.getDisabledListener().isFieldDisabled(rownr);
        if (disabled) {
            return;
        }
    }
    button = new Button(table, SWT.PUSH);
    props.setLook(button, Props.WIDGET_STYLE_TABLE);
    String buttonText = columns[colnr - 1].getButtonText();
    if (buttonText != null) {
        button.setText(buttonText);
    }
    button.setImage(GUIResource.getInstance().getImage("ui/images/edittext.svg"));
    SelectionListener selAdpt = colinfo.getSelectionAdapter();
    if (selAdpt != null) {
        button.addSelectionListener(selAdpt);
    }
    buttonRownr = rownr;
    buttonColnr = colnr;
    // button.addTraverseListener(lsTraverse);
    buttonContent = row.getText(colnr);
    String tooltip = columns[colnr - 1].getToolTip();
    if (tooltip != null) {
        button.setToolTipText(tooltip);
    } else {
        button.setToolTipText("");
    }
    // hop to next field
    button.addTraverseListener(lsTraverse);
    button.addTraverseListener(new TraverseListener() {

        @Override
        public void keyTraversed(TraverseEvent arg0) {
            closeActiveButton();
        }
    });
    editor.horizontalAlignment = SWT.LEFT;
    editor.verticalAlignment = SWT.TOP;
    editor.grabHorizontal = false;
    editor.grabVertical = false;
    Point size = button.computeSize(SWT.DEFAULT, SWT.DEFAULT);
    editor.minimumWidth = size.x;
    editor.minimumHeight = size.y - 2;
    // setRowNums();
    editor.layout();
    // Open the text editor in the correct column of the selected row.
    editor.setEditor(button);
    button.setFocus();
// if the button loses focus, destroy it...
/*
     * button.addFocusListener(new FocusAdapter() { public void focusLost(FocusEvent e) { button.dispose(); } } );
     */
}
Also used : TraverseEvent(org.eclipse.swt.events.TraverseEvent) Button(org.eclipse.swt.widgets.Button) TraverseListener(org.eclipse.swt.events.TraverseListener) ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) Point(org.eclipse.swt.graphics.Point) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

SelectionListener (org.eclipse.swt.events.SelectionListener)711 SelectionEvent (org.eclipse.swt.events.SelectionEvent)665 GridData (org.eclipse.swt.layout.GridData)411 Button (org.eclipse.swt.widgets.Button)409 Composite (org.eclipse.swt.widgets.Composite)381 GridLayout (org.eclipse.swt.layout.GridLayout)374 Label (org.eclipse.swt.widgets.Label)256 Text (org.eclipse.swt.widgets.Text)152 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)140 Group (org.eclipse.swt.widgets.Group)137 ModifyListener (org.eclipse.swt.events.ModifyListener)113 ModifyEvent (org.eclipse.swt.events.ModifyEvent)112 Combo (org.eclipse.swt.widgets.Combo)101 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)69 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)69 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)69 FormData (org.eclipse.swt.layout.FormData)69 Event (org.eclipse.swt.widgets.Event)69 FormAttachment (org.eclipse.swt.layout.FormAttachment)68 ArrayList (java.util.ArrayList)57