Skip to content

Commit

Permalink
[466340] Ensure *Support classes share similar contract.
Browse files Browse the repository at this point in the history
- Ensured PropertyStoreSupport does not implement IPropertyStore.
- Ensured PropertyStoreSupport does not create a local
PropertyChangeSupport but uses one that get's pass into the constructor.
- Ensured ActivatableSupport does not provide an unused generic
parameter.
  • Loading branch information
nyssen committed May 4, 2015
1 parent 45c5454 commit 7fb61f2
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,12 @@
* for this purpose.
*
* @author anyssen
*
* @param <A>
* The type of {@link IActivatable} supported by this class.
*
*
*/
public class ActivatableSupport<A extends IActivatable> {
public class ActivatableSupport {

private boolean isActive = false;
private A source;
private IActivatable source;
private PropertyChangeSupport pcs;

/**
Expand All @@ -65,7 +61,7 @@ public class ActivatableSupport<A extends IActivatable> {
* An {@link PropertyChangeSupport}, which will be used to fire
* {@link PropertyChangeEvent}'s during state changes.
*/
public ActivatableSupport(A source, PropertyChangeSupport pcs) {
public ActivatableSupport(IActivatable source, PropertyChangeSupport pcs) {
if (source == null) {
throw new IllegalArgumentException("source may not be null.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
* interface, the generic type parameter of {@link IAdaptable.Bound}
* has to match this one.
*/
public class AdaptableSupport<A extends IAdaptable> {
public class AdaptableSupport<A extends IAdaptable> implements IDisposable {

private A source;
private PropertyChangeSupport pcs;
Expand Down Expand Up @@ -103,7 +103,7 @@ public <T> T getAdapter(AdapterKey<? super T> key) {
// an adapter instance may be registered under different keys
int adapterCount = new HashSet<T>(adaptersForTypeKey.values()).size();
if (adapterCount == 1) {
return (T) adaptersForTypeKey.values().iterator().next();
return adaptersForTypeKey.values().iterator().next();
}

return null;
Expand All @@ -124,7 +124,7 @@ public <T> T getAdapter(TypeToken<? super T> key) {
// an adapter instance may be registered under different keys
int adapterCount = new HashSet<T>(adaptersForTypeKey.values()).size();
if (adapterCount == 1) {
return (T) adaptersForTypeKey.values().iterator().next();
return adaptersForTypeKey.values().iterator().next();
}

if (adapterCount > 1) {
Expand Down Expand Up @@ -254,7 +254,7 @@ public void setAdapters(Map<AdapterKey<?>, Object> adaptersWithKeys,
+ ", as its neither a super interface nor a super class of its type.");
}
if (overwrite || !getAdapters().containsKey(key)) {
setAdapter((AdapterKey) key, (Object) adaptersWithKeys.get(key));
setAdapter((AdapterKey) key, adaptersWithKeys.get(key));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,17 @@
*******************************************************************************/
package org.eclipse.gef4.common.properties;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.HashMap;
import java.util.Map;

public class PropertyStoreSupport implements IPropertyStore {
public class PropertyStoreSupport {

private Map<String, Object> properties = new HashMap<String, Object>();
private PropertyChangeSupport pcs;

public PropertyStoreSupport(Object source) {
pcs = new PropertyChangeSupport(source);
public PropertyStoreSupport(IPropertyStore source, PropertyChangeSupport pcs) {
this.pcs = pcs;
}

public Object getProperty(String name) {
Expand All @@ -40,15 +39,4 @@ public void setProperty(String propertyName, Object newValue) {
pcs.firePropertyChange(propertyName, oldValue, newValue);
}
}

@Override
public void addPropertyChangeListener(PropertyChangeListener listener) {
pcs.addPropertyChangeListener(listener);
}

@Override
public void removePropertyChangeListener(PropertyChangeListener listener) {
pcs.removePropertyChangeListener(listener);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public abstract class AbstractLayoutContext implements ILayoutContext {
private final List<Runnable> preLayoutPass = new ArrayList<Runnable>();
private final List<ILayoutFilter> layoutFilters = new ArrayList<ILayoutFilter>();

protected PropertyStoreSupport pss = new PropertyStoreSupport(this);
protected PropertyChangeSupport pcs = new PropertyChangeSupport(this);
protected PropertyStoreSupport pss = new PropertyStoreSupport(this, pcs);

public void addContextListener(IContextListener listener) {
lls.addContextListener(listener);
Expand Down Expand Up @@ -359,7 +359,8 @@ public void setProperty(String name, Object value) {
pcs.firePropertyChange(name, oldValue, value);
}

public void setStaticLayoutAlgorithm(ILayoutAlgorithm staticLayoutAlgorithm) {
public void setStaticLayoutAlgorithm(
ILayoutAlgorithm staticLayoutAlgorithm) {
ILayoutAlgorithm oldStaticLayoutAlgorithm = this.staticLayoutAlgorithm;
if (oldStaticLayoutAlgorithm != staticLayoutAlgorithm) {
this.staticLayoutAlgorithm = staticLayoutAlgorithm;
Expand All @@ -373,7 +374,7 @@ public void unschedulePostLayoutPass(Runnable runnable) {
if (!postLayoutPass.contains(runnable)) {
new IllegalArgumentException(
"Given Runnable is not contained in the list.")
.printStackTrace();
.printStackTrace();
}
postLayoutPass.remove(runnable);
}
Expand All @@ -382,7 +383,7 @@ public void unschedulePreLayoutPass(Runnable runnable) {
if (!preLayoutPass.contains(runnable)) {
new IllegalArgumentException(
"Given Runnable is not contained in the list.")
.printStackTrace();
.printStackTrace();
}
preLayoutPass.remove(runnable);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,10 @@
public abstract class AbstractDomain<VR> implements IDomain<VR> {

protected PropertyChangeSupport pcs = new PropertyChangeSupport(this);

private ActivatableSupport acs = new ActivatableSupport(this, pcs);
private AdaptableSupport<IDomain<VR>> ads = new AdaptableSupport<IDomain<VR>>(
this, pcs);

private ActivatableSupport<IDomain<VR>> acs = new ActivatableSupport<IDomain<VR>>(
this, pcs);

private IOperationHistory operationHistory;
private IUndoContext undoContext;
private ForwardUndoCompositeOperation transaction;
Expand Down Expand Up @@ -88,8 +85,8 @@ public void closeExecutionTransaction(ITool<VR> tool) {
// check if the transaction has an effect (or is empty)
if (transaction != null && !transaction.getOperations().isEmpty()) {
// adjust the label
transaction.setLabel(transaction.getOperations().iterator().next()
.getLabel());
transaction.setLabel(
transaction.getOperations().iterator().next().getLabel());
// successfully close operation
getOperationHistory().closeOperation(true, true,
IOperationHistory.EXECUTE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,16 @@
* @param <V>
* The visual node used by this {@link AbstractVisualPart}.
*/
public abstract class AbstractVisualPart<VR, V extends VR> implements
IVisualPart<VR, V> {
public abstract class AbstractVisualPart<VR, V extends VR>
implements IVisualPart<VR, V> {

private static final String DEFAULT_ANCHORAGE_ROLE = "default";

protected PropertyChangeSupport pcs = new PropertyChangeSupport(this);

private ActivatableSupport acs = new ActivatableSupport(this, pcs);
private AdaptableSupport<IVisualPart<VR, V>> ads = new AdaptableSupport<IVisualPart<VR, V>>(
this, pcs);

private ActivatableSupport<IVisualPart<VR, V>> acs = new ActivatableSupport<IVisualPart<VR, V>>(
this, pcs);

private IVisualPart<VR, ? extends VR> parent;
private List<IVisualPart<VR, ? extends VR>> children;

Expand Down Expand Up @@ -120,8 +117,8 @@ public void addAnchorage(IVisualPart<VR, ? extends VR> anchorage,
}

// copy anchorages by role (required for the change notification)
SetMultimap<IVisualPart<VR, ? extends VR>, String> oldAnchorages = anchorages == null ? HashMultimap
.<IVisualPart<VR, ? extends VR>, String> create()
SetMultimap<IVisualPart<VR, ? extends VR>, String> oldAnchorages = anchorages == null
? HashMultimap.<IVisualPart<VR, ? extends VR>, String> create()
: HashMultimap.create(anchorages);

if (oldAnchorages.containsEntry(anchorage, role)) {
Expand Down Expand Up @@ -154,9 +151,9 @@ private void addAnchorageWithoutNotify(
@Override
public void addAnchored(IVisualPart<VR, ? extends VR> anchored) {
// copy anchoreds (required for the change notification)
Multiset<IVisualPart<VR, ? extends VR>> oldAnchoreds = anchoreds == null ? HashMultiset
.<IVisualPart<VR, ? extends VR>> create() : HashMultiset
.create(anchoreds);
Multiset<IVisualPart<VR, ? extends VR>> oldAnchoreds = anchoreds == null
? HashMultiset.<IVisualPart<VR, ? extends VR>> create()
: HashMultiset.create(anchoreds);

// determine the viewer before adding the anchored
IViewer<VR> oldViewer = getViewer();
Expand All @@ -172,7 +169,8 @@ public void addAnchored(IVisualPart<VR, ? extends VR> anchored) {
register(newViewer);
}

pcs.firePropertyChange(ANCHOREDS_PROPERTY, oldAnchoreds, getAnchoreds());
pcs.firePropertyChange(ANCHOREDS_PROPERTY, oldAnchoreds,
getAnchoreds());
}

@Override
Expand Down Expand Up @@ -224,7 +222,8 @@ public void addChildren(
* The child's position
* @see #addChild(IVisualPart, int)
*/
protected void addChildVisual(IVisualPart<VR, ? extends VR> child, int index) {
protected void addChildVisual(IVisualPart<VR, ? extends VR> child,
int index) {
throw new UnsupportedOperationException(
"Need to properly implement addChildVisual(IVisualPart, int) for "
+ this.getClass());
Expand Down Expand Up @@ -342,8 +341,9 @@ public <T> Map<AdapterKey<? extends T>, T> getAdapters(
public Multiset<IVisualPart<VR, ? extends VR>> getAnchoreds() {
if (anchoreds == null) {
return Multisets
.<IVisualPart<VR, ? extends VR>> unmodifiableMultiset(HashMultiset
.<IVisualPart<VR, ? extends VR>> create());
.<IVisualPart<VR, ? extends VR>> unmodifiableMultiset(
HashMultiset
.<IVisualPart<VR, ? extends VR>> create());
}
return Multisets.unmodifiableMultiset(anchoreds);
}
Expand Down Expand Up @@ -468,8 +468,8 @@ public void removeAnchorage(IVisualPart<VR, ? extends VR> anchorage,
}

// copy anchorages (required for the change notification)
SetMultimap<IVisualPart<VR, ? extends VR>, String> oldAnchorages = anchorages == null ? HashMultimap
.<IVisualPart<VR, ? extends VR>, String> create()
SetMultimap<IVisualPart<VR, ? extends VR>, String> oldAnchorages = anchorages == null
? HashMultimap.<IVisualPart<VR, ? extends VR>, String> create()
: HashMultimap.create(anchorages);

if (!oldAnchorages.containsEntry(anchorage, role)) {
Expand Down Expand Up @@ -506,9 +506,9 @@ private void removeAnchorageWithoutNotify(
@Override
public void removeAnchored(IVisualPart<VR, ? extends VR> anchored) {
// copy anchoreds (required for the change notification)
Multiset<IVisualPart<VR, ? extends VR>> oldAnchoreds = anchoreds == null ? HashMultiset
.<IVisualPart<VR, ? extends VR>> create() : HashMultiset
.create(anchoreds);
Multiset<IVisualPart<VR, ? extends VR>> oldAnchoreds = anchoreds == null
? HashMultiset.<IVisualPart<VR, ? extends VR>> create()
: HashMultiset.create(anchoreds);

// determine viewer before and after removing the anchored
IViewer<VR> oldViewer = getViewer();
Expand All @@ -526,7 +526,8 @@ public void removeAnchored(IVisualPart<VR, ? extends VR> anchored) {
anchoreds = null;
}

pcs.firePropertyChange(ANCHOREDS_PROPERTY, oldAnchoreds, getAnchoreds());
pcs.firePropertyChange(ANCHOREDS_PROPERTY, oldAnchoreds,
getAnchoreds());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,17 +42,14 @@
* The visual root node of the UI toolkit used, e.g.
* javafx.scene.Node in case of JavaFX.
*/
public abstract class AbstractViewer<VR> implements IViewer<VR>,
IAdaptable.Bound<IDomain<VR>> {
public abstract class AbstractViewer<VR>
implements IViewer<VR>, IAdaptable.Bound<IDomain<VR>> {

protected PropertyChangeSupport pcs = new PropertyChangeSupport(this);

private ActivatableSupport acs = new ActivatableSupport(this, pcs);
private AdaptableSupport<IViewer<VR>> ads = new AdaptableSupport<IViewer<VR>>(
this, pcs);

private ActivatableSupport<IViewer<VR>> acs = new ActivatableSupport<IViewer<VR>>(
this, pcs);

private Map<Object, IContentPart<VR, ? extends VR>> contentsToContentPartMap = new IdentityHashMap<Object, IContentPart<VR, ? extends VR>>();
private Map<VR, IVisualPart<VR, ? extends VR>> visualsToVisualPartMap = new HashMap<VR, IVisualPart<VR, ? extends VR>>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package org.eclipse.gef4.zest.fx.layout;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.util.Map.Entry;

import org.eclipse.gef4.common.properties.PropertyStoreSupport;
Expand All @@ -26,15 +27,15 @@ public class GraphEdgeLayout implements IConnectionLayout {

private GraphLayoutContext context;
private Edge edge;
private PropertyStoreSupport pss = new PropertyStoreSupport(this);
private PropertyChangeSupport pcs = new PropertyChangeSupport(this);
private PropertyStoreSupport pss = new PropertyStoreSupport(this, pcs);

public GraphEdgeLayout(GraphLayoutContext context, Edge edge) {
this.context = context;
this.edge = edge;

// graph directed?
Object type = context.getGraph().getAttrs()
.get(ZestProperties.GRAPH_TYPE);
Object type = context.getGraph().getAttrs().get(ZestProperties.GRAPH_TYPE);
if (type == ZestProperties.GRAPH_TYPE_DIRECTED) {
setProperty(LayoutProperties.DIRECTED_PROPERTY, true);
}
Expand All @@ -47,7 +48,7 @@ public GraphEdgeLayout(GraphLayoutContext context, Edge edge) {

@Override
public void addPropertyChangeListener(PropertyChangeListener listener) {
pss.addPropertyChangeListener(listener);
pcs.addPropertyChangeListener(listener);
}

public Edge getEdge() {
Expand All @@ -71,7 +72,7 @@ public INodeLayout getTarget() {

@Override
public void removePropertyChangeListener(PropertyChangeListener listener) {
pss.removePropertyChangeListener(listener);
pcs.removePropertyChangeListener(listener);
}

@Override
Expand Down
Loading

0 comments on commit 7fb61f2

Please sign in to comment.