diff options
Diffstat (limited to 'bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeModelElement.java')
-rw-r--r-- | bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeModelElement.java | 196 |
1 files changed, 0 insertions, 196 deletions
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeModelElement.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeModelElement.java deleted file mode 100644 index fcda55e62..000000000 --- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/SynchronizeModelElement.java +++ /dev/null @@ -1,196 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.team.internal.ui.synchronize; - -import org.eclipse.compare.structuremergeviewer.*; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.*; -import org.eclipse.jface.resource.ImageDescriptor; -import org.eclipse.jface.util.*; -import org.eclipse.team.core.synchronize.SyncInfo; -import org.eclipse.team.ui.synchronize.ISynchronizeModelElement; -import org.eclipse.ui.model.IWorkbenchAdapter; - -/** - * A model element that can be shown in viewers. - * - * @since 3.0 - */ -public abstract class SynchronizeModelElement extends DiffNode implements IAdaptable, ISynchronizeModelElement { - - /* - * Internal flags bits for stroing properties in the flags variable - */ - private static final int BUSY_FLAG = 0x01; - private static final int PROPAGATED_CONFLICT_FLAG = 0x02; - private static final int PROPAGATED_ERROR_FLAG = 0x04; - private static final int PROPAGATED_WARNING_FLAG =0x08; - - // Instance variable containing the flags for this node - private int flags; - private ListenerList listeners; - - public SynchronizeModelElement(IDiffContainer parent) { - super(parent, SyncInfo.IN_SYNC); - } - - /* (non-Javadoc) - * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) - */ - public Object getAdapter(Class adapter) { - return Platform.getAdapterManager().getAdapter(this, adapter); - } - - public synchronized void addPropertyChangeListener(IPropertyChangeListener listener) { - if (listeners == null) { - listeners = new ListenerList(); - } - listeners.add(listener); - } - - public synchronized void removePropertyChangeListener(IPropertyChangeListener listener) { - if (listeners != null) { - listeners.remove(listener); - if (listeners.isEmpty()) { - listeners = null; - } - } - } - - /** - * Return whether this node has the given property set. - * @param propertyName the flag to test - * @return <code>true</code> if the property is set - */ - public boolean getProperty(String propertyName) { - return (getFlags() & getFlag(propertyName)) > 0; - } - - /** - * Add the flag to the flags for this node - * @param propertyName the flag to add - */ - public void setProperty(String propertyName, boolean value) { - if (value) { - if (!getProperty(propertyName)) { - int flag = getFlag(propertyName); - flags |= flag; - firePropertyChange(propertyName); - } - } else { - if (getProperty(propertyName)) { - int flag = getFlag(propertyName); - flags ^= flag; - firePropertyChange(propertyName); - } - } - } - - public void setPropertyToRoot(String propertyName, boolean value) { - if (value) { - addToRoot(propertyName); - } else { - removeToRoot(propertyName); - } - } - - public void fireChanges() { - fireChange(); - } - - public ImageDescriptor getImageDescriptor(Object object) { - IResource resource = getResource(); - if(resource != null) { - IWorkbenchAdapter adapter = (IWorkbenchAdapter)((IAdaptable) resource).getAdapter(IWorkbenchAdapter.class); - return adapter.getImageDescriptor(resource); - } - return null; - } - - public abstract IResource getResource(); - - private void addToRoot(String flag) { - setProperty(flag, true); - SynchronizeModelElement parent = (SynchronizeModelElement)getParent(); - if (parent != null) { - if (parent.getProperty(flag)) return; - parent.addToRoot(flag); - } - } - - private void firePropertyChange(String propertyName) { - Object[] allListeners; - synchronized(this) { - if (listeners == null) return; - allListeners = listeners.getListeners(); - } - boolean set = getProperty(propertyName); - final PropertyChangeEvent event = new PropertyChangeEvent(this, propertyName, Boolean.valueOf(!set), Boolean.valueOf(set)); - for (int i = 0; i < allListeners.length; i++) { - Object object = allListeners[i]; - if (object instanceof IPropertyChangeListener) { - final IPropertyChangeListener listener = (IPropertyChangeListener)object; - Platform.run(new ISafeRunnable() { - public void handleException(Throwable exception) { - // Exceptions logged by the platform - } - public void run() throws Exception { - listener.propertyChange(event); - } - }); - } - } - } - - private int getFlag(String propertyName) { - if (propertyName == BUSY_PROPERTY) { - return BUSY_FLAG; - } else if (propertyName == PROPAGATED_CONFLICT_PROPERTY) { - return PROPAGATED_CONFLICT_FLAG; - } else if(propertyName == PROPAGATED_ERROR_MARKER_PROPERTY) { - return PROPAGATED_ERROR_FLAG; - } else if(propertyName == PROPAGATED_WARNING_MARKER_PROPERTY) { - return PROPAGATED_WARNING_FLAG; - } - return 0; - } - - private int getFlags() { - return flags; - } - - private boolean hasChildWithFlag(String flag) { - IDiffElement[] childen = getChildren(); - for (int i = 0; i < childen.length; i++) { - IDiffElement element = childen[i]; - if (((SynchronizeModelElement)element).getProperty(flag)) { - return true; - } - } - return false; - } - - private void removeToRoot(String flag) { - boolean hasProperty = getProperty(flag); - if(hasProperty) { - setProperty(flag, false); - SynchronizeModelElement parent = (SynchronizeModelElement)getParent(); - if (parent != null) { - // If the parent doesn't have the tag, no recalculation is required - // Also, if the parent still has a child with the tag, no recalculation is needed - if (parent.getProperty(flag) && !parent.hasChildWithFlag(flag)) { - // The parent no longer has the flag so propogate the reclaculation - parent.removeToRoot(flag); - } - } - } - } -} |