Skip to content
Snippets Groups Projects
Commit 6e45fb5e authored by Nils Christian Ehmke's avatar Nils Christian Ehmke
Browse files

Started with the observer patterns

parent da71914c
No related branches found
No related tags found
No related merge requests found
......@@ -28,6 +28,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Observable;
import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
......@@ -65,7 +66,7 @@ import org.eclipse.emf.common.util.EList;
*/
@ManagedBean
@SessionScoped
public class SelectedMainProjectBean {
public class SelectedMainProjectBean extends Observable {
/**
* The logger within this class.
*/
......@@ -95,6 +96,10 @@ public class SelectedMainProjectBean {
*/
private List<Connection> connections;
public enum UPDATE_MSG {
SELECTION_CHANGED
}
/**
* Creates a new instance of this class.
*/
......@@ -121,7 +126,11 @@ public class SelectedMainProjectBean {
this.mainProject = mainProject;
this.connections = this.getConnectionsFromProject();
FacesContext.getCurrentInstance().addMessage(null, new FacesMessage(FacesMessage.SEVERITY_INFO, "", "New main project: " + mainProject.getName()));
}
// Inform the observers
setChanged();
notifyObservers(UPDATE_MSG.SELECTION_CHANGED);
}
/**
* This method delivers the available reader-plugins for the current main project. The delivered plugins are never abstract.
......
......@@ -22,20 +22,40 @@ package kieker.webgui.beans.session;
import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;
import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;
import kieker.analysis.model.analysisMetaModel.MIPlugin;
import org.primefaces.context.RequestContext;
/**
* This bean can be used to save the currently selected plugin of the user.
* This bean can be used to save the currently selected plugin of the user. This bean registers to the user's instance of {@link SelectedMainProjectBean} as an
* observer. If the main project changes, the content of this bean changes as well. This bean also updates the properties form if the selection of the plugin
* changes.
*
* @author Nils Christian Ehmke
* @version 1.0
*/
@ManagedBean
@SessionScoped
public final class SelectedPluginBean {
public final class SelectedPluginBean implements Observer {
/**
* This is the name of the target element to be updated when the plugin selection changes.
*/
private static final String UPDATE_TARGET = "propertiesForm";
/**
* This is the main project bean where this instance registers as an observer.
*/
private final SelectedMainProjectBean observableBean;
/**
* The plugin which is stored by this container.
......@@ -46,7 +66,29 @@ public final class SelectedPluginBean {
* Creates a new instance of this class.
*/
public SelectedPluginBean() {
/* No code necessary. */
// Try to get the main project bean.
final FacesContext context = FacesContext.getCurrentInstance();
this.observableBean = context.getApplication().evaluateExpressionGet(context, "#{selectedMainProjectBean}", SelectedMainProjectBean.class);
}
/**
* This method is used to initialize the object after creation.
*/
@PostConstruct
@SuppressWarnings("FinalPrivateMethod")
private final void postConstruct() {
// Register this instance as an observer
this.observableBean.addObserver(this);
}
/**
* This method is used to finalize the object before destruction.
*/
@PreDestroy
@SuppressWarnings("FinalPrivateMethod")
private final void preDestroy() {
// Unregister this instance as an observer
this.observableBean.deleteObserver(this);
}
/**
......@@ -59,21 +101,39 @@ public final class SelectedPluginBean {
}
/**
* Sets the plugin stored by this bean.
* Sets the plugin stored by this bean and updates (if possible) the corresponding element in the current context.
*
* @param plugin
* The new bean to be stored within this bean.
*/
public void setPlugin(final MIPlugin plugin) {
this.plugin = plugin;
// Update the element
final RequestContext requestContext = RequestContext.getCurrentInstance();
requestContext.addPartialUpdateTarget(SelectedPluginBean.UPDATE_TARGET);
}
/**
* This method delivers a list containing all properties of the current plugin, but adds the name as a string to it.
*
* @return A list with all properties plus the name (as a string). If no plugin is selected, this method returns an empty list, never null.
*/
public List<Object> getAdvancedProperties() {
final List<Object> resultList = new ArrayList<Object>();
resultList.add(plugin.getName());
resultList.addAll(plugin.getProperties());
if (this.plugin != null) {
resultList.add(this.plugin.getName());
resultList.addAll(this.plugin.getProperties());
}
return resultList;
}
@Override
public void update(final Observable o, final Object arg) {
// If the main project has been newly selected, we have to set the current plugin to null
if (arg == SelectedMainProjectBean.UPDATE_MSG.SELECTION_CHANGED) {
this.setPlugin(null);
}
}
}
......@@ -34,6 +34,7 @@
<p:menubar>
<p:submenu label="File">
<p:menuitem value="New Project" onclick="newProjectDialog.show()" ajax="true" />
<p:menuitem value="Import Project" ajax="true" />
<p:menuitem value="Manage Dependencies" ajax="false" url="/Kieker.WebGUI/manageDependencies" />
<p:separator />
<p:menuitem value="Settings" onclick="settingsDialog.show()" ajax="true" />
......@@ -114,7 +115,7 @@
<h:form id="centerForm" style="height: 100%">
<div class="canvas" id="mainCanvas" style="width : #{currentWorkspaceSizeBean.sizeX}px;height: #{currentWorkspaceSizeBean.sizeY}px">
<c:forEach items="#{selectedMainProjectBean.mainProject.plugins}" var="plugin" varStatus="counter">
<p:remoteCommand name="setPlugin#{counter.index}" action="#{selectedPluginBean.setPlugin(plugin)}" update=":propertiesForm"/>
<p:remoteCommand name="setPlugin#{counter.index}" action="#{selectedPluginBean.setPlugin(plugin)}"/>
<!-- Netbeans reports an error here, but the code does still work though... -->
<div onclick="setPlugin#{counter.index}();" class="ui-panel ui-widget ui-widget-content ui-corner-all block draggable" id="#{stringToIDBean.stringToID(plugin)}" >
<div class="ui-panel-titlebar ui-widget-header ui-corner-all">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment