Java Code Examples for org.eclipse.jface.util.PropertyChangeEvent#getOldValue()

The following examples show how to use org.eclipse.jface.util.PropertyChangeEvent#getOldValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WorkingSetManagerModificationStrategyProvider.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Returns with the strategy for the given property change even argument,
 *
 * @param event
 *            a property change argument.
 * @return a strategy encapsulating an actual working set manager modification.
 */
public WorkingSetManagerModificationStrategy getStrategy(final PropertyChangeEvent event) {

	if (event == null) {
		return NOOP;
	}

	final String property = event.getProperty();
	switch (property) {
	case CHANGE_WORKING_SET_ADD:
		return new AddWorkingSetModificationStrategy((IWorkingSet) event.getNewValue());
	case CHANGE_WORKING_SET_REMOVE:
		return new RemoveWorkingSetModificationStrategy((IWorkingSet) event.getOldValue());
	case CHANGE_WORKING_SET_LABEL_CHANGE: //$FALL-THROUGH$
	case CHANGE_WORKING_SET_NAME_CHANGE: //$FALL-THROUGH$
	case CHANGE_WORKING_SET_CONTENT_CHANGE:
		return new UpdateWorkingSetModificationStraregy(
				(IWorkingSet) event.getOldValue(),
				(IWorkingSet) event.getNewValue());
	default:
		return NOOP;
	}
}
 
Example 2
Source File: AbstractToggleActionContributor.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void addPropertyChangeListener() {
	propertyChangeListener = new IPropertyChangeListener() {
		@Override
		public void propertyChange(PropertyChangeEvent event) {
			if (getPreferenceKey().equals(event.getProperty()) && event.getOldValue() != event.getNewValue()) {
				boolean newValue = Boolean.parseBoolean(event.getNewValue().toString());
				stateChanged(newValue);
				getAction().setChecked(newValue);
			}
		}
	};
	preferenceStore = preferenceStoreAccess.getPreferenceStore();
	preferenceStore.addPropertyChangeListener(propertyChangeListener);
}
 
Example 3
Source File: WorkingSetModel.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
private boolean isAffected(PropertyChangeEvent event) {
	if (fActiveWorkingSets == null)
		return false;
	Object oldValue= event.getOldValue();
	Object newValue= event.getNewValue();
	if ((oldValue != null && fActiveWorkingSets.contains(oldValue))
			|| (newValue != null && fActiveWorkingSets.contains(newValue))) {
		return true;
	}
	return false;
}
 
Example 4
Source File: WorkingSetActionProvider.java    From translationstudio8 with GNU General Public License v2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent event) {
	String property = event.getProperty();
	Object newValue = event.getNewValue();
	Object oldValue = event.getOldValue();

	String newLabel = null;
	if (IWorkingSetManager.CHANGE_WORKING_SET_REMOVE.equals(property) && oldValue == workingSet) {
		newLabel = ""; //$NON-NLS-1$
		setWorkingSet(null);
	} else if (IWorkingSetManager.CHANGE_WORKING_SET_NAME_CHANGE.equals(property) && newValue == workingSet) {
		newLabel = workingSet.getLabel();
	} else if (IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE.equals(property) && newValue == workingSet) {
		if (workingSet.isAggregateWorkingSet() && workingSet.isEmpty()) {
			// act as if the working set has been made null
			if (!emptyWorkingSet) {
				emptyWorkingSet = true;
				setWorkingSetFilter(null);
				newLabel = null;
			}
		} else {
			// we've gone from empty to non-empty on our set.
			// Restore it.
			if (emptyWorkingSet) {
				emptyWorkingSet = false;
				setWorkingSetFilter(workingSet);
				newLabel = workingSet.getLabel();
			}
		}
	}
	if (viewer != null) {
		if (newLabel != null)
			viewer.getCommonNavigator().setWorkingSetLabel(newLabel);
		viewer.getFrameList().reset();
		viewer.refresh();
	}
}
 
Example 5
Source File: WorkingSetActionProvider.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
public void propertyChange(PropertyChangeEvent event) {
	String property = event.getProperty();
	Object newValue = event.getNewValue();
	Object oldValue = event.getOldValue();

	String newLabel = null;
	if (IWorkingSetManager.CHANGE_WORKING_SET_REMOVE.equals(property) && oldValue == workingSet) {
		newLabel = ""; //$NON-NLS-1$
		setWorkingSet(null);
	} else if (IWorkingSetManager.CHANGE_WORKING_SET_NAME_CHANGE.equals(property) && newValue == workingSet) {
		newLabel = workingSet.getLabel();
	} else if (IWorkingSetManager.CHANGE_WORKING_SET_CONTENT_CHANGE.equals(property) && newValue == workingSet) {
		if (workingSet.isAggregateWorkingSet() && workingSet.isEmpty()) {
			// act as if the working set has been made null
			if (!emptyWorkingSet) {
				emptyWorkingSet = true;
				setWorkingSetFilter(null);
				newLabel = null;
			}
		} else {
			// we've gone from empty to non-empty on our set.
			// Restore it.
			if (emptyWorkingSet) {
				emptyWorkingSet = false;
				setWorkingSetFilter(workingSet);
				newLabel = workingSet.getLabel();
			}
		}
	}
	if (viewer != null) {
		if (newLabel != null)
			viewer.getCommonNavigator().setWorkingSetLabel(newLabel);
		viewer.getFrameList().reset();
		viewer.refresh();
	}
}
 
