diff options
author | Cedric Dumoulin | 2013-10-29 13:12:45 +0000 |
---|---|---|
committer | Cedric Dumoulin | 2014-01-27 13:54:21 +0000 |
commit | 8a90e1eda0a789fea36d7250d55b718d46083eb6 (patch) | |
tree | 15e262b232b465297af40534479ea58f44b06ad1 /extraplugins/layers | |
parent | 011aecb533b6240e9203bace7a397ec561faab1c (diff) | |
download | org.eclipse.papyrus-8a90e1eda0a789fea36d7250d55b718d46083eb6.tar.gz org.eclipse.papyrus-8a90e1eda0a789fea36d7250d55b718d46083eb6.tar.xz org.eclipse.papyrus-8a90e1eda0a789fea36d7250d55b718d46083eb6.zip |
organize imports
Diffstat (limited to 'extraplugins/layers')
7 files changed, 1416 insertions, 1415 deletions
diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/INotationDiagramRemovedEventListener.java b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/INotationDiagramRemovedEventListener.java index 2780035393a..0bb361f8f97 100644 --- a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/INotationDiagramRemovedEventListener.java +++ b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/INotationDiagramRemovedEventListener.java @@ -1,36 +1,34 @@ -/*******************************************************************************
- * Copyright (c) 2013 CEA LIST.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr
- ******************************************************************************/
-package org.eclipse.papyrus.layers.runtime;
-
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.resource.Resource;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel;
-import org.eclipse.papyrus.layers.stackmodel.layers.LayersStack;
-import org.eclipse.papyrus.layers.stackmodel.layers.LayersStackApplication;
-
-
-/**
- * Class implementing this interface can listen to diagram removed event from a {@link Resource}.
- *
- * @author cedric dumoulin
- *
- */
-public interface INotationDiagramRemovedEventListener {
-
- /**
- * Called by events when a {@link Diagram} is removed from the {@link NotationModel}
- * @param msg
- */
- public void diagramRemoved(Notification msg) ;
-
-
-}
+/******************************************************************************* + * Copyright (c) 2013 CEA LIST. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Cedric Dumoulin Cedric.dumoulin@lifl.fr + ******************************************************************************/ +package org.eclipse.papyrus.layers.runtime; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.resource.Resource; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.papyrus.infra.gmfdiag.common.model.NotationModel; + + +/** + * Class implementing this interface can listen to diagram removed event from a {@link Resource}. + * + * @author cedric dumoulin + * + */ +public interface INotationDiagramRemovedEventListener { + + /** + * Called by events when a {@link Diagram} is removed from the {@link NotationModel} + * @param msg + */ + public void diagramRemoved(Notification msg) ; + + +} diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/LayerStackSynchronizer.java b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/LayerStackSynchronizer.java index 68eca88a78a..06cae601d6e 100644 --- a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/LayerStackSynchronizer.java +++ b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/LayerStackSynchronizer.java @@ -1,463 +1,462 @@ -/*******************************************************************************
- * Copyright (c) 2013 CEA LIST.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr
- ******************************************************************************/
-package org.eclipse.papyrus.layers.runtime;
-
-import java.util.List;
-
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.layers.stackmodel.BadStateException;
-import org.eclipse.papyrus.layers.stackmodel.LayersException;
-import org.eclipse.papyrus.layers.stackmodel.NotFoundException;
-import org.eclipse.papyrus.layers.stackmodel.command.ComputePropertyValueCommand;
-import org.eclipse.papyrus.layers.stackmodel.layers.AbstractLayer;
-import org.eclipse.papyrus.layers.stackmodel.layers.Layer;
-import org.eclipse.papyrus.layers.stackmodel.layers.LayersStack;
-import org.eclipse.papyrus.layers.stackmodel.layers.LayersStackApplication;
-import org.eclipse.papyrus.layers.stackmodel.layers.Property;
-import org.eclipse.papyrus.layers.stackmodel.layers.PropertySetter;
-import org.eclipse.papyrus.layers.stackmodel.notifier.DiagramViewEventNotifier;
-import org.eclipse.papyrus.layers.stackmodel.notifier.IDiagramViewEventListener;
-
-
-/**
- * This class is used to synchronize the diagram's properties when something
- * change in the LayerStack.
- * It listen on events from {@link LayersStack} and {@link Diagram}.
- *
- * @author cedric dumoulin
- *
- */
-public class LayerStackSynchronizer implements IDiagramViewEventListener, ILayersModelEventListener {
-
- /**
- * The observed diagram.
- */
- protected Diagram diagram;
-
- /**
- * The observed LayerStack.
- */
- protected LayersStack layersStack;
-
- /**
- * The application object. Required by some methods.
- * <br>
- * Method requiring this object must check it before any use,
- * as this object can be null.
- *
- */
- protected LayersStackApplication application;
-
- /**
- * The notifier of layer model events.
- */
- protected LayersModelEventNotifier layersModelEventNotifier;
-
- /**
- * The notifier of layer model events.
- */
- protected DiagramViewEventNotifier diagramViewEventNotifier;
-
- /**
- * Constructor.
- *
- * @param layersStack The layerStack to listen to. It should have an associated diagram.
- *
- */
- public LayerStackSynchronizer(LayersStack layersStack) {
- this.diagram = layersStack.getDiagram();
- this.layersStack = layersStack;
-
- // try to get the application object
- // it is the container of the layerStack
- application = (LayersStackApplication)layersStack.eContainer();
-
-
- activate();
-// System.err.println("LayerStackSynchronizer( " +diagram.getName()+ " ) started");
- }
-
-
-
- /**
- * @return the diagram
- */
- public Diagram getDiagram() {
- return diagram;
- }
-
-
-
- /**
- * @return the layersStack
- */
- public LayersStack getLayersStack() {
- return layersStack;
- }
-
-
-
- /**
- * Activate the listeners.
- *
- */
- protected void activate() {
-
- diagramViewEventNotifier = new DiagramViewEventNotifier(diagram);
- diagramViewEventNotifier.addEventListener(this);
-
- layersModelEventNotifier = new LayersModelEventNotifier(layersStack);
- layersModelEventNotifier.addLayersModelEventListener(this);
-
- }
-
- /**
- * Deactivate listeners
- */
- protected void deactivate() {
- diagramViewEventNotifier.removeEventListener(this);
- diagramViewEventNotifier = null;
-
- layersModelEventNotifier.removeLayersModelEventListener(this);
- layersModelEventNotifier = null;
- }
-
- /**
- * Dispose the synchronizer
- */
- protected void dispose() {
- // Deactivate listeners
- deactivate();
- diagramViewEventNotifier = null;
- layersModelEventNotifier = null;
- }
-
- /**
- * Return true if the object is disposed.
- * @return
- */
- protected boolean isDisposed() {
- return diagramViewEventNotifier == null;
- }
-
- /**
- * Check if the application object is not null.
- * Throw an exception if the application object is null.
- * <br>
- * In normal use, the Application is the container of the LayerStack.
- * It is set in the constructor of this class.
- *
- * @throws BadStateException
- */
- protected void checkApplication() throws BadStateException {
- if( application == null) {
- throw new BadStateException("Attempt to call a method requireing the 'application object, but the Application object is not set. You must provide a LayerStack contained in its Application.");
- }
- }
- /**
- *
- * @see org.eclipse.papyrus.layers.runtime.ILayersModelEventListener#propertyValueAdded(org.eclipse.emf.common.notify.Notification)
- *
- * @param notification
- */
- @Override
- public void propertyValueAdded(Notification notification) {
- System.out.println("propertyValueAdded " + notification.getNewValue());
-
- try {
- // Name of the property
- String propertyName = LayersModelEventUtils.PropertyEvents.getPropertyNameFromValueAdd(notification);
-
- // Need to recompute the associated views
- AbstractLayer layer = LayersModelEventUtils.PropertyEvents.getAbstractLayer(notification);
- List<View> views = layer.getViews();
- if( views.size() == 0) {
- return;
- }
-
- checkApplication();
- Property property = application.getPropertyRegistry().getProperty(propertyName);
-
- List<ComputePropertyValueCommand> commands = layersStack.getViewsComputePropertyValueCommand(views, property);
-
- PropertySetter setter = application.getPropertySetterRegistry().getPropertySetter(property);
-
- // Walk each view and set the property
- for( int i=0; i<views.size(); i++) {
- setter.setValue(views.get(i), commands.get(i).getCmdValue() );
- }
- } catch (NotFoundException e) {
- System.err.println(e.getMessage());
- } catch (LayersException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
-
-
- @Override
- public void propertyValueRemoved(Notification notification) {
- System.out.println("propertyValueRemoved " + notification.getOldValue());
-
- try {
- // Name of the property
- String propertyName = LayersModelEventUtils.PropertyEvents.getPropertyNameFromValueRemove(notification);
-
- // Need to recompute the associated views
- AbstractLayer layer = LayersModelEventUtils.PropertyEvents.getAbstractLayer(notification);
- List<View> views = layer.getViews();
- if( views.size() == 0) {
- return;
- }
-
- checkApplication();
- Property property = application.getPropertyRegistry().getProperty(propertyName);
-
- List<ComputePropertyValueCommand> commands = layersStack.getViewsComputePropertyValueCommand(views, property);
- if( commands == null) {
- // no command
- return;
- }
-
- PropertySetter setter = application.getPropertySetterRegistry().getPropertySetter(property);
-
- // Walk each view and set the property
- for( int i=0; i<views.size(); i++) {
- // A command can be null
- ComputePropertyValueCommand cmd = commands.get(i).getCmdValue();
- if( cmd != null ) {
- setter.setValue(views.get(i), cmd.getCmdValue() );
- }
-
- }
- } catch (NotFoundException e) {
- System.err.println(e.getMessage());
- } catch (LayersException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
-
-
- @Override
- public void propertyValueChanged(Notification notification) {
- System.out.println("propertyValueChanged " + notification.getNewValue());
-
- try {
- // Name of the property
- String propertyName = LayersModelEventUtils.PropertyEvents.getPropertyNameFromValueSet(notification);
-
- // Need to recompute the associated views
- AbstractLayer layer = LayersModelEventUtils.PropertyEvents.getAbstractLayer(notification);
- List<View> views = layer.getViews();
- if( views.size() == 0) {
- return;
- }
-
- checkApplication();
- Property property = application.getPropertyRegistry().getProperty(propertyName);
-
- List<ComputePropertyValueCommand> commands = layersStack.getViewsComputePropertyValueCommand(views, property);
-
- PropertySetter setter = application.getPropertySetterRegistry().getPropertySetter(property);
-
- // Walk each view and set the property
- for( int i=0; i<views.size(); i++) {
- setter.setValue(views.get(i), commands.get(i).getCmdValue() );
- }
- } catch (NotFoundException e) {
- System.err.println(e.getMessage());
- } catch (LayersException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
-
-
- @Override
- public void layerAdded(Notification notification) {
- System.out.println(this.getClass().getSimpleName() + " layerAdded(not implemented) " + notification.getNewValue());
-
- }
-
-
-
- @Override
- public void layerRemoved(Notification notification) {
- System.out.println(this.getClass().getSimpleName() + " layerRemoved(not implemented) " + notification.getOldValue());
-
- }
-
-
-
- /**
- *
- * @see org.eclipse.papyrus.layers.runtime.ILayersModelEventListener#layerMoved(org.eclipse.emf.common.notify.Notification)
- *
- * @param notification
- */
- @Override
- public void layerMoved(Notification notification) {
- System.out.println(this.getClass().getSimpleName() + " layerMoved(not implemented) " + notification.getNewValue());
-
- }
-
- /**
- *
- * @see org.eclipse.papyrus.layers.runtime.ILayersModelEventListener#layerSet(org.eclipse.emf.common.notify.Notification)
- *
- * @param notification
- */
- @Override
- public void layerSet(Notification notification) {
- System.out.println(this.getClass().getSimpleName() + " layerSet(not implemented) " + notification.getNewValue());
-
- }
-
-
-
- /**
- *
- * @see org.eclipse.papyrus.layers.runtime.ILayersModelEventListener#viewAddedToLayer(org.eclipse.emf.common.notify.Notification)
- *
- * @param notification
- */
- @Override
- public void viewAddedToLayer(Notification notification) {
- System.out.println("viewAddedToLayer" + notification.getNewValue());
-
- // We need to find the view, the layer in which it is added,
- // and the properties attached to this layer.
- // Then, we compute this property and set it to the view.
- try {
- AbstractLayer layer = LayersModelEventUtils.PropertyEvents.getAbstractLayer(notification);
- View view = LayersModelEventUtils.ViewEvents.getViewAdded(notification);
-
-
- checkApplication();
- List<Property> properties = layer.getAttachedProperties();
-
- List<ComputePropertyValueCommand> commands = layersStack.getPropertiesComputePropertyValueCommand(view, properties);
- if(commands == null) {
- // No property to set
- return;
- }
-
- PropertySetter setter;
- // Walk each cmd and set the property
- for( int i=0; i<commands.size(); i++) {
- try {
- Property property = properties.get(i);
- setter = application.getPropertySetterRegistry().getPropertySetter(property);
- setter.setValue(view, commands.get(i).getCmdValue() );
- } catch (NotFoundException e) {
- // No setter found
- System.err.println(e.getMessage());
- } catch (NullPointerException e) {
- // A command is null
- }
- }
- } catch (LayersException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
-
-
- /**
- *
- * @see org.eclipse.papyrus.layers.runtime.ILayersModelEventListener#viewRemovedFromLayer(org.eclipse.emf.common.notify.Notification)
- *
- * @param notification
- */
- @Override
- public void viewRemovedFromLayer(Notification notification) {
- // We need to find the view, the layer in which it is added,
- // and the properties attached to this layer.
- // Then, we compute this property and set it to the view.
- try {
- AbstractLayer layer = LayersModelEventUtils.PropertyEvents.getAbstractLayer(notification);
-// View view = LayersModelEventUtils.ViewEvents.getViewRemoved(notification);
-
-
-// List<Property> properties = layer.getAttachedProperties();
-
- // Here we need to reset default values to the view
- // TODO: reset default values for specified properties.
- } catch (LayersException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
-
-
- /**
- *
- * @see org.eclipse.papyrus.layers.runtime.ILayersModelEventListener#viewMovedBetweenLayer(org.eclipse.emf.common.notify.Notification)
- *
- * @param notification
- */
- @Override
- public void viewMovedBetweenLayer(Notification notification) {
- System.out.println(this.getClass().getSimpleName() + " viewMovedBetweenLayer(not implemented) " + notification.getNewValue());
-
- }
-
-
-
- /**
- *
- * @see org.eclipse.papyrus.layers.stackmodel.notifier.IDiagramViewEventListener#diagramViewAdded(org.eclipse.emf.common.notify.Notification)
- *
- * @param msg
- */
- @Override
- public void diagramViewAdded(Notification msg) {
- System.out.println(this.getClass().getSimpleName() + " diagramViewAdded(not implemented) " + msg.getNewValue());
-
- // WARNING !!!
- // Some filtering should be done on the event.
- // When a View is removed, the event is sent for each of its parts. This
- // result in multiple events receiving.
- // Only events on Shape and Links are useful. So, we need to
- // do some filtering (in the DiagramViewEventNotifier ?).
- }
-
-
-
- /**
- *
- * @see org.eclipse.papyrus.layers.stackmodel.notifier.IDiagramViewEventListener#diagramViewRemoved(org.eclipse.emf.common.notify.Notification)
- *
- * @param msg
- */
- @Override
- public void diagramViewRemoved(Notification msg) {
- System.out.println(this.getClass().getSimpleName() + " diagramViewRemoved(not implemented) " + msg.getOldValue());
-
- // WARNING !!!
- // Some filtering should be done on the event.
- // When a View is removed, the event is sent for each of its parts. This
- // result in multiple events receiving.
- // Only events on Shape and Links are useful. So, we need to
- // do some filtering (in the DiagramViewEventNotifier ?).
- }
-
-
-
-}
+/******************************************************************************* + * Copyright (c) 2013 CEA LIST. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Cedric Dumoulin Cedric.dumoulin@lifl.fr + ******************************************************************************/ +package org.eclipse.papyrus.layers.runtime; + +import java.util.List; + +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.gmf.runtime.notation.View; +import org.eclipse.papyrus.layers.stackmodel.BadStateException; +import org.eclipse.papyrus.layers.stackmodel.LayersException; +import org.eclipse.papyrus.layers.stackmodel.NotFoundException; +import org.eclipse.papyrus.layers.stackmodel.command.ComputePropertyValueCommand; +import org.eclipse.papyrus.layers.stackmodel.layers.AbstractLayer; +import org.eclipse.papyrus.layers.stackmodel.layers.LayersStack; +import org.eclipse.papyrus.layers.stackmodel.layers.LayersStackApplication; +import org.eclipse.papyrus.layers.stackmodel.layers.Property; +import org.eclipse.papyrus.layers.stackmodel.layers.PropertySetter; +import org.eclipse.papyrus.layers.stackmodel.notifier.DiagramViewEventNotifier; +import org.eclipse.papyrus.layers.stackmodel.notifier.IDiagramViewEventListener; + + +/** + * This class is used to synchronize the diagram's properties when something + * change in the LayerStack. + * It listen on events from {@link LayersStack} and {@link Diagram}. + * + * @author cedric dumoulin + * + */ +public class LayerStackSynchronizer implements IDiagramViewEventListener, ILayersModelEventListener { + + /** + * The observed diagram. + */ + protected Diagram diagram; + + /** + * The observed LayerStack. + */ + protected LayersStack layersStack; + + /** + * The application object. Required by some methods. + * <br> + * Method requiring this object must check it before any use, + * as this object can be null. + * + */ + protected LayersStackApplication application; + + /** + * The notifier of layer model events. + */ + protected LayersModelEventNotifier layersModelEventNotifier; + + /** + * The notifier of layer model events. + */ + protected DiagramViewEventNotifier diagramViewEventNotifier; + + /** + * Constructor. + * + * @param layersStack The layerStack to listen to. It should have an associated diagram. + * + */ + public LayerStackSynchronizer(LayersStack layersStack) { + this.diagram = layersStack.getDiagram(); + this.layersStack = layersStack; + + // try to get the application object + // it is the container of the layerStack + application = (LayersStackApplication)layersStack.eContainer(); + + + activate(); +// System.err.println("LayerStackSynchronizer( " +diagram.getName()+ " ) started"); + } + + + + /** + * @return the diagram + */ + public Diagram getDiagram() { + return diagram; + } + + + + /** + * @return the layersStack + */ + public LayersStack getLayersStack() { + return layersStack; + } + + + + /** + * Activate the listeners. + * + */ + protected void activate() { + + diagramViewEventNotifier = new DiagramViewEventNotifier(diagram); + diagramViewEventNotifier.addEventListener(this); + + layersModelEventNotifier = new LayersModelEventNotifier(layersStack); + layersModelEventNotifier.addLayersModelEventListener(this); + + } + + /** + * Deactivate listeners + */ + protected void deactivate() { + diagramViewEventNotifier.removeEventListener(this); + diagramViewEventNotifier = null; + + layersModelEventNotifier.removeLayersModelEventListener(this); + layersModelEventNotifier = null; + } + + /** + * Dispose the synchronizer + */ + protected void dispose() { + // Deactivate listeners + deactivate(); + diagramViewEventNotifier = null; + layersModelEventNotifier = null; + } + + /** + * Return true if the object is disposed. + * @return + */ + protected boolean isDisposed() { + return diagramViewEventNotifier == null; + } + + /** + * Check if the application object is not null. + * Throw an exception if the application object is null. + * <br> + * In normal use, the Application is the container of the LayerStack. + * It is set in the constructor of this class. + * + * @throws BadStateException + */ + protected void checkApplication() throws BadStateException { + if( application == null) { + throw new BadStateException("Attempt to call a method requireing the 'application object, but the Application object is not set. You must provide a LayerStack contained in its Application."); + } + } + /** + * + * @see org.eclipse.papyrus.layers.runtime.ILayersModelEventListener#propertyValueAdded(org.eclipse.emf.common.notify.Notification) + * + * @param notification + */ + @Override + public void propertyValueAdded(Notification notification) { + System.out.println("propertyValueAdded " + notification.getNewValue()); + + try { + // Name of the property + String propertyName = LayersModelEventUtils.PropertyEvents.getPropertyNameFromValueAdd(notification); + + // Need to recompute the associated views + AbstractLayer layer = LayersModelEventUtils.PropertyEvents.getAbstractLayer(notification); + List<View> views = layer.getViews(); + if( views.size() == 0) { + return; + } + + checkApplication(); + Property property = application.getPropertyRegistry().getProperty(propertyName); + + List<ComputePropertyValueCommand> commands = layersStack.getViewsComputePropertyValueCommand(views, property); + + PropertySetter setter = application.getPropertySetterRegistry().getPropertySetter(property); + + // Walk each view and set the property + for( int i=0; i<views.size(); i++) { + setter.setValue(views.get(i), commands.get(i).getCmdValue() ); + } + } catch (NotFoundException e) { + System.err.println(e.getMessage()); + } catch (LayersException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + + + @Override + public void propertyValueRemoved(Notification notification) { + System.out.println("propertyValueRemoved " + notification.getOldValue()); + + try { + // Name of the property + String propertyName = LayersModelEventUtils.PropertyEvents.getPropertyNameFromValueRemove(notification); + + // Need to recompute the associated views + AbstractLayer layer = LayersModelEventUtils.PropertyEvents.getAbstractLayer(notification); + List<View> views = layer.getViews(); + if( views.size() == 0) { + return; + } + + checkApplication(); + Property property = application.getPropertyRegistry().getProperty(propertyName); + + List<ComputePropertyValueCommand> commands = layersStack.getViewsComputePropertyValueCommand(views, property); + if( commands == null) { + // no command + return; + } + + PropertySetter setter = application.getPropertySetterRegistry().getPropertySetter(property); + + // Walk each view and set the property + for( int i=0; i<views.size(); i++) { + // A command can be null + ComputePropertyValueCommand cmd = commands.get(i).getCmdValue(); + if( cmd != null ) { + setter.setValue(views.get(i), cmd.getCmdValue() ); + } + + } + } catch (NotFoundException e) { + System.err.println(e.getMessage()); + } catch (LayersException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + + + @Override + public void propertyValueChanged(Notification notification) { + System.out.println("propertyValueChanged " + notification.getNewValue()); + + try { + // Name of the property + String propertyName = LayersModelEventUtils.PropertyEvents.getPropertyNameFromValueSet(notification); + + // Need to recompute the associated views + AbstractLayer layer = LayersModelEventUtils.PropertyEvents.getAbstractLayer(notification); + List<View> views = layer.getViews(); + if( views.size() == 0) { + return; + } + + checkApplication(); + Property property = application.getPropertyRegistry().getProperty(propertyName); + + List<ComputePropertyValueCommand> commands = layersStack.getViewsComputePropertyValueCommand(views, property); + + PropertySetter setter = application.getPropertySetterRegistry().getPropertySetter(property); + + // Walk each view and set the property + for( int i=0; i<views.size(); i++) { + setter.setValue(views.get(i), commands.get(i).getCmdValue() ); + } + } catch (NotFoundException e) { + System.err.println(e.getMessage()); + } catch (LayersException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + + + @Override + public void layerAdded(Notification notification) { + System.out.println(this.getClass().getSimpleName() + " layerAdded(not implemented) " + notification.getNewValue()); + + } + + + + @Override + public void layerRemoved(Notification notification) { + System.out.println(this.getClass().getSimpleName() + " layerRemoved(not implemented) " + notification.getOldValue()); + + } + + + + /** + * + * @see org.eclipse.papyrus.layers.runtime.ILayersModelEventListener#layerMoved(org.eclipse.emf.common.notify.Notification) + * + * @param notification + */ + @Override + public void layerMoved(Notification notification) { + System.out.println(this.getClass().getSimpleName() + " layerMoved(not implemented) " + notification.getNewValue()); + + } + + /** + * + * @see org.eclipse.papyrus.layers.runtime.ILayersModelEventListener#layerSet(org.eclipse.emf.common.notify.Notification) + * + * @param notification + */ + @Override + public void layerSet(Notification notification) { + System.out.println(this.getClass().getSimpleName() + " layerSet(not implemented) " + notification.getNewValue()); + + } + + + + /** + * + * @see org.eclipse.papyrus.layers.runtime.ILayersModelEventListener#viewAddedToLayer(org.eclipse.emf.common.notify.Notification) + * + * @param notification + */ + @Override + public void viewAddedToLayer(Notification notification) { + System.out.println("viewAddedToLayer" + notification.getNewValue()); + + // We need to find the view, the layer in which it is added, + // and the properties attached to this layer. + // Then, we compute this property and set it to the view. + try { + AbstractLayer layer = LayersModelEventUtils.PropertyEvents.getAbstractLayer(notification); + View view = LayersModelEventUtils.ViewEvents.getViewAdded(notification); + + + checkApplication(); + List<Property> properties = layer.getAttachedProperties(); + + List<ComputePropertyValueCommand> commands = layersStack.getPropertiesComputePropertyValueCommand(view, properties); + if(commands == null) { + // No property to set + return; + } + + PropertySetter setter; + // Walk each cmd and set the property + for( int i=0; i<commands.size(); i++) { + try { + Property property = properties.get(i); + setter = application.getPropertySetterRegistry().getPropertySetter(property); + setter.setValue(view, commands.get(i).getCmdValue() ); + } catch (NotFoundException e) { + // No setter found + System.err.println(e.getMessage()); + } catch (NullPointerException e) { + // A command is null + } + } + } catch (LayersException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + + + /** + * + * @see org.eclipse.papyrus.layers.runtime.ILayersModelEventListener#viewRemovedFromLayer(org.eclipse.emf.common.notify.Notification) + * + * @param notification + */ + @Override + public void viewRemovedFromLayer(Notification notification) { + // We need to find the view, the layer in which it is added, + // and the properties attached to this layer. + // Then, we compute this property and set it to the view. + try { + AbstractLayer layer = LayersModelEventUtils.PropertyEvents.getAbstractLayer(notification); +// View view = LayersModelEventUtils.ViewEvents.getViewRemoved(notification); + + +// List<Property> properties = layer.getAttachedProperties(); + + // Here we need to reset default values to the view + // TODO: reset default values for specified properties. + } catch (LayersException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + + + /** + * + * @see org.eclipse.papyrus.layers.runtime.ILayersModelEventListener#viewMovedBetweenLayer(org.eclipse.emf.common.notify.Notification) + * + * @param notification + */ + @Override + public void viewMovedBetweenLayer(Notification notification) { + System.out.println(this.getClass().getSimpleName() + " viewMovedBetweenLayer(not implemented) " + notification.getNewValue()); + + } + + + + /** + * + * @see org.eclipse.papyrus.layers.stackmodel.notifier.IDiagramViewEventListener#diagramViewAdded(org.eclipse.emf.common.notify.Notification) + * + * @param msg + */ + @Override + public void diagramViewAdded(Notification msg) { + System.out.println(this.getClass().getSimpleName() + " diagramViewAdded(not implemented) " + msg.getNewValue()); + + // WARNING !!! + // Some filtering should be done on the event. + // When a View is removed, the event is sent for each of its parts. This + // result in multiple events receiving. + // Only events on Shape and Links are useful. So, we need to + // do some filtering (in the DiagramViewEventNotifier ?). + } + + + + /** + * + * @see org.eclipse.papyrus.layers.stackmodel.notifier.IDiagramViewEventListener#diagramViewRemoved(org.eclipse.emf.common.notify.Notification) + * + * @param msg + */ + @Override + public void diagramViewRemoved(Notification msg) { + System.out.println(this.getClass().getSimpleName() + " diagramViewRemoved(not implemented) " + msg.getOldValue()); + + // WARNING !!! + // Some filtering should be done on the event. + // When a View is removed, the event is sent for each of its parts. This + // result in multiple events receiving. + // Only events on Shape and Links are useful. So, we need to + // do some filtering (in the DiagramViewEventNotifier ?). + } + + + +} diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/LayersModelEventNotifier.java b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/LayersModelEventNotifier.java index 3a5cffac3f1..ae8ace2bb1f 100644 --- a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/LayersModelEventNotifier.java +++ b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/LayersModelEventNotifier.java @@ -1,398 +1,396 @@ -/*******************************************************************************
- * Copyright (c) 2013 CEA LIST.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr
- ******************************************************************************/
-package org.eclipse.papyrus.layers.runtime;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.eclipse.emf.common.notify.Adapter;
-import org.eclipse.emf.common.notify.Notification;
-import org.eclipse.emf.ecore.EObject;
-import org.eclipse.emf.ecore.util.EContentAdapter;
-import org.eclipse.gmf.runtime.notation.View;
-import org.eclipse.papyrus.layers.stackmodel.NotFoundException;
-import org.eclipse.papyrus.layers.stackmodel.layers.AbstractLayer;
-import org.eclipse.papyrus.layers.stackmodel.layers.Layer;
-import org.eclipse.papyrus.layers.stackmodel.layers.LayersPackage;
-import org.eclipse.papyrus.layers.stackmodel.layers.LayersStack;
-import org.eclipse.papyrus.layers.stackmodel.layers.TypeInstance;
-import org.eclipse.papyrus.layers.stackmodel.layers.impl.StringToTypeInstanceMapImpl;
-import org.eclipse.papyrus.layers.stackmodel.layers.util.ECoreUtils;
-
-
-/**
- * This class listen to a {@link LayersStack} and send event to listeners.
- *
- * @author cedric dumoulin
- *
- */
-public class LayersModelEventNotifier {
-
- /**
- * The observed {@link LayersStack}.
- */
- protected LayersStack layersStack;
-
- /**
- * List of listener to notify.
- */
- protected List<ILayersModelEventListener> listeners = new ArrayList<ILayersModelEventListener>();
-
- /**
- * listener on layers changes.
- *
- */
- protected Adapter layersListener = new EContentAdapter() {
-
- @Override
- public void notifyChanged(Notification notification) {
- System.err.println("event received " + notification.getFeature());
- // Self atttach
- super.notifyChanged(notification);
-
- // Check layers modification
- // There is two sources: LayerOperator::layers and LayersStack::layers
- if( notification.getFeature() == LayersPackage.eINSTANCE.getLayerOperator_Layers()
- || notification.getFeature() == LayersPackage.eINSTANCE.getLayersStack_Layers() ) {
- // LayerOperator::layers || LayersStack::layers
- // check the event type.
- switch(notification.getEventType()) {
- case Notification.SET:
- fireLayerSet(notification);
- break;
- case Notification.ADD:
- // A layer is added
- fireLayerAdded(notification);
- break;
- case Notification.REMOVE:
- // A layer is removed
- fireLayerRemoved(notification);
- break;
- case Notification.MOVE:
- // A layer is moved
- fireLayerMoved(notification);
- break;
- }
- }
- // Check view event
- // View event can by fired by: AbstractLayer::views
- else if (notification.getFeature() == LayersPackage.eINSTANCE.getAbstractLayer_Views() ) {
-
- // check the event type.
- switch(notification.getEventType()) {
- case Notification.ADD:
- // A layer is added
- // the concerned view
-// View view = (View)notification.getNewValue();
-// AbstractLayer layer = (AbstractLayer)notification.getNotifier()
-
- fireViewAddedToLayer(notification);
- break;
- case Notification.REMOVE:
- // A layer is removed
- // the concerned view
-// View view = (View)notification.getOldValue();
-// AbstractLayer layer = (AbstractLayer)notification.getNotifier()
-
- fireViewRemovedFromLayer(notification);
- break;
- }
-
- }
- // Check instance addition/deletion
- // instance event can by fired by: AbstractLayer::propertyValuesMap
- else if (notification.getFeature() == LayersPackage.eINSTANCE.getAbstractLayer_PropertyValueMap() ) {
- // check the event type.
- switch(notification.getEventType()) {
-// case Notification.SET:
-// {
-// // A key is added
-// break;
-// }
-// case Notification.UNSET:
-// // A key is added
-// break;
- case Notification.ADD:
- {
- // An entry is added
- StringToTypeInstanceMapImpl entry = (StringToTypeInstanceMapImpl)notification.getNewValue();
-// System.out.println("ADD" + entry.getValue()
-// + ", key=" + entry.getKey());
- // Add the corresponding instance to propertyValues
- //Layer layer = (Layer)notification.getNotifier();
- //String propertyName = entry.getKey();
- //TypeInstance propertyValue = (TypeInstance)entry.getValue();
- firePropertyValueAddedEvent(notification);
- break;
- }
- case Notification.REMOVE:
- {
- // An entry is removed
- StringToTypeInstanceMapImpl entry = (StringToTypeInstanceMapImpl)notification.getOldValue();
-// System.out.println("REMOVE" + entry.getValue()
-// + ", key=" + entry.getKey());
- // Add the corresponding instance to propertyValues
- //Layer layer = (Layer)notification.getNotifier();
- //String propertyName = entry.getKey();
- //TypeInstance propertyValue = (TypeInstance)entry.getValue();
- firePropertyValueRemoved(notification);
- break;
- }
- default:
- break;
- }
-
- }
- // Check property instance modification event
- // instance change event can by fired by: any modification in a subclass of TypeInstance
- else {
- try {
- // Lookup if the event comes from a type instance
- TypeInstance ancestor = (TypeInstance)ECoreUtils.lookupAncestorOfType((EObject)notification.getNotifier(), LayersPackage.eINSTANCE.getTypeInstance());
- // originating layer
- AbstractLayer layer = (AbstractLayer)ECoreUtils.lookupAncestorOfType((EObject)notification.getNotifier(), LayersPackage.eINSTANCE.getAbstractLayer());
- // or: layer = (AbstractLayer)ancestor.eContainer().eContainer().eContainer();
- // StringToTypeInstanceMapImpl entry = (StringToTypeInstanceMapImpl)ancestor.eContainer();
- //String propertyName = entry.getKey();
- //TypeInstance propertyValue = (TypeInstance)entry.getValue();
- //
-// String propertyName
- // check the event type.
- switch(notification.getEventType()) {
- case Notification.SET:
- // An instance value is set
- firePropertyValueChanged(notification);
- break;
- case Notification.ADD:
- // An instance value is set
- firePropertyValueChanged(notification);
- break;
- case Notification.REMOVE:
- // An instance value is set
- firePropertyValueChanged(notification);
- break;
- }
- } catch (NotFoundException e) {
- // lookupAncestorOfType() found nothing
- // silently fail
- }
-
-
-
- }
-
- }
- };
-
- /**
- * Constructor.
- *
- * @param layersStack The observed {@link LayersStack}.
- */
- public LayersModelEventNotifier(LayersStack layersStack) {
- this.layersStack = layersStack;
- activate();
- }
-
- /**
- * setup the listeners.
- */
- protected void activate() {
- layersStack.eAdapters().add(layersListener);
-
- }
-
- /**
- * remove the listeners.
- */
- protected void deactivate() {
- layersStack.eAdapters().remove(layersListener);
-
- }
-
- /**
- * Dispose this object.
- */
- public void dispose() {
-
- deactivate();
- listeners.clear();
- layersListener = null;
- }
-
- /**
- * Return true if the object is disposed.
- * @return
- */
- public boolean isDisposed() {
- return layersListener==null;
- }
-
- /**
- * Add the specified listener to the list of listener.
- * Do not add it if the listener is already in the list.
- *
- * @param listener
- */
- public void addLayersModelEventListener(ILayersModelEventListener listener) {
-
- if(listener == null ) {
- return;
- }
-
- // Check if exist
- if( listeners.contains(listener)) {
- return;
- }
-
- listeners.add(listener);
- }
-
- /**
- * Remove the specified listener from the list of listeners.
- * @param listener
- */
- public void removeLayersModelEventListener(ILayersModelEventListener listener) {
-
- listeners.remove(listener);
- }
- /**
- * Method called when a value is added to one layer.
- * The vent contains: the layer, the property name, the new value.
- *
- * @param notification
- */
- public void firePropertyValueAddedEvent( Notification notification ) {
-
- for(ILayersModelEventListener listener : listeners) {
- listener.propertyValueAdded(notification);
- }
- }
-
- /**
- * Method called when a value is removed from one layer.
- * The vent contains: the layer, the property name, the new value.
- *
- * @param notification
- */
- public void firePropertyValueRemoved( Notification notification ) {
-
- for(ILayersModelEventListener listener : listeners) {
- listener.propertyValueRemoved(notification);
- }
- }
-
- /**
- * Method called when a value is changed in one layer.
- * The vent contains: the layer, the property name, the new value.
- *
- * @param notification
- */
- public void firePropertyValueChanged( Notification notification ) {
-
- for(ILayersModelEventListener listener : listeners) {
- listener.propertyValueChanged(notification);
- }
- }
-
- /**
- * Method called when a layer is added to one layer.
- * The event contains: the layer.
- *
- * @param notification
- */
- public void fireLayerSet( Notification notification ) {
-
- for(ILayersModelEventListener listener : listeners) {
- listener.layerSet(notification);
- }
- }
-
- /**
- * Method called when a layer is added to one layer.
- * The event contains: the layer.
- *
- * @param notification
- */
- public void fireLayerAdded( Notification notification ) {
-
- for(ILayersModelEventListener listener : listeners) {
- listener.layerAdded(notification);
- }
- }
-
- /**
- * Method called when a layer is removed from one layer.
- * The event contains: the layer.
- *
- * @param notification
- */
- public void fireLayerRemoved( Notification notification ) {
-
- for(ILayersModelEventListener listener : listeners) {
- listener.layerRemoved(notification);
- }
- }
-
- /**
- * Method called when a layer is moved in LayerStack.
- * The event contains: the layer.
- *
- * @param notification
- */
- public void fireLayerMoved( Notification notification ) {
-
- for(ILayersModelEventListener listener : listeners) {
- listener.layerMoved(notification);
- }
- }
-
-
- /**
- * Method called when a view is added to one layer.
- * The event contains: the layer, the view.
- *
- * @param notification
- */
- public void fireViewAddedToLayer( Notification notification ) {
-
- for(ILayersModelEventListener listener : listeners) {
- listener.viewAddedToLayer(notification);
- }
- }
-
- /**
- * Method called when a view is removed from one layer.
- * The event contains: the layer, the view.
- *
- * @param notification
- */
- public void fireViewRemovedFromLayer( Notification notification ) {
-
- for(ILayersModelEventListener listener : listeners) {
- listener.viewRemovedFromLayer(notification);
- }
- }
-
- /**
- * Method called when a view is moved from one layer to another layer.
- * The event contains: the layer, the view.
- *
- * @param notification
- */
- public void fireViewMovedBetweenLayer( Notification notification ) {
-
- for(ILayersModelEventListener listener : listeners) {
- listener.viewMovedBetweenLayer(notification);
- }
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2013 CEA LIST. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Cedric Dumoulin Cedric.dumoulin@lifl.fr + ******************************************************************************/ +package org.eclipse.papyrus.layers.runtime; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.emf.common.notify.Adapter; +import org.eclipse.emf.common.notify.Notification; +import org.eclipse.emf.ecore.EObject; +import org.eclipse.emf.ecore.util.EContentAdapter; +import org.eclipse.papyrus.layers.stackmodel.NotFoundException; +import org.eclipse.papyrus.layers.stackmodel.layers.AbstractLayer; +import org.eclipse.papyrus.layers.stackmodel.layers.LayersPackage; +import org.eclipse.papyrus.layers.stackmodel.layers.LayersStack; +import org.eclipse.papyrus.layers.stackmodel.layers.TypeInstance; +import org.eclipse.papyrus.layers.stackmodel.layers.impl.StringToTypeInstanceMapImpl; +import org.eclipse.papyrus.layers.stackmodel.layers.util.ECoreUtils; + + +/** + * This class listen to a {@link LayersStack} and send event to listeners. + * + * @author cedric dumoulin + * + */ +public class LayersModelEventNotifier { + + /** + * The observed {@link LayersStack}. + */ + protected LayersStack layersStack; + + /** + * List of listener to notify. + */ + protected List<ILayersModelEventListener> listeners = new ArrayList<ILayersModelEventListener>(); + + /** + * listener on layers changes. + * + */ + protected Adapter layersListener = new EContentAdapter() { + + @Override + public void notifyChanged(Notification notification) { + System.err.println("event received " + notification.getFeature()); + // Self atttach + super.notifyChanged(notification); + + // Check layers modification + // There is two sources: LayerOperator::layers and LayersStack::layers + if( notification.getFeature() == LayersPackage.eINSTANCE.getLayerOperator_Layers() + || notification.getFeature() == LayersPackage.eINSTANCE.getLayersStack_Layers() ) { + // LayerOperator::layers || LayersStack::layers + // check the event type. + switch(notification.getEventType()) { + case Notification.SET: + fireLayerSet(notification); + break; + case Notification.ADD: + // A layer is added + fireLayerAdded(notification); + break; + case Notification.REMOVE: + // A layer is removed + fireLayerRemoved(notification); + break; + case Notification.MOVE: + // A layer is moved + fireLayerMoved(notification); + break; + } + } + // Check view event + // View event can by fired by: AbstractLayer::views + else if (notification.getFeature() == LayersPackage.eINSTANCE.getAbstractLayer_Views() ) { + + // check the event type. + switch(notification.getEventType()) { + case Notification.ADD: + // A layer is added + // the concerned view +// View view = (View)notification.getNewValue(); +// AbstractLayer layer = (AbstractLayer)notification.getNotifier() + + fireViewAddedToLayer(notification); + break; + case Notification.REMOVE: + // A layer is removed + // the concerned view +// View view = (View)notification.getOldValue(); +// AbstractLayer layer = (AbstractLayer)notification.getNotifier() + + fireViewRemovedFromLayer(notification); + break; + } + + } + // Check instance addition/deletion + // instance event can by fired by: AbstractLayer::propertyValuesMap + else if (notification.getFeature() == LayersPackage.eINSTANCE.getAbstractLayer_PropertyValueMap() ) { + // check the event type. + switch(notification.getEventType()) { +// case Notification.SET: +// { +// // A key is added +// break; +// } +// case Notification.UNSET: +// // A key is added +// break; + case Notification.ADD: + { + // An entry is added + StringToTypeInstanceMapImpl entry = (StringToTypeInstanceMapImpl)notification.getNewValue(); +// System.out.println("ADD" + entry.getValue() +// + ", key=" + entry.getKey()); + // Add the corresponding instance to propertyValues + //Layer layer = (Layer)notification.getNotifier(); + //String propertyName = entry.getKey(); + //TypeInstance propertyValue = (TypeInstance)entry.getValue(); + firePropertyValueAddedEvent(notification); + break; + } + case Notification.REMOVE: + { + // An entry is removed + StringToTypeInstanceMapImpl entry = (StringToTypeInstanceMapImpl)notification.getOldValue(); +// System.out.println("REMOVE" + entry.getValue() +// + ", key=" + entry.getKey()); + // Add the corresponding instance to propertyValues + //Layer layer = (Layer)notification.getNotifier(); + //String propertyName = entry.getKey(); + //TypeInstance propertyValue = (TypeInstance)entry.getValue(); + firePropertyValueRemoved(notification); + break; + } + default: + break; + } + + } + // Check property instance modification event + // instance change event can by fired by: any modification in a subclass of TypeInstance + else { + try { + // Lookup if the event comes from a type instance + TypeInstance ancestor = (TypeInstance)ECoreUtils.lookupAncestorOfType((EObject)notification.getNotifier(), LayersPackage.eINSTANCE.getTypeInstance()); + // originating layer + AbstractLayer layer = (AbstractLayer)ECoreUtils.lookupAncestorOfType((EObject)notification.getNotifier(), LayersPackage.eINSTANCE.getAbstractLayer()); + // or: layer = (AbstractLayer)ancestor.eContainer().eContainer().eContainer(); + // StringToTypeInstanceMapImpl entry = (StringToTypeInstanceMapImpl)ancestor.eContainer(); + //String propertyName = entry.getKey(); + //TypeInstance propertyValue = (TypeInstance)entry.getValue(); + // +// String propertyName + // check the event type. + switch(notification.getEventType()) { + case Notification.SET: + // An instance value is set + firePropertyValueChanged(notification); + break; + case Notification.ADD: + // An instance value is set + firePropertyValueChanged(notification); + break; + case Notification.REMOVE: + // An instance value is set + firePropertyValueChanged(notification); + break; + } + } catch (NotFoundException e) { + // lookupAncestorOfType() found nothing + // silently fail + } + + + + } + + } + }; + + /** + * Constructor. + * + * @param layersStack The observed {@link LayersStack}. + */ + public LayersModelEventNotifier(LayersStack layersStack) { + this.layersStack = layersStack; + activate(); + } + + /** + * setup the listeners. + */ + protected void activate() { + layersStack.eAdapters().add(layersListener); + + } + + /** + * remove the listeners. + */ + protected void deactivate() { + layersStack.eAdapters().remove(layersListener); + + } + + /** + * Dispose this object. + */ + public void dispose() { + + deactivate(); + listeners.clear(); + layersListener = null; + } + + /** + * Return true if the object is disposed. + * @return + */ + public boolean isDisposed() { + return layersListener==null; + } + + /** + * Add the specified listener to the list of listener. + * Do not add it if the listener is already in the list. + * + * @param listener + */ + public void addLayersModelEventListener(ILayersModelEventListener listener) { + + if(listener == null ) { + return; + } + + // Check if exist + if( listeners.contains(listener)) { + return; + } + + listeners.add(listener); + } + + /** + * Remove the specified listener from the list of listeners. + * @param listener + */ + public void removeLayersModelEventListener(ILayersModelEventListener listener) { + + listeners.remove(listener); + } + /** + * Method called when a value is added to one layer. + * The vent contains: the layer, the property name, the new value. + * + * @param notification + */ + public void firePropertyValueAddedEvent( Notification notification ) { + + for(ILayersModelEventListener listener : listeners) { + listener.propertyValueAdded(notification); + } + } + + /** + * Method called when a value is removed from one layer. + * The vent contains: the layer, the property name, the new value. + * + * @param notification + */ + public void firePropertyValueRemoved( Notification notification ) { + + for(ILayersModelEventListener listener : listeners) { + listener.propertyValueRemoved(notification); + } + } + + /** + * Method called when a value is changed in one layer. + * The vent contains: the layer, the property name, the new value. + * + * @param notification + */ + public void firePropertyValueChanged( Notification notification ) { + + for(ILayersModelEventListener listener : listeners) { + listener.propertyValueChanged(notification); + } + } + + /** + * Method called when a layer is added to one layer. + * The event contains: the layer. + * + * @param notification + */ + public void fireLayerSet( Notification notification ) { + + for(ILayersModelEventListener listener : listeners) { + listener.layerSet(notification); + } + } + + /** + * Method called when a layer is added to one layer. + * The event contains: the layer. + * + * @param notification + */ + public void fireLayerAdded( Notification notification ) { + + for(ILayersModelEventListener listener : listeners) { + listener.layerAdded(notification); + } + } + + /** + * Method called when a layer is removed from one layer. + * The event contains: the layer. + * + * @param notification + */ + public void fireLayerRemoved( Notification notification ) { + + for(ILayersModelEventListener listener : listeners) { + listener.layerRemoved(notification); + } + } + + /** + * Method called when a layer is moved in LayerStack. + * The event contains: the layer. + * + * @param notification + */ + public void fireLayerMoved( Notification notification ) { + + for(ILayersModelEventListener listener : listeners) { + listener.layerMoved(notification); + } + } + + + /** + * Method called when a view is added to one layer. + * The event contains: the layer, the view. + * + * @param notification + */ + public void fireViewAddedToLayer( Notification notification ) { + + for(ILayersModelEventListener listener : listeners) { + listener.viewAddedToLayer(notification); + } + } + + /** + * Method called when a view is removed from one layer. + * The event contains: the layer, the view. + * + * @param notification + */ + public void fireViewRemovedFromLayer( Notification notification ) { + + for(ILayersModelEventListener listener : listeners) { + listener.viewRemovedFromLayer(notification); + } + } + + /** + * Method called when a view is moved from one layer to another layer. + * The event contains: the layer, the view. + * + * @param notification + */ + public void fireViewMovedBetweenLayer( Notification notification ) { + + for(ILayersModelEventListener listener : listeners) { + listener.viewMovedBetweenLayer(notification); + } + } + +} diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/NotationDiagramHelper.java b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/NotationDiagramHelper.java index d5322f422b5..c2837ed4e7a 100644 --- a/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/NotationDiagramHelper.java +++ b/extraplugins/layers/org.eclipse.papyrus.layers.runtime/src/org/eclipse/papyrus/layers/runtime/NotationDiagramHelper.java @@ -1,207 +1,206 @@ -/*******************************************************************************
- * Copyright (c) 2013 CEA LIST.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr
- ******************************************************************************/
-package org.eclipse.papyrus.layers.runtime;
-
-import org.eclipse.gmf.runtime.notation.Diagram;
-import org.eclipse.papyrus.layers.runtime.model.LayersModel;
-import org.eclipse.papyrus.layers.runtime.utils.LayersStackUtil;
-import org.eclipse.papyrus.layers.stackmodel.layers.LayersStack;
-import org.eclipse.papyrus.layers.stackmodel.layers.LayersStackApplication;
-
-
-/**
- * This class manage a notation.Diagram. It allows to :
- * <ul>
- * <li>Add or remove a LayersStack</li>
- * <li>get the LayersStackMngr if a LayersStack exist.</li>
- * </ul>
- *
- * @author Cedric dumoulin
- *
- */
-public class NotationDiagramHelper {
-
- /**
- * Associated Diagram.
- */
- protected Diagram diagram;
-
- /**
- * Layers model.
- */
- protected LayersModel layersModel;
-
- protected LayersStackApplication layersApplication;
-
-// /**
-// * The associated {@link LayersStackMngr}. Maybe null if no LayersStack is associated.
-// */
-// protected LayersStackMngr layerStackMngr;
-//
-// /**
-// * Notifier sending event when the layerStack is added or removed.
-// */
-// private LayersStackAttachedNotifier layerStackAttachedNotifier;
-
-// /**
-// * Listen on events from the layerStackAttachedNotifier.
-// */
-// private LayersStackAttachedListener layerStackAttachedListener = new LayersStackAttachedListener() {
-//
-// public void layerStackRemoved(LayersStackAttachedEvent event) {
-// layerStackMngr.dispose();
-// layerStackMngr = null;
-// }
-//
-// public void layerStackAttached(LayersStackAttachedEvent event) {
-//
-// if(layerStackMngr != null)
-// {
-// layerStackMngr.dispose();
-// layerStackMngr = null;
-// }
-//
-// layerStackMngr = new LayersStackMngr(event.getLayersStack());
-// }
-//
-// public void diagramChanged(LayersStackAttachedEvent event) {
-// // Not used because diagram is never set.
-// if(layerStackMngr != null)
-// {
-// layerStackMngr.dispose();
-// layerStackMngr = null;
-// }
-//
-// layerStackMngr = new LayersStackMngr(event.getLayersStack());
-//
-// }
-// };
-
- /**
- * Constructor.
- * Construct the manager and initialize it.
- * @param layersModel
- *
- */
- public NotationDiagramHelper(LayersModel layersModel, Diagram diagram) {
- this.diagram = diagram;
- this.layersModel = layersModel;
-
-// // Set the layerStackMngr if necessary
-// LayersStack layerStack = LayersStackUtil.getInstance().lookupLayersStack(diagram);
-// if(layerStack != null) {
-// layerStackMngr = new LayersStackMngr(layerStack);
-// }
-//
-// // Set the listeners on changes
-// layerStackAttachedNotifier = new LayersStackAttachedNotifier(diagram);
-// layerStackAttachedNotifier.addLayersStackAttachedEventListener(layerStackAttachedListener);
-
- activate();
- }
-
- /**
- * Activate the manager.
- */
- public void activate() {
-// layerStackAttachedNotifier.activate();
- }
-
- /**
- * Deactivate the manager.
- */
- public void deactivate() {
-// layerStackAttachedNotifier.deactivate();
- }
-
- /**
- * Dispose all resources.
- */
- public void dispose() {
-// layerStackAttachedNotifier.deactivate();
-
- diagram = null;
- }
-
-
- /**
- * @return the diagram
- */
- public Diagram getDiagram() {
- return diagram;
- }
-
-
-// /**
-// * Return the {@link LayersStackMngr} if any. Throw an
-// * @return the layerStackMngr
-// * @throws NotSetException If the layerStackMngr is not set.
-// */
-// public LayersStackMngr getLayersStackMngr() throws NotSetException {
-//
-// if(layerStackMngr == null)
-// throw new NotSetException(this.getClass().getSimpleName() + ".getLayersStackMngr(): layerStackMngr is not set.");
-//
-// return layerStackMngr;
-// }
-
- /**
- * Attach the {@link LayersStack} to the diagram.
- * Do nothing if a LayersStack is already attached.
- */
- public void attachLayersStack() {
-
- LayersStackApplication application = layersModel.getLayerStackApplication();
- application.getLayersStackFor(diagram);
- }
-
- /**
- * detach the {@link LayersStack} from the diagram.
- * Do nothing if no LayersStack is attached.
- */
- public void removeLayersStack() {
- LayersStackApplication application = layersModel.getLayerStackApplication();
- application.removeLayersStackFor(diagram);
- }
-
- /**
- * Return True if a {@link LayersStack} is attached to the diagram.
- *
- * @return True if a {@link LayersStack} is attached to the diagram.
- */
- public boolean isLayersStackAttached() {
- LayersStackApplication application = layersModel.lookupLayerStackApplication();
- if(application == null ) {
- return false;
- }
- return application.isLayersStackAttachedFor(diagram);
- }
-
-// /**
-// * Add a listener for the {@link LayersStackActivatedEvent}.
-// *
-// * @param listener
-// */
-// public void addLayersStackAttachedEventListener(LayersStackAttachedListener listener) {
-// layerStackAttachedNotifier.addLayersStackAttachedEventListener(listener);
-// }
-//
-// /**
-// * Remove a listener for the {@link LayersStackActivatedEvent}.
-// *
-// * @param listener
-// */
-// public void removeLayersStackAttachedEventListener(LayersStackAttachedListener listener) {
-// layerStackAttachedNotifier.removeLayersStackAttachedEventListener(listener);
-// }
-
-
-}
+/******************************************************************************* + * Copyright (c) 2013 CEA LIST. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Cedric Dumoulin Cedric.dumoulin@lifl.fr + ******************************************************************************/ +package org.eclipse.papyrus.layers.runtime; + +import org.eclipse.gmf.runtime.notation.Diagram; +import org.eclipse.papyrus.layers.runtime.model.LayersModel; +import org.eclipse.papyrus.layers.stackmodel.layers.LayersStack; +import org.eclipse.papyrus.layers.stackmodel.layers.LayersStackApplication; + + +/** + * This class manage a notation.Diagram. It allows to : + * <ul> + * <li>Add or remove a LayersStack</li> + * <li>get the LayersStackMngr if a LayersStack exist.</li> + * </ul> + * + * @author Cedric dumoulin + * + */ +public class NotationDiagramHelper { + + /** + * Associated Diagram. + */ + protected Diagram diagram; + + /** + * Layers model. + */ + protected LayersModel layersModel; + + protected LayersStackApplication layersApplication; + +// /** +// * The associated {@link LayersStackMngr}. Maybe null if no LayersStack is associated. +// */ +// protected LayersStackMngr layerStackMngr; +// +// /** +// * Notifier sending event when the layerStack is added or removed. +// */ +// private LayersStackAttachedNotifier layerStackAttachedNotifier; + +// /** +// * Listen on events from the layerStackAttachedNotifier. +// */ +// private LayersStackAttachedListener layerStackAttachedListener = new LayersStackAttachedListener() { +// +// public void layerStackRemoved(LayersStackAttachedEvent event) { +// layerStackMngr.dispose(); +// layerStackMngr = null; +// } +// +// public void layerStackAttached(LayersStackAttachedEvent event) { +// +// if(layerStackMngr != null) +// { +// layerStackMngr.dispose(); +// layerStackMngr = null; +// } +// +// layerStackMngr = new LayersStackMngr(event.getLayersStack()); +// } +// +// public void diagramChanged(LayersStackAttachedEvent event) { +// // Not used because diagram is never set. +// if(layerStackMngr != null) +// { +// layerStackMngr.dispose(); +// layerStackMngr = null; +// } +// +// layerStackMngr = new LayersStackMngr(event.getLayersStack()); +// +// } +// }; + + /** + * Constructor. + * Construct the manager and initialize it. + * @param layersModel + * + */ + public NotationDiagramHelper(LayersModel layersModel, Diagram diagram) { + this.diagram = diagram; + this.layersModel = layersModel; + +// // Set the layerStackMngr if necessary +// LayersStack layerStack = LayersStackUtil.getInstance().lookupLayersStack(diagram); +// if(layerStack != null) { +// layerStackMngr = new LayersStackMngr(layerStack); +// } +// +// // Set the listeners on changes +// layerStackAttachedNotifier = new LayersStackAttachedNotifier(diagram); +// layerStackAttachedNotifier.addLayersStackAttachedEventListener(layerStackAttachedListener); + + activate(); + } + + /** + * Activate the manager. + */ + public void activate() { +// layerStackAttachedNotifier.activate(); + } + + /** + * Deactivate the manager. + */ + public void deactivate() { +// layerStackAttachedNotifier.deactivate(); + } + + /** + * Dispose all resources. + */ + public void dispose() { +// layerStackAttachedNotifier.deactivate(); + + diagram = null; + } + + + /** + * @return the diagram + */ + public Diagram getDiagram() { + return diagram; + } + + +// /** +// * Return the {@link LayersStackMngr} if any. Throw an +// * @return the layerStackMngr +// * @throws NotSetException If the layerStackMngr is not set. +// */ +// public LayersStackMngr getLayersStackMngr() throws NotSetException { +// +// if(layerStackMngr == null) +// throw new NotSetException(this.getClass().getSimpleName() + ".getLayersStackMngr(): layerStackMngr is not set."); +// +// return layerStackMngr; +// } + + /** + * Attach the {@link LayersStack} to the diagram. + * Do nothing if a LayersStack is already attached. + */ + public void attachLayersStack() { + + LayersStackApplication application = layersModel.getLayerStackApplication(); + application.getLayersStackFor(diagram); + } + + /** + * detach the {@link LayersStack} from the diagram. + * Do nothing if no LayersStack is attached. + */ + public void removeLayersStack() { + LayersStackApplication application = layersModel.getLayerStackApplication(); + application.removeLayersStackFor(diagram); + } + + /** + * Return True if a {@link LayersStack} is attached to the diagram. + * + * @return True if a {@link LayersStack} is attached to the diagram. + */ + public boolean isLayersStackAttached() { + LayersStackApplication application = layersModel.lookupLayerStackApplication(); + if(application == null ) { + return false; + } + return application.isLayersStackAttachedFor(diagram); + } + +// /** +// * Add a listener for the {@link LayersStackActivatedEvent}. +// * +// * @param listener +// */ +// public void addLayersStackAttachedEventListener(LayersStackAttachedListener listener) { +// layerStackAttachedNotifier.addLayersStackAttachedEventListener(listener); +// } +// +// /** +// * Remove a listener for the {@link LayersStackActivatedEvent}. +// * +// * @param listener +// */ +// public void removeLayersStackAttachedEventListener(LayersStackAttachedListener listener) { +// layerStackAttachedNotifier.removeLayersStackAttachedEventListener(listener); +// } + + +} diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/loaders/LayerOperatorDescriptorRegistryLoader.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/loaders/LayerOperatorDescriptorRegistryLoader.java index b9a38f6b51f..bb14d6d123e 100644 --- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/loaders/LayerOperatorDescriptorRegistryLoader.java +++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/loaders/LayerOperatorDescriptorRegistryLoader.java @@ -1,116 +1,118 @@ -/*******************************************************************************
- * Copyright (c) 2013 CEA LIST.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr
- ******************************************************************************/
-package org.eclipse.papyrus.layers.stackmodel.layers.loaders;
-
-import org.eclipse.papyrus.layers.stackmodel.NotFoundException;
-import org.eclipse.papyrus.layers.stackmodel.layers.CustomPropertyOperator;
-import org.eclipse.papyrus.layers.stackmodel.layers.LayerOperatorDescriptor;
-import org.eclipse.papyrus.layers.stackmodel.layers.LayerOperatorDescriptorRegistry;
-import org.eclipse.papyrus.layers.stackmodel.layers.LayersFactory;
-import org.eclipse.papyrus.layers.stackmodel.layers.PropertyRegistry;
-import org.eclipse.papyrus.layers.stackmodel.operators.BooleanAndOperator;
-import org.eclipse.papyrus.layers.stackmodel.operators.BooleanOrOperator;
-
-
-/**
- * Class used to load a {@link LayerOperatorDescriptorRegistry}.
- *
- * @author cedric dumoulin
- *
- */
-public class LayerOperatorDescriptorRegistryLoader implements ILayerOperatorDescriptorRegistryLoader {
-
- /**
- * Load the specified registry. Initialize its Descriptors and its Operators.
- *
- * @param layerOperatorDescriptorRegistry
- * @param propertyRegistry
- */
- public void loadRegistryOld(LayerOperatorDescriptorRegistry descriptorRegistry, PropertyRegistry propertyRegistry) {
-
- // Custom operator declarations
- // operatorName, operatorImplementationClass
- String[] operatorDeclarations = new String[] {
- "booleanOr", BooleanOrOperator.class.getName(),
- "booleanAnd", BooleanAndOperator.class.getName(),
-
- };
-
- // Load operators
- for( int i=0; i<operatorDeclarations.length; i+=2) {
- CustomPropertyOperator operator = LayersFactory.eINSTANCE.createCustomPropertyOperator();
- operator.setName(operatorDeclarations[i]);
- operator.setClassname(operatorDeclarations[i+1]);
- descriptorRegistry.addPropertyOperator(operator);
- }
-
- // AndLayerStackOperatorDescriptor
- // propertyName, operatorName
- String[] andDescriptorDeclarations = new String [] {
- "isVisible", "booleanAnd",
- };
-
- LayerOperatorDescriptor andDescriptor = LayersFactory.eINSTANCE.createAndStackedLayerOperatorDescriptor();
- descriptorRegistry.addLayerOperatorDescriptor(andDescriptor);
-
- // attach operator to layer and property
- String descriptorName = andDescriptor.getName();
- for( int i=0; i<andDescriptorDeclarations.length; i+=2) {
- try {
- descriptorRegistry.attachOperatorToDescriptor(propertyRegistry.getProperty(andDescriptorDeclarations[i]), andDescriptorDeclarations[i+1], descriptorName);
- } catch (NotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- // OrLayerStackOperatorDescriptor
- // propertyName, operatorName
- String[] orDescriptorDeclarations = new String [] {
- "isVisible", "booleanOr",
- };
-
- LayerOperatorDescriptor orDescriptor = LayersFactory.eINSTANCE.createOrStackedLayerOperatorDescriptor();
- descriptorRegistry.addLayerOperatorDescriptor(orDescriptor);
-
- // attach operator to layer and property
- descriptorName = orDescriptor.getName();
- for( int i=0; i<orDescriptorDeclarations.length; i+=2) {
- try {
- descriptorRegistry.attachOperatorToDescriptor(propertyRegistry.getProperty(orDescriptorDeclarations[i]), orDescriptorDeclarations[i+1], descriptorName);
- } catch (NotFoundException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
- }
-
- /**
- * @see org.eclipse.papyrus.layers.stackmodel.layers.loaders.ILayerOperatorDescriptorRegistryLoader#loadLayerOperatorDescriptorRegistry(org.eclipse.papyrus.layers.stackmodel.layers.LayerOperatorDescriptorRegistry, org.eclipse.papyrus.layers.stackmodel.layers.PropertyRegistry)
- *
- * @param descriptorRegistry
- * @param propertyRegistry
- */
- public void loadLayerOperatorDescriptorRegistry(LayerOperatorDescriptorRegistry descriptorRegistry, PropertyRegistry propertyRegistry) {
-
- createLayersConfigModel();
-
- }
-
- /**
- * Create a Model
- */
- private void createLayersConfigModel() {
- // TODO Auto-generated method stub
-
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2013 CEA LIST. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Cedric Dumoulin Cedric.dumoulin@lifl.fr + ******************************************************************************/ +package org.eclipse.papyrus.layers.stackmodel.layers.loaders; + +import org.eclipse.papyrus.layers.stackmodel.NotFoundException; +import org.eclipse.papyrus.layers.stackmodel.layers.CustomPropertyOperator; +import org.eclipse.papyrus.layers.stackmodel.layers.LayerOperatorDescriptor; +import org.eclipse.papyrus.layers.stackmodel.layers.LayerOperatorDescriptorRegistry; +import org.eclipse.papyrus.layers.stackmodel.layers.LayersFactory; +import org.eclipse.papyrus.layers.stackmodel.layers.PropertyRegistry; +import org.eclipse.papyrus.layers.stackmodel.operators.BooleanAndOperator; +import org.eclipse.papyrus.layers.stackmodel.operators.BooleanOrOperator; + + +/** + * Class used to load a {@link LayerOperatorDescriptorRegistry}. + * + * @author cedric dumoulin + * + *@deprecated use {@link RegistriesLoader} instead. + * + */ +public class LayerOperatorDescriptorRegistryLoader implements ILayerOperatorDescriptorRegistryLoader { + + /** + * Load the specified registry. Initialize its Descriptors and its Operators. + * + * @param layerOperatorDescriptorRegistry + * @param propertyRegistry + */ + public void loadRegistryOld(LayerOperatorDescriptorRegistry descriptorRegistry, PropertyRegistry propertyRegistry) { + + // Custom operator declarations + // operatorName, operatorImplementationClass + String[] operatorDeclarations = new String[] { + "booleanOr", BooleanOrOperator.class.getName(), + "booleanAnd", BooleanAndOperator.class.getName(), + + }; + + // Load operators + for( int i=0; i<operatorDeclarations.length; i+=2) { + CustomPropertyOperator operator = LayersFactory.eINSTANCE.createCustomPropertyOperator(); + operator.setName(operatorDeclarations[i]); + operator.setClassname(operatorDeclarations[i+1]); + descriptorRegistry.addPropertyOperator(operator); + } + + // AndLayerStackOperatorDescriptor + // propertyName, operatorName + String[] andDescriptorDeclarations = new String [] { + "isVisible", "booleanAnd", + }; + + LayerOperatorDescriptor andDescriptor = LayersFactory.eINSTANCE.createAndStackedLayerOperatorDescriptor(); + descriptorRegistry.addLayerOperatorDescriptor(andDescriptor); + + // attach operator to layer and property + String descriptorName = andDescriptor.getName(); + for( int i=0; i<andDescriptorDeclarations.length; i+=2) { + try { + descriptorRegistry.attachOperatorToDescriptor(propertyRegistry.getProperty(andDescriptorDeclarations[i]), andDescriptorDeclarations[i+1], descriptorName); + } catch (NotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + // OrLayerStackOperatorDescriptor + // propertyName, operatorName + String[] orDescriptorDeclarations = new String [] { + "isVisible", "booleanOr", + }; + + LayerOperatorDescriptor orDescriptor = LayersFactory.eINSTANCE.createOrStackedLayerOperatorDescriptor(); + descriptorRegistry.addLayerOperatorDescriptor(orDescriptor); + + // attach operator to layer and property + descriptorName = orDescriptor.getName(); + for( int i=0; i<orDescriptorDeclarations.length; i+=2) { + try { + descriptorRegistry.attachOperatorToDescriptor(propertyRegistry.getProperty(orDescriptorDeclarations[i]), orDescriptorDeclarations[i+1], descriptorName); + } catch (NotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + } + + /** + * @see org.eclipse.papyrus.layers.stackmodel.layers.loaders.ILayerOperatorDescriptorRegistryLoader#loadLayerOperatorDescriptorRegistry(org.eclipse.papyrus.layers.stackmodel.layers.LayerOperatorDescriptorRegistry, org.eclipse.papyrus.layers.stackmodel.layers.PropertyRegistry) + * + * @param descriptorRegistry + * @param propertyRegistry + */ + public void loadLayerOperatorDescriptorRegistry(LayerOperatorDescriptorRegistry descriptorRegistry, PropertyRegistry propertyRegistry) { + + createLayersConfigModel(); + + } + + /** + * Create a Model + */ + private void createLayersConfigModel() { + // TODO Auto-generated method stub + + } + +} diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/loaders/RegistriesLoader.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/loaders/RegistriesLoader.java index 1a071d622e2..a5214e40c83 100644 --- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/loaders/RegistriesLoader.java +++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/src/org/eclipse/papyrus/layers/stackmodel/layers/loaders/RegistriesLoader.java @@ -1,97 +1,97 @@ -/*******************************************************************************
- * Copyright (c) 2013 CEA LIST.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr
- ******************************************************************************/
-package org.eclipse.papyrus.layers.stackmodel.layers.loaders;
-
-import org.eclipse.papyrus.layers.configmodel.layersconfig.LayerOperatorConfig;
-import org.eclipse.papyrus.layers.configmodel.layersconfig.OperatorBinding;
-import org.eclipse.papyrus.layers.configmodel.layersconfig.OperatorConfig;
-import org.eclipse.papyrus.layers.stackmodel.InstanciationException;
-import org.eclipse.papyrus.layers.stackmodel.NotFoundException;
-import org.eclipse.papyrus.layers.stackmodel.layers.LayerOperatorDescriptor;
-import org.eclipse.papyrus.layers.stackmodel.layers.LayerOperatorDescriptorRegistry;
-import org.eclipse.papyrus.layers.stackmodel.layers.Property;
-import org.eclipse.papyrus.layers.stackmodel.layers.PropertyOperator;
-import org.eclipse.papyrus.layers.stackmodel.layers.PropertyRegistry;
-
-
-/**
- * A loader used to load various Registries from a unique {@link LayersConfigModel}.
- * @author cedric dumoulin
- *
- */
-public class RegistriesLoader implements ILayerOperatorDescriptorRegistryLoader {
-
- /**
- * The model used to load the registries.
- *
- */
- protected LayersConfigModel model;
-
- /**
- * Constructor.
- *
- * @param model
- */
- public RegistriesLoader(LayersConfigModel model) {
- this.model = model;
- }
-
- /**
- * Load the {@link LayerOperatorDescriptorRegistryLoader} from the {@link LayersConfigModel}.
- *
- * @see org.eclipse.papyrus.layers.stackmodel.layers.loaders.ILayerOperatorDescriptorRegistryLoader#loadLayerOperatorDescriptorRegistry(org.eclipse.papyrus.layers.stackmodel.layers.LayerOperatorDescriptorRegistry, org.eclipse.papyrus.layers.stackmodel.layers.PropertyRegistry)
- *
- * @param descriptorRegistry
- * @param propertyRegistry
- */
- @Override
- public void loadLayerOperatorDescriptorRegistry(LayerOperatorDescriptorRegistry descriptorRegistry, PropertyRegistry propertyRegistry) {
-
- // Load LayerOperators
- for( LayerOperatorConfig layerOperatorConfig : model.getAllLayerOperatorConfig() ) {
- try {
- LayerOperatorDescriptor descriptor = layerOperatorConfig.createLayersOperatorDescriptor();
- descriptorRegistry.addLayerOperatorDescriptor(descriptor);
- } catch (InstanciationException e) {
- System.err.println("LOG - " + this.getClass().getName() + " - " + e.getMessage());
- e.printStackTrace();
- }
- }
-
- // Load operators
- for( OperatorConfig operatorConfig : model.getAllOperatorConfig()) {
- try {
- PropertyOperator operator = operatorConfig.createOperatorDescriptor();
- descriptorRegistry.addPropertyOperator(operator);
- } catch (InstanciationException e) {
- System.err.println("LOG - " + this.getClass().getName() + " - " + e.getMessage());
- e.printStackTrace();
- }
-
- }
-
- // Populate LayerOperator with operators
- for( OperatorBinding binding : model.getAllOperatorBinding()) {
- try {
- Property property = propertyRegistry.getProperty(binding.getPropertyId().getName());
- String layerDescriptorName = binding.getLayerOperatorConfig().getName();
- String operatorName = binding.getOperator().getName();
- descriptorRegistry.attachOperatorToDescriptor(property, operatorName, layerDescriptorName);
- } catch (NotFoundException e) {
- System.err.println("LOG - " + this.getClass().getName() + " - " + e.getMessage());
- e.printStackTrace();
- }
-
- }
-
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2013 CEA LIST. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Cedric Dumoulin Cedric.dumoulin@lifl.fr + ******************************************************************************/ +package org.eclipse.papyrus.layers.stackmodel.layers.loaders; + +import org.eclipse.papyrus.layers.configmodel.layersconfig.LayerOperatorConfig; +import org.eclipse.papyrus.layers.configmodel.layersconfig.OperatorBinding; +import org.eclipse.papyrus.layers.configmodel.layersconfig.OperatorConfig; +import org.eclipse.papyrus.layers.stackmodel.InstanciationException; +import org.eclipse.papyrus.layers.stackmodel.NotFoundException; +import org.eclipse.papyrus.layers.stackmodel.layers.LayerOperatorDescriptor; +import org.eclipse.papyrus.layers.stackmodel.layers.LayerOperatorDescriptorRegistry; +import org.eclipse.papyrus.layers.stackmodel.layers.Property; +import org.eclipse.papyrus.layers.stackmodel.layers.PropertyOperator; +import org.eclipse.papyrus.layers.stackmodel.layers.PropertyRegistry; + + +/** + * A loader used to load various Registries from a unique {@link LayersConfigModel}. + * @author cedric dumoulin + * + */ +public class RegistriesLoader implements ILayerOperatorDescriptorRegistryLoader { + + /** + * The model used to load the registries. + * + */ + protected LayersConfigModel model; + + /** + * Constructor. + * + * @param model + */ + public RegistriesLoader(LayersConfigModel model) { + this.model = model; + } + + /** + * Load the {@link LayerOperatorDescriptorRegistry} from the {@link LayersConfigModel}. + * + * @see org.eclipse.papyrus.layers.stackmodel.layers.loaders.ILayerOperatorDescriptorRegistryLoader#loadLayerOperatorDescriptorRegistry(org.eclipse.papyrus.layers.stackmodel.layers.LayerOperatorDescriptorRegistry, org.eclipse.papyrus.layers.stackmodel.layers.PropertyRegistry) + * + * @param descriptorRegistry + * @param propertyRegistry + */ + @Override + public void loadLayerOperatorDescriptorRegistry(LayerOperatorDescriptorRegistry descriptorRegistry, PropertyRegistry propertyRegistry) { + + // Load LayerOperators + for( LayerOperatorConfig layerOperatorConfig : model.getAllLayerOperatorConfig() ) { + try { + LayerOperatorDescriptor descriptor = layerOperatorConfig.createLayersOperatorDescriptor(); + descriptorRegistry.addLayerOperatorDescriptor(descriptor); + } catch (InstanciationException e) { + System.err.println("LOG - " + this.getClass().getName() + " - " + e.getMessage()); + e.printStackTrace(); + } + } + + // Load operators + for( OperatorConfig operatorConfig : model.getAllOperatorConfig()) { + try { + PropertyOperator operator = operatorConfig.createOperatorDescriptor(); + descriptorRegistry.addPropertyOperator(operator); + } catch (InstanciationException e) { + System.err.println("LOG - " + this.getClass().getName() + " - " + e.getMessage()); + e.printStackTrace(); + } + + } + + // Populate LayerOperator with operators + for( OperatorBinding binding : model.getAllOperatorBinding()) { + try { + Property property = propertyRegistry.getProperty(binding.getPropertyId().getName()); + String layerDescriptorName = binding.getLayerOperatorConfig().getName(); + String operatorName = binding.getOperator().getName(); + descriptorRegistry.attachOperatorToDescriptor(property, operatorName, layerDescriptorName); + } catch (NotFoundException e) { + System.err.println("LOG - " + this.getClass().getName() + " - " + e.getMessage()); + e.printStackTrace(); + } + + } + + } + +} diff --git a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/layers/loaders/LayerOperatorDescriptorRegistryLoaderTest.java b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/layers/loaders/LayerOperatorDescriptorRegistryLoaderTest.java index 55fd528b96f..1664b204a01 100644 --- a/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/layers/loaders/LayerOperatorDescriptorRegistryLoaderTest.java +++ b/extraplugins/layers/org.eclipse.papyrus.layers.stackmodel/test/org/eclipse/papyrus/layers/stackmodel/layers/loaders/LayerOperatorDescriptorRegistryLoaderTest.java @@ -1,98 +1,103 @@ -/*******************************************************************************
- * Copyright (c) 2013 CEA LIST.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr
- ******************************************************************************/
-package org.eclipse.papyrus.layers.stackmodel.layers.loaders;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
-
-import org.eclipse.papyrus.layers.stackmodel.NotFoundException;
-import org.eclipse.papyrus.layers.stackmodel.layers.LayerOperatorDescriptorRegistry;
-import org.eclipse.papyrus.layers.stackmodel.layers.LayersFactory;
-import org.eclipse.papyrus.layers.stackmodel.layers.Property;
-import org.eclipse.papyrus.layers.stackmodel.layers.PropertyRegistry;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-
-/**
- * @author cedric dumoulin
- *
- */
-public class LayerOperatorDescriptorRegistryLoaderTest {
-
- /**
- * @throws java.lang.Exception
- */
- @Before
- public void setUp() throws Exception {
- }
-
- /**
- * @throws java.lang.Exception
- */
- @After
- public void tearDown() throws Exception {
- }
-
- /**
- * Test method for constructor.
- */
- @Test
- public void testLayerOperatorDescriptorRegistryLoader() {
-
- LayerOperatorDescriptorRegistryLoader loader = new LayerOperatorDescriptorRegistryLoader();
-
- assertNotNull("object created", loader);
- }
-
- /**
- * Test method for {@link org.eclipse.papyrus.layers.stackmodel.layers.loaders.LayerOperatorDescriptorRegistryLoader#loadLayerOperatorDescriptorRegistry(org.eclipse.papyrus.layers.stackmodel.layers.LayerOperatorDescriptorRegistry, org.eclipse.papyrus.layers.stackmodel.layers.PropertyRegistry)}.
- * Check if the loader correctly initialize the LayerOperator and the Operators.
- * @throws NotFoundException
- */
- @Test
- public void testLoadRegistry() throws NotFoundException {
-
- // Create a PropertyRegistry
- PropertyRegistry propertyRegistry = LayersFactory.eINSTANCE.createPropertyRegistry();
-
- // Create a registry
- int propertiesCollectionSize = propertyRegistry.getPropertiesCount();
- LayerOperatorDescriptorRegistry registry = LayersFactory.eINSTANCE.createLayerOperatorDescriptorRegistry();
- registry.setPropertyCollectionSize(propertiesCollectionSize);
- // Create the loader
- LayerOperatorDescriptorRegistryLoader loader = new LayerOperatorDescriptorRegistryLoader();
-
-
- // Load the registry with the loader
- loader.loadLayerOperatorDescriptorRegistry(registry, propertyRegistry);
-
- // check registry content
- assertNotNull("layerOperator AndLayerOperator loaded", registry.getLayerOperatorDescriptor("OrStackedLayerOperator") );
- assertNotNull("layerOperator OrLayerOperator loaded", registry.getLayerOperatorDescriptor("AndStackedLayerOperator") );
-
-
- assertNotNull("Operator BooleanAnd loaded", registry.getPropertyOperator("booleanOr"));
- assertNotNull("Operator BooleanAnd loaded", registry.getPropertyOperator("booleanAnd"));
-
- // Check attachment
- Property isVisibleProp = propertyRegistry.getProperty("isVisible");
- assertNotNull("property set", isVisibleProp);
- assertNotNull("Operator attached to AndLayerOperator ", registry.getLayerOperatorDescriptor("OrStackedLayerOperator").getPropertyOperator(isVisibleProp) );
- assertNotNull("Operator attached to OrLayerOperator ", registry.getLayerOperatorDescriptor("AndStackedLayerOperator").getPropertyOperator(isVisibleProp) );
- // check if the right operator is attached to the right layerOperator
- assertSame("Operator attached to AndLayerOperator ", registry.getPropertyOperator("booleanOr"), registry.getLayerOperatorDescriptor("OrStackedLayerOperator").getPropertyOperator(isVisibleProp) );
- assertSame("Operator attached to OrLayerOperator ", registry.getPropertyOperator("booleanAnd"), registry.getLayerOperatorDescriptor("AndStackedLayerOperator").getPropertyOperator(isVisibleProp) );
-
- }
-
-}
+/******************************************************************************* + * Copyright (c) 2013 CEA LIST. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Cedric Dumoulin Cedric.dumoulin@lifl.fr + ******************************************************************************/ +package org.eclipse.papyrus.layers.stackmodel.layers.loaders; + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertSame; + +import org.eclipse.papyrus.layers.stackmodel.NotFoundException; +import org.eclipse.papyrus.layers.stackmodel.layers.LayerOperatorDescriptorRegistry; +import org.eclipse.papyrus.layers.stackmodel.layers.LayersFactory; +import org.eclipse.papyrus.layers.stackmodel.layers.Property; +import org.eclipse.papyrus.layers.stackmodel.layers.PropertyRegistry; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + + +/** + * @author cedric dumoulin + * + */ +public class LayerOperatorDescriptorRegistryLoaderTest { + + /** + * @throws java.lang.Exception + */ + @Before + public void setUp() throws Exception { + } + + /** + * @throws java.lang.Exception + */ + @After + public void tearDown() throws Exception { + } + + /** + * Test method for constructor. + */ + @Test + public void testLayerOperatorDescriptorRegistryLoader() { + + LayerOperatorDescriptorRegistryLoader loader = new LayerOperatorDescriptorRegistryLoader(); + + assertNotNull("object created", loader); + } + + /** + * Test method for {@link org.eclipse.papyrus.layers.stackmodel.layers.loaders.LayerOperatorDescriptorRegistryLoader#loadLayerOperatorDescriptorRegistry(org.eclipse.papyrus.layers.stackmodel.layers.LayerOperatorDescriptorRegistry, org.eclipse.papyrus.layers.stackmodel.layers.PropertyRegistry)}. + * Check if the loader correctly initialize the LayerOperator and the Operators. + * Registry loading do not use this loader (LayerOperatorDescriptorRegistryLoader) anymore. + * The new loader {@link RegistriesLoader} is now used. + * + * @throws NotFoundException + */ + @Test + @Ignore + public void testLoadRegistry() throws NotFoundException { + + // Create a PropertyRegistry + PropertyRegistry propertyRegistry = LayersFactory.eINSTANCE.createPropertyRegistry(); + + // Create a registry + int propertiesCollectionSize = propertyRegistry.getPropertiesCount(); + LayerOperatorDescriptorRegistry registry = LayersFactory.eINSTANCE.createLayerOperatorDescriptorRegistry(); + registry.setPropertyCollectionSize(propertiesCollectionSize); + // Create the loader + LayerOperatorDescriptorRegistryLoader loader = new LayerOperatorDescriptorRegistryLoader(); + + + // Load the registry with the loader + loader.loadLayerOperatorDescriptorRegistry(registry, propertyRegistry); + + // check registry content + assertNotNull("layerOperator AndLayerOperator loaded", registry.getLayerOperatorDescriptor("OrStackedLayerOperator") ); + assertNotNull("layerOperator OrLayerOperator loaded", registry.getLayerOperatorDescriptor("AndStackedLayerOperator") ); + + + assertNotNull("Operator BooleanAnd loaded", registry.getPropertyOperator("booleanOr")); + assertNotNull("Operator BooleanAnd loaded", registry.getPropertyOperator("booleanAnd")); + + // Check attachment + Property isVisibleProp = propertyRegistry.getProperty("isVisible"); + assertNotNull("property set", isVisibleProp); + assertNotNull("Operator attached to AndLayerOperator ", registry.getLayerOperatorDescriptor("OrStackedLayerOperator").getPropertyOperator(isVisibleProp) ); + assertNotNull("Operator attached to OrLayerOperator ", registry.getLayerOperatorDescriptor("AndStackedLayerOperator").getPropertyOperator(isVisibleProp) ); + // check if the right operator is attached to the right layerOperator + assertSame("Operator attached to AndLayerOperator ", registry.getPropertyOperator("booleanOr"), registry.getLayerOperatorDescriptor("OrStackedLayerOperator").getPropertyOperator(isVisibleProp) ); + assertSame("Operator attached to OrLayerOperator ", registry.getPropertyOperator("booleanAnd"), registry.getLayerOperatorDescriptor("AndStackedLayerOperator").getPropertyOperator(isVisibleProp) ); + + } + +} |