Commit 6d36fe34 authored by Robert Smith's avatar Robert Smith
Browse files

Fixed circular dependency



Removed a circular dependency from the package hierarchy.
Signed-off-by: Robert Smith's avatarRobert Smith <SmithRW@ornl.gov>
parent 7cfcb00f
......@@ -4,7 +4,8 @@ Bundle-Name: Eclipse Widgets RCP Bundle
Bundle-SymbolicName: org.eclipse.ice.client.widgets.rcp;singleton:=true
Bundle-Version: 2.1.8
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Export-Package: org.eclipse.ice.client.widgets.reactoreditor.plant
Export-Package: org.eclipse.ice.client.widgets.jme,
org.eclipse.ice.client.widgets.reactoreditor.plant
Import-Package: com.jme3.animation,
com.jme3.app,
com.jme3.app.state,
......
/*******************************************************************************
* Copyright (c) 2014 UT-Battelle, LLC.
* 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:
* Jordan Deyton (UT-Battelle, LLC.) - initial API and implementation and/or
* initial documentation
*
*******************************************************************************/
package org.eclipse.ice.client.widgets.jme;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.ice.datastructures.ICEObject.ICEObject;
import org.eclipse.ice.datastructures.ICEObject.IUpdateable;
import org.eclipse.ice.datastructures.ICEObject.IUpdateableListener;
import org.eclipse.ice.viz.service.jme3.application.IRenderQueue;
import org.eclipse.ice.viz.service.jme3.widgets.AbstractView;
import com.jme3.scene.Node;
/**
* This class provides a base implementation for a controller that manages an
* {@link IUpdateable} model and an {@link AbstractView} associated with that
* model. It ensures that changes to the model or features provided by the
* controller itself are synchronized with the view through the parent
* SimpleApplication's simpleUpdate() thread.
*
* @author Jordan Deyton
*
*/
public abstract class AbstractController implements IUpdateableListener {
/*
* Note: We previously had an IControllerListener interface whereby objects
* could listen for changes to an AbstractController. If this interface is
* required for future work, this package (widgets.jme) and the plant
* package (widgets.reactoreditor.plant) should be selectively reverted to
* restore IControllerListener, AbstractController, and PipeController to
* their state before 20140903-1600. Also note that this change was
* committed to the branch.
*/
/**
* The model for which this controller provides a view.
*/
protected final IUpdateable model;
/**
* The {@link AbstractView} associated with this controller.
*/
private final AbstractView view;
/**
* The queue responsible for tasks that need to be performed on the jME
* rendering thread.
*/
protected final IRenderQueue renderQueue;
/**
* Whether or not the controller and its view have been disposed.
*/
protected final AtomicBoolean disposed;
// ---- Base Features ---- //
/**
* The current parent node for the {@link #view}.
*/
private Node parentNode;
// ----------------------- //
/**
* The default constructor. If any arguments are invalid (null), an
* {@link IllegalArgumentException} is thrown.
*
* @param model
* The model for which this controller provides a view.
* @param view
* The view associated with this controller. This needs to be
* instantiated by the sub-class.
* @param renderQueue
* The queue responsible for tasks that need to be performed on
* the jME rendering thread.
*/
public AbstractController(IUpdateable model, AbstractView view,
IRenderQueue renderQueue) {
// Set the model and register with it. It should not be null.
this.model = (model != null ? model : new ICEObject());
this.model.register(this);
// Set the view. If it is null, create a new, basic view.
this.view = (view != null ? view : new AbstractView("Invalid View") {
});
// Set the update queue. If it is null, create a new queue.
this.renderQueue = (renderQueue != null ? renderQueue
: new IRenderQueue() {
@Override
public <T> Future<T> enqueue(Callable<T> callable) {
return null;
}
});
// Initialize the disposed boolean.
disposed = new AtomicBoolean(false);
// ---- Initialize any base features. ---- //
parentNode = null;
// --------------------------------------- //
return;
}
/**
* @return The model for which this controller provides a view.
*/
public IUpdateable getModel() {
return model;
}
/**
* Sets the Node to which the associated {@link AbstractView} is attached.
*
* @param node
* The new parent node for the associated {@link AbstractView}.
*/
public void setParentNode(Node node) {
// If the parent node is not null and is different, we can attach the
// view to the new parent.
if (node != null && node != parentNode) {
this.parentNode = node;
// If the controller is not disposed, we should try to attach the
// view to the new parent.
if (!disposed.get()) {
renderQueue.enqueue(new Callable<Boolean>() {
@Override
public Boolean call() {
view.setParentNode(parentNode);
return true;
}
});
}
}
return;
}
/**
* Disposes of the AbstractController and its associated
* {@link AbstractView}.
*/
public void dispose() {
// If we have not already disposed of the controller, we need to
// unregister from the IUpdateable model and, if possible, dispose of
// the AbstractView managed by this controller.
if (disposed.compareAndSet(false, true)) {
// Unregister from the model.
model.unregister(this);
// Add a new update action to remove the view.
renderQueue.enqueue(new Callable<Boolean>() {
@Override
public Boolean call() {
view.dispose();
return true;
}
});
}
return;
}
/**
* Updates the controller and/or view if the {@link #model} has changed.
*/
@Override
public abstract void update(IUpdateable component);
}
/*******************************************************************************
* Copyright (c) 2014 UT-Battelle, LLC.
* 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:
* Jordan Deyton (UT-Battelle, LLC.) - initial API and implementation and/or
* initial documentation
*
*******************************************************************************/
package org.eclipse.ice.client.widgets.jme;
import org.eclipse.ice.client.widgets.reactoreditor.plant.PlantAppState;
import org.eclipse.ice.reactor.plant.PlantComposite;
import org.eclipse.ice.viz.service.jme3.application.MasterApplication;
import org.eclipse.ice.viz.service.jme3.application.ViewAppState;
import org.eclipse.ice.viz.service.jme3.internal.MasterApplicationHolder;
/**
* This factory is used to create custom {@link ViewAppState}s for components
* including <code>GeometryComponent</code>s, <code>MeshComponent</code>s, and
* <code>PlantComposite</code>s. To embed the view in an SWT
* <code>Composite</code>, see
* {@link ViewAppState#createComposite(org.eclipse.swt.widgets.Composite)}.
*
* @author Jordan
*
*/
public class ViewFactory {
// TODO We may want to handle this via an OSGi-based factories and registry.
/**
* The core <code>MasterApplication</code> that renders all of the views.
*/
private final MasterApplication app;
/**
* The default constructor.
*/
public ViewFactory() {
this(false);
}
/**
* A constructor that allows the <code>ViewFactory</code> to create its own
* {@link MasterApplication} if the OSGi-provided
* <code>MasterApplication</code> is not available.
* <p>
* <b>Note:</b> This is <i>not intended</i> for use inside ICE but inside
* static applications. In ICE, the <code>MasterApplication</code> is
* created only via an OSGi-provided factory.
* </p>
* <p>
* <b>Note 2:</b> If you use more than one <code>ViewFactory</code> with
* <code>staticFallBack</code> set to <code>true</code> and without running
* OSGi, then your program may not work properly. jME does not support
* multiple <code>SimpleApplication</code>s running simultaneously.
* </p>
*
* @param staticFallBack
* If true, then this factory will create its own
* <code>MasterApplication</code> when it cannot acquire one via
* OSGi.
*/
public ViewFactory(boolean staticFallBack) {
// Try to get the app via OSGi.
MasterApplication app = MasterApplicationHolder.getApplication();
// If the flag is set to true and we couldn't get the app through OSGi,
// create a new app.
if (app == null && staticFallBack) {
app = MasterApplication.createApplication();
}
this.app = app;
}
/**
// * Creates a {@link MeshAppState} for the specified
// * <code>MeshComponent</code>.
// *
// * @param mesh
// * The root <code>MeshComponent</code> or mesh that contains
// * edges, vertices, and other <code>MeshComponent</code>s.
// * @return A new <code>MeshAppState</code>, or null if there is no core
// * <code>MasterApplication</code> in the background.
// */
// public MeshAppState createMeshView(MeshComponent mesh) {
//
// MeshAppState view = null;
//
// if (app != null) {
//
// // If necessary, wait until the MasterApplication has started before
// // trying to add a new AppState, or nothing may initialize.
// if (!app.isInitialized()) {
// app.blockUntilInitialized(0);
// }
//
// view = new MeshAppState();
// view.start(app);
//
// view.setMesh(mesh);
// }
//
// return view;
// }
/**
* Creates a {@link PlantAppState} for the specified
* <code>PlantComposite</code>.
*
* @param plant
* The root <code>PlantComponent</code> or plant that can contain
* several <code>PlantComponent</code>s.
* @return A new <code>PlantAppState</code>, or null if there is no core
* <code>MasterApplication</code> in the background.
*/
public PlantAppState createPlantView(PlantComposite plant) {
PlantAppState view = null;
if (app != null) {
// If necessary, wait until the MasterApplication has started before
// trying to add a new AppState, or nothing may initialize.
if (!app.isInitialized()) {
app.blockUntilInitialized(0);
}
view = new PlantAppState();
view.start(app);
view.setPlant(plant);
}
return view;
}
/**
* Disposes of the specified view.
*
* @param view
* The view to dispose.
*/
public void disposeView(ViewAppState view) {
if (view != null) {
view.stop();
// If we need to do anything special, do it here.
}
return;
}
}
......@@ -15,9 +15,9 @@ package org.eclipse.ice.client.widgets.reactoreditor.plant;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.ice.client.widgets.jme.AbstractController;
import org.eclipse.ice.datastructures.ICEObject.IUpdateable;
import org.eclipse.ice.viz.service.jme3.application.IRenderQueue;
import org.eclipse.ice.viz.service.jme3.widgets.AbstractController;
import com.jme3.math.ColorRGBA;
......
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry exported="true" kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
</classpath>
......@@ -26,12 +26,7 @@ Import-Package: ca.odell.glazedlists,
org.eclipse.emf.ecore.xmi,
org.eclipse.emf.ecore.xmi.impl,
org.eclipse.emf.ecore.xmi.util,
org.eclipse.ice.viz.service.datastructures,
org.eclipse.ice.viz.service.datastructures.VizObject,
org.eclipse.ice.viz.service.datastructures.resource,
org.eclipse.ice.viz.service.geometry.shapes,
org.eclipse.ice.viz.service.jme3.geometry,
org.eclipse.ice.viz.service.mesh.datastructures,
org.eclipse.ice.viz.service.modeling,
org.eclipse.xsd,
org.osgi.framework;version="1.6.0",
......
......@@ -7,5 +7,6 @@ Fragment-Host: org.eclipse.ice.reactor.plant;bundle-version="2.0.0"
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Require-Bundle: org.junit;bundle-version="4.11.0"
Bundle-Vendor: Oak Ridge National Laboratory
Import-Package: org.eclipse.ice.viz.service.datastructures,
Import-Package: ca.odell.glazedlists.gui,
org.eclipse.ice.viz.service.datastructures,
org.eclipse.ice.viz.service.mesh.datastructures
......@@ -4,14 +4,14 @@ Bundle-Name: org.eclipse.ice.reactor.plant
Bundle-SymbolicName: org.eclipse.ice.reactor.plant;singleton:=true
Bundle-Version: 2.1.8
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
Require-Bundle: org.eclipse.ice.datastructures
Export-Package: org.eclipse.ice.reactor.plant
Import-Package: ncsa.hdf.hdf5lib,
ncsa.hdf.hdf5lib.exceptions,
org.eclipse.ice.datastructures.ICEObject,
org.eclipse.ice.datastructures.componentVisitor,
org.eclipse.ice.io.hdf,
org.eclipse.ice.viz.service.datastructures.VizObject,
org.eclipse.ice.viz.service.modeling,
org.eclipse.swt.widgets,
org.slf4j;version="1.7.2"
Service-Component: OSGI-INF/PlantIOFactory.xml
Bundle-Vendor: Oak Ridge National Laboratory
Export-Package: org.eclipse.ice.reactor.plant
......@@ -43,6 +43,7 @@ Import-Package: com.jme3.app,
com.jme3.system.awt,
com.jme3.texture,
com.jme3.util,
org.eclipse.ice.datastructures.ICEObject,
org.eclipse.ice.viz.service,
org.eclipse.ice.viz.service.datastructures,
org.eclipse.ice.viz.service.datastructures.VizObject,
......
......@@ -16,6 +16,7 @@ import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;
import org.eclipse.ice.datastructures.ICEObject.IUpdateableListener;
import org.eclipse.ice.viz.service.datastructures.VizObject.IVizUpdateable;
import org.eclipse.ice.viz.service.datastructures.VizObject.IVizUpdateableListener;
import org.eclipse.ice.viz.service.datastructures.VizObject.VizObject;
......@@ -33,7 +34,7 @@ import com.jme3.scene.Node;
* @author Jordan Deyton
*
*/
public abstract class AbstractController implements IVizUpdateableListener {
public abstract class AbstractController implements IUpdateableListener {
/*
* Note: We previously had an IControllerListener interface whereby objects
* could listen for changes to an AbstractController. If this interface is
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment