Search in sources :

Example 51 with IPropertyChangeListener

use of org.eclipse.jface.util.IPropertyChangeListener in project translationstudio8 by heartsome.

the class KeysPreferencePage method createTree.

private void createTree(Composite parent) {
    fPatternFilter = new CategoryPatternFilter(true, fDefaultCategory);
    fPatternFilter.filterCategories(true);
    GridData gridData;
    fFilteredTree = new CategoryFilterTree(parent, SWT.SINGLE | SWT.BORDER | SWT.FULL_SELECTION, fPatternFilter);
    final GridLayout layout = new GridLayout(1, false);
    layout.marginWidth = 0;
    fFilteredTree.setLayout(layout);
    gridData = new GridData();
    gridData.grabExcessHorizontalSpace = true;
    gridData.grabExcessVerticalSpace = true;
    gridData.horizontalAlignment = SWT.FILL;
    gridData.verticalAlignment = SWT.FILL;
    fFilteredTree.setLayoutData(gridData);
    viewer = fFilteredTree.getViewer();
    // Make sure the filtered tree has a height of ITEMS_TO_SHOW
    final Tree tree = viewer.getTree();
    tree.setHeaderVisible(true);
    final Object layoutData = tree.getLayoutData();
    if (layoutData instanceof GridData) {
        gridData = (GridData) layoutData;
        final int itemHeight = tree.getItemHeight();
        if (itemHeight > 1) {
            gridData.heightHint = ITEMS_TO_SHOW * itemHeight;
        }
    }
    BindingModelComparator comparator = new BindingModelComparator();
    comparator.setSortColumn(2);
    viewer.setComparator(comparator);
    final TreeColumn commandNameColumn = new TreeColumn(tree, SWT.LEFT, COMMAND_NAME_COLUMN);
    commandNameColumn.setText(Messages.getString("preferencepage.KeysPreferencePage.commandNameColumn"));
    tree.setSortColumn(commandNameColumn);
    tree.setSortDirection(comparator.isAscending() ? SWT.UP : SWT.DOWN);
    commandNameColumn.addSelectionListener(new ResortColumn(comparator, commandNameColumn, viewer, COMMAND_NAME_COLUMN));
    final TreeViewerColumn triggerSequenceColumn = new TreeViewerColumn(viewer, SWT.LEFT, KEY_SEQUENCE_COLUMN);
    triggerSequenceColumn.getColumn().setText(Messages.getString("preferencepage.KeysPreferencePage.triggerSequenceColumn"));
    triggerSequenceColumn.getColumn().addSelectionListener(new ResortColumn(comparator, triggerSequenceColumn.getColumn(), viewer, KEY_SEQUENCE_COLUMN));
    triggerSequenceColumn.setEditingSupport(new TableViewerEditingSupport(viewer, 1));
    final TreeColumn categoryColumn = new TreeColumn(tree, SWT.LEFT, CATEGORY_COLUMN);
    categoryColumn.setText(Messages.getString("preferencepage.KeysPreferencePage.categoryColumn"));
    categoryColumn.addSelectionListener(new ResortColumn(comparator, categoryColumn, viewer, CATEGORY_COLUMN));
    viewer.setContentProvider(new ModelContentProvider());
    viewer.setLabelProvider(new BindingElementLabelProvider());
    fFilteredTree.getPatternFilter().setIncludeLeadingWildcard(true);
    final TreeColumn[] columns = viewer.getTree().getColumns();
    columns[COMMAND_NAME_COLUMN].setWidth(240);
    columns[KEY_SEQUENCE_COLUMN].setWidth(130);
    columns[CATEGORY_COLUMN].setWidth(130);
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        // When the viewer changes selection, update the model's current
        // selection
        public void selectionChanged(SelectionChangedEvent event) {
            changeBackground();
            ModelElement binding = (ModelElement) ((IStructuredSelection) event.getSelection()).getFirstElement();
            model.setSelectedElement(binding);
        }
    });
    IPropertyChangeListener treeUpdateListener = new IPropertyChangeListener() {

        // When the model changes a property, update the viewer
        public void propertyChange(PropertyChangeEvent event) {
            if (event.getSource() == model && CommonModel.PROP_SELECTED_ELEMENT.equals(event.getProperty())) {
                Object newVal = event.getNewValue();
                StructuredSelection structuredSelection = newVal == null ? null : new StructuredSelection(newVal);
                viewer.setSelection(structuredSelection, true);
            } else if (event.getSource() instanceof BindingElement && ModelElement.PROP_MODEL_OBJECT.equals(event.getProperty())) {
                viewer.update(event.getSource(), null);
            } else if (BindingElement.PROP_CONFLICT.equals(event.getProperty())) {
                viewer.update(event.getSource(), null);
            } else if (BindingModel.PROP_BINDINGS.equals(event.getProperty())) {
            // viewer.refresh();
            } else if (BindingModel.PROP_BINDING_ADD.equals(event.getProperty())) {
                viewer.add(model, event.getNewValue());
            } else if (BindingModel.PROP_BINDING_REMOVE.equals(event.getProperty())) {
                viewer.remove(event.getNewValue());
            } else if (BindingModel.PROP_BINDING_FILTER.equals(event.getProperty())) {
            // viewer.refresh();
            }
            changeBackground();
        // isValid();
        }
    };
    keyController.addPropertyChangeListener(treeUpdateListener);
    // IPropertyChangeListener conflictsListener = new IPropertyChangeListener() {
    // public void propertyChange(PropertyChangeEvent event) {
    // // System.out.println(event.getNewValue().getClass());
    // if (keyController.getConflictModel().getConflicts() != null) {
    // if (ConflictModel.PROP_CONFLICTS.equals(event.getProperty())) {
    // // lstConflict.clear();
    // if (event.getNewValue() != null) {
    // lstConflict.addAll((Collection<? extends Object>) event.getNewValue());
    // }
    // // conflictViewer.setInput(event.getNewValue());
    // } else if (ConflictModel.PROP_CONFLICTS_ADD.equals(event.getProperty())) {
    // if (event.getNewValue() != null) {
    // lstConflict.add(event.getNewValue());
    // }
    // // conflictViewer.add(event.getNewValue());
    // } else if (ConflictModel.PROP_CONFLICTS_REMOVE.equals(event.getProperty())) {
    // // conflictViewer.remove(event.getNewValue());
    // if (event.getNewValue() != null) {
    // lstConflict.remove(event.getNewValue());
    // }
    // }
    // } else {
    // lstConflict.clear();
    // }
    // // if (event.getSource() == keyController.getConflictModel()
    // // && CommonModel.PROP_SELECTED_ELEMENT.equals(event.getProperty())) {
    // // if (keyController.getConflictModel().getConflicts() != null) {
    // // Object newVal = event.getNewValue();
    // // StructuredSelection structuredSelection = newVal == null ? null : new StructuredSelection(
    // // newVal);
    // // // conflictViewer.setSelection(structuredSelection, true);
    // // }
    // // } else if (ConflictModel.PROP_CONFLICTS.equals(event.getProperty())) {
    // // // lstConflict.clear();
    // // if (event.getNewValue() != null) {
    // // lstConflict.addAll((Collection<? extends Object>) event.getNewValue());
    // // }
    // // // conflictViewer.setInput(event.getNewValue());
    // // } else if (ConflictModel.PROP_CONFLICTS_ADD.equals(event.getProperty())) {
    // // if (event.getNewValue() != null) {
    // // lstConflict.clear();
    // // lstConflict.add(event.getNewValue());
    // // }
    // // // conflictViewer.add(event.getNewValue());
    // // } else if (ConflictModel.PROP_CONFLICTS_REMOVE.equals(event.getProperty())) {
    // // // conflictViewer.remove(event.getNewValue());
    // // if (event.getNewValue() != null) {
    // // lstConflict.clear();
    // // lstConflict.remove(event.getNewValue());
    // // }
    // // }
    // }
    // };
    // keyController.addPropertyChangeListener(conflictsListener);
    IPropertyChangeListener dataUpdateListener = new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            BindingElement bindingElement = null;
            boolean weCare = false;
            if (event.getSource() == model && CommonModel.PROP_SELECTED_ELEMENT.equals(event.getProperty())) {
                bindingElement = (BindingElement) event.getNewValue();
                weCare = true;
            } else if (event.getSource() == model.getSelectedElement() && ModelElement.PROP_MODEL_OBJECT.equals(event.getProperty())) {
                bindingElement = (BindingElement) event.getSource();
                weCare = true;
            }
            if (bindingElement == null && weCare) {
                //$NON-NLS-1$
                fBindingText.setText("");
            } else if (bindingElement != null) {
                KeySequence trigger = (KeySequence) bindingElement.getTrigger();
                fKeySequenceText.setKeySequence(trigger);
            }
        }
    };
    keyController.addPropertyChangeListener(dataUpdateListener);
}
Also used : BindingElement(org.eclipse.ui.internal.keys.model.BindingElement) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ModelElement(org.eclipse.ui.internal.keys.model.ModelElement) GridLayout(org.eclipse.swt.layout.GridLayout) TreeColumn(org.eclipse.swt.widgets.TreeColumn) Tree(org.eclipse.swt.widgets.Tree) FilteredTree(org.eclipse.ui.dialogs.FilteredTree) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) TreeViewerColumn(org.eclipse.jface.viewers.TreeViewerColumn) GridData(org.eclipse.swt.layout.GridData) KeySequence(org.eclipse.jface.bindings.keys.KeySequence)

Example 52 with IPropertyChangeListener

use of org.eclipse.jface.util.IPropertyChangeListener in project translationstudio8 by heartsome.

the class ConflictModel2 method init.

public void init(BindingManager manager, BindingModel model) {
    bindingManager = manager;
    bindingModel = model;
    conflictsMap = new HashMap();
    Iterator i = bindingModel.getBindings().iterator();
    while (i.hasNext()) {
        BindingElement be = (BindingElement) i.next();
        if (be.getModelObject() instanceof Binding) {
            updateConflictsFor(be);
        }
    }
    controller.addPropertyChangeListener(new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            if (event.getSource() == ConflictModel2.this && CommonModel.PROP_SELECTED_ELEMENT.equals(event.getProperty())) {
                if (event.getNewValue() != null) {
                    updateConflictsFor((BindingElement) event.getOldValue(), (BindingElement) event.getNewValue());
                    setConflicts((Collection) conflictsMap.get(event.getNewValue()));
                } else {
                    setConflicts(null);
                }
            } else if (BindingModel.PROP_BINDING_REMOVE.equals(event.getProperty())) {
                updateConflictsFor((BindingElement) event.getOldValue(), (BindingElement) event.getNewValue(), true);
            }
        }
    });
}
Also used : Binding(org.eclipse.jface.bindings.Binding) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) HashMap(java.util.HashMap) BindingElement(org.eclipse.ui.internal.keys.model.BindingElement) Iterator(java.util.Iterator) Collection(java.util.Collection)