Example 6
Source File: EclipsePreferenceStoreAdapter.java    From saros with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void propertyChange(final PropertyChangeEvent event) {
  final PreferenceChangeEvent eventToFire =
      new PreferenceChangeEvent(
          event.getProperty(), event.getOldValue(), event.getNewValue());

  for (final IPreferenceChangeListener listener : listeners)
    listener.preferenceChange(eventToFire);
}
 
Example 7
Source File: BugActionProvider.java    From spotbugs with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public void init(ICommonActionExtensionSite aSite) {
    site = aSite;
    super.init(aSite);
    final StructuredViewer viewer = aSite.getStructuredViewer();
    final BugContentProvider provider = BugContentProvider.getProvider(site.getContentService());

    filterChangeListener = new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (!initDone) {
                return;
            }
            IWorkingSet oldWorkingSet = provider.getCurrentWorkingSet();
            IWorkingSet oldWorkingSet1 = (IWorkingSet) event.getOldValue();
            IWorkingSet newWorkingSet = (IWorkingSet) event.getNewValue();
            if (newWorkingSet != null && (oldWorkingSet == newWorkingSet || oldWorkingSet1 == newWorkingSet)) {
                return;
            }
            if (viewer != null) {
                provider.setCurrentWorkingSet(newWorkingSet);
                if (newWorkingSet == null) {
                    viewer.setInput(ResourcesPlugin.getWorkspace().getRoot());
                } else if (oldWorkingSet != newWorkingSet) {
                    viewer.setInput(newWorkingSet);
                }
            }
        }
    };


    workingSetActionGroup = new WorkingSetFilterActionGroup(aSite.getViewSite().getShell(), filterChangeListener);
    if (provider == null)
        throw new NullPointerException("no provider");
    workingSetActionGroup.setWorkingSet(provider.getCurrentWorkingSet());
    doubleClickAction = new MyAction();
    // only if doubleClickAction must know tree selection:
    viewer.addSelectionChangedListener(doubleClickAction);
    initDone = true;
}
 
Example 8
Source File: TLCChainedPreferenceStore.java    From tlaplus with MIT License 4 votes vote down vote up
/**
 * Handle property change event from the child listener with the given child preference store.
 *
 * @param childPreferenceStore the child preference store
 * @param event the event
 */
private void handlePropertyChangeEvent(IPreferenceStore childPreferenceStore, PropertyChangeEvent event) {
	String property= event.getProperty();
	Object oldValue= event.getOldValue();
	Object newValue= event.getNewValue();

	IPreferenceStore visibleStore= getVisibleStore(property);

	/*
	 * Assume that the property is there but has no default value (its owner relies on the default-default value)
	 * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=52827
	 */
	if (visibleStore == null && newValue != null)
		visibleStore= childPreferenceStore;

	if (visibleStore == null) {
		// no visible store
		if (oldValue != null)
			// removal in child, last in chain -> removal in this chained preference store
			firePropertyChangeEvent(event);
	} else if (visibleStore == childPreferenceStore) {
		// event from visible store
		if (oldValue != null) {
			// change in child, visible store -> change in this chained preference store
			firePropertyChangeEvent(event);
		} else {
			// insertion in child
			IPreferenceStore oldVisibleStore= null;
			int i= 0;
			int length= fPreferenceStores.length;
			while (i < length && fPreferenceStores[i++] != visibleStore) {
				// do nothing
			}
			while (oldVisibleStore == null && i < length) {
				if (fPreferenceStores[i].contains(property))
					oldVisibleStore= fPreferenceStores[i];
				i++;
			}

			if (oldVisibleStore == null) {
				// insertion in child, first in chain -> insertion in this chained preference store
				firePropertyChangeEvent(event);
			} else {
				// insertion in child, not first in chain
				oldValue= getOtherValue(property, oldVisibleStore, newValue);
				if (!oldValue.equals(newValue))
					// insertion in child, different old value -> change in this chained preference store
					firePropertyChangeEvent(property, oldValue, newValue);
				// else: insertion in child, same old value -> no change in this chained preference store
			}
		}
	} else {
		// event from other than the visible store
		boolean eventBeforeVisibleStore= false;
		for (int i= 0, length= fPreferenceStores.length; i < length; i++) {
			IPreferenceStore store= fPreferenceStores[i];
			if (store == visibleStore)
				break;
			if (store == childPreferenceStore) {
				eventBeforeVisibleStore= true;
				break;
			}
		}

		if (eventBeforeVisibleStore) {
			// removal in child, before visible store

			/*
			 * The original event's new value can be non-null (removed assertion).
			 * see https://bugs.eclipse.org/bugs/show_bug.cgi?id=69419
			 */

			newValue= getOtherValue(property, visibleStore, oldValue);
			if (!newValue.equals(oldValue))
				// removal in child, before visible store, different old value -> change in this chained preference store
				firePropertyChangeEvent(property, oldValue, newValue);
			// else: removal in child, before visible store, same old value -> no change in this chained preference store
		}
		// else: event behind visible store -> no change in this chained preference store
	}
}