Example 53 with IPropertyChangeListener

use of org.eclipse.jface.util.IPropertyChangeListener in project translationstudio8 by heartsome.

the class KeyController2 method firePropertyChange.

public void firePropertyChange(Object source, String propId, Object oldVal, Object newVal) {
    if (!isNotifying()) {
        return;
    }
    if (Util.equals(oldVal, newVal)) {
        return;
    }
    Object[] listeners = getEventManager().getListeners();
    PropertyChangeEvent event = new PropertyChangeEvent(source, propId, oldVal, newVal);
    for (int i = 0; i < listeners.length; i++) {
        ((IPropertyChangeListener) listeners[i]).propertyChange(event);
    }
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent)

Example 54 with IPropertyChangeListener

use of org.eclipse.jface.util.IPropertyChangeListener in project translationstudio8 by heartsome.

the class WorkingSetActionProvider method init.

public void init(ICommonActionExtensionSite aSite) {
    viewer = (CommonViewer) aSite.getStructuredViewer();
    contentService = aSite.getContentService();
    filterService = (NavigatorFilterService) contentService.getFilterService();
    extensionStateModel = contentService.findStateModel(WorkingSetsContentProvider.EXTENSION_ID);
    workingSetActionGroup = new WorkingSetFilterActionGroup(aSite.getViewSite().getShell(), filterChangeListener);
    workingSetRootModeActionGroup = new WorkingSetRootModeActionGroup(viewer, extensionStateModel);
    topLevelModeListener = new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            setWorkingSet(workingSet);
            viewer.getFrameList().reset();
        }
    };
    if (contentService.isActive(WorkingSetsContentProvider.EXTENSION_ID)) {
        managerChangeListener.listen();
        extensionStateModel.addPropertyChangeListener(topLevelModeListener);
    }
    contentService.getActivationService().addExtensionActivationListener(activationListener);
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) WorkingSetFilterActionGroup(org.eclipse.ui.actions.WorkingSetFilterActionGroup)

Example 55 with IPropertyChangeListener

use of org.eclipse.jface.util.IPropertyChangeListener in project tdi-studio-se by Talend.

the class HL7DragAndDrogDialog method createDialogArea.

/*
     * (non-Javadoc) Method declared on Dialog.
     */
protected Control createDialogArea(Composite parent) {
    // create composite
    Composite composite = (Composite) super.createDialogArea(parent);
    // composite.setLayout(new GridLayout());
    String[][] namevalues = null;
    if (hideAttr) {
        namevalues = new String[][] { { "Create as sub-element of target node", CREATE_AS_SUBELEMENT }, { "Add linker to target node", CREATE_AS_TEXT } };
    } else {
        namevalues = new String[][] { { "Create as sub-element of target node", CREATE_AS_SUBELEMENT }, { "Create as attribute of target node", CREATE_AS_ATTRIBUTE }, { "Add linker to target node", CREATE_AS_TEXT } };
    }
    RadioGroupFieldEditor rgfe = new RadioGroupFieldEditor("", "Select the operation:", 1, namevalues, composite, true);
    GridLayout layout = new GridLayout();
    layout.marginWidth = 12;
    composite.setLayout(layout);
    rgfe.setPropertyChangeListener(new IPropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent event) {
            value = event.getNewValue().toString();
        }
    });
    applyDialogFont(composite);
    return composite;
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) RadioGroupFieldEditor(org.eclipse.jface.preference.RadioGroupFieldEditor) GridLayout(org.eclipse.swt.layout.GridLayout) PropertyChangeEvent(org.eclipse.jface.util.PropertyChangeEvent) Composite(org.eclipse.swt.widgets.Composite)

Aggregations

IPropertyChangeListener (org.eclipse.jface.util.IPropertyChangeListener)126 PropertyChangeEvent (org.eclipse.jface.util.PropertyChangeEvent)120 Composite (org.eclipse.swt.widgets.Composite)55 GridData (org.eclipse.swt.layout.GridData)44 Label (org.eclipse.swt.widgets.Label)39 GridLayout (org.eclipse.swt.layout.GridLayout)37 SelectionEvent (org.eclipse.swt.events.SelectionEvent)31 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)25 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)22 Button (org.eclipse.swt.widgets.Button)22 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)21 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)20 ColorSelector (org.eclipse.jface.preference.ColorSelector)14 ComboViewer (org.eclipse.jface.viewers.ComboViewer)12 Text (org.eclipse.swt.widgets.Text)11 Iterator (java.util.Iterator)10 ISelection (org.eclipse.jface.viewers.ISelection)10 StructuredSelection (org.eclipse.jface.viewers.StructuredSelection)10 IPreferenceStore (org.eclipse.jface.preference.IPreferenceStore)9 SashForm (org.eclipse.swt.custom.SashForm)9