From 098128b8ef11b99a13a516b804f9c50593da604e Mon Sep 17 00:00:00 2001 From: Nils Christian Ehmke <nie@informatik.uni-kiel.de> Date: Fri, 1 Jun 2012 15:19:25 +0200 Subject: [PATCH] Repositories can now be connected with filters. --- .../session/CurrentWorkSpaceProjectBean.java | 54 ++++++++++++--- .../MIRepositoryStringConverter.java | 65 +++++++++++++++++++ .../src/main/webapp/ProjectWorkSpace.xhtml | 3 +- .../webapp/dialogs/connectionDialog.xhtml | 31 +++++---- 4 files changed, 131 insertions(+), 22 deletions(-) create mode 100644 Kieker.WebGUI/src/main/java/kieker/webgui/converter/MIRepositoryStringConverter.java diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/CurrentWorkSpaceProjectBean.java b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/CurrentWorkSpaceProjectBean.java index 755583bd..a746fd28 100644 --- a/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/CurrentWorkSpaceProjectBean.java +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/beans/session/CurrentWorkSpaceProjectBean.java @@ -56,6 +56,7 @@ import kieker.analysis.repository.AbstractRepository; import kieker.analysis.repository.annotation.Repository; import kieker.common.configuration.Configuration; import kieker.webgui.common.ConnectionFilterToFilter; +import kieker.webgui.common.ConnectionFilterToRepository; import kieker.webgui.common.FSManager; import kieker.webgui.common.Pair; import kieker.webgui.common.PluginFinder; @@ -73,6 +74,7 @@ import org.primefaces.model.UploadedFile; * @author Nils Christian Ehmke * @version 1.0 */ +// TODO Update port map and repository map on add/delete @ManagedBean @SessionScoped public final class CurrentWorkSpaceProjectBean { @@ -120,8 +122,10 @@ public final class CurrentWorkSpaceProjectBean { private final ConcurrentHashMap<String, MIPlugin> pluginMap = new ConcurrentHashMap<String, MIPlugin>(); private final ConcurrentHashMap<String, MIPort> portMap = new ConcurrentHashMap<String, MIPort>(); + private final ConcurrentHashMap<String, MIRepository> repositoryMap = new ConcurrentHashMap<String, MIRepository>(); private MIPlugin selectedPlugin; - private final List<ConnectionFilterToFilter> connections = new ArrayList<ConnectionFilterToFilter>(); + private final List<ConnectionFilterToFilter> filter2filterConnections = new ArrayList<ConnectionFilterToFilter>(); + private final List<ConnectionFilterToRepository> filter2repositoryConnections = new ArrayList<ConnectionFilterToRepository>(); private MIRepository selectedRepository; /** @@ -179,6 +183,10 @@ public final class CurrentWorkSpaceProjectBean { } private void intializeHashMaps() { + this.pluginMap.clear(); + this.portMap.clear(); + this.repositoryMap.clear(); + for (final MIPlugin plugin : this.project.getPlugins()) { this.pluginMap.put(plugin.toString(), plugin); for (final MIPort port : plugin.getOutputPorts()) { @@ -190,6 +198,9 @@ public final class CurrentWorkSpaceProjectBean { } } } + for (final MIRepository repository : this.project.getRepositories()) { + this.repositoryMap.put(repository.toString(), repository); + } } /** @@ -300,6 +311,8 @@ public final class CurrentWorkSpaceProjectBean { this.selectedPlugin = null; this.timeStamp = 0; this.pluginMap.clear(); + this.filter2filterConnections.clear(); + this.filter2repositoryConnections.clear(); return CurrentWorkSpaceProjectBean.PAGE_PROJECT_OVERVIEW; } @@ -644,21 +657,27 @@ public final class CurrentWorkSpaceProjectBean { * This method extracts the connections between the filters from the current main project. */ private void getConnectionsFromProject() { - this.connections.clear(); + this.filter2filterConnections.clear(); + this.filter2repositoryConnections.clear(); if (this.project != null) { final EList<MIPlugin> mPlugins = this.project.getPlugins(); + for (final MIPlugin mPlugin : mPlugins) { final EList<MIOutputPort> mOutputPorts = mPlugin.getOutputPorts(); for (final MIOutputPort mOutputPort : mOutputPorts) { final EList<MIInputPort> mInputPorts = mOutputPort.getSubscribers(); for (final MIInputPort mInputPort : mInputPorts) { - this.connections.add(new ConnectionFilterToFilter(mPlugin, mInputPort.getParent(), mInputPort, mOutputPort)); + this.filter2filterConnections.add(new ConnectionFilterToFilter(mPlugin, mInputPort.getParent(), mInputPort, mOutputPort)); } } + + final EList<MIRepositoryConnector> mConnectors = mPlugin.getRepositories(); + for (final MIRepositoryConnector mConnector : mConnectors) { + this.filter2repositoryConnections.add(new ConnectionFilterToRepository(mPlugin, mConnector.getRepository(), mConnector)); + } } } - } /** @@ -666,8 +685,16 @@ public final class CurrentWorkSpaceProjectBean { * * @return A list containing all available connections. */ - public List<ConnectionFilterToFilter> getConnections() { - return this.connections; + public List<ConnectionFilterToFilter> getFilterConnections() { + return this.filter2filterConnections; + } + + public List<ConnectionFilterToRepository> getRepoConnections() { + return this.filter2repositoryConnections; + } + + public EList<MIRepository> getRepositories() { + return this.project.getRepositories(); } /** @@ -677,7 +704,7 @@ public final class CurrentWorkSpaceProjectBean { */ public List<ConnectionFilterToFilter> getValidConnections() { final List<ConnectionFilterToFilter> validConnections = new ArrayList<ConnectionFilterToFilter>(); - final List<ConnectionFilterToFilter> availableConnections = this.getConnections(); + final List<ConnectionFilterToFilter> availableConnections = this.getFilterConnections(); for (final ConnectionFilterToFilter connection : availableConnections) { if (connection.isValid()) { @@ -692,18 +719,24 @@ public final class CurrentWorkSpaceProjectBean { * This method adds an empty connection to the current main project. */ public void addConnection() { - this.connections.add(new ConnectionFilterToFilter(null, null, null, null)); + this.filter2filterConnections.add(new ConnectionFilterToFilter(null, null, null, null)); } /** * This method "submits" the current connections to the main project (In other words: The connections will be stored within the main project). */ public void submitConnections() { - for (final ConnectionFilterToFilter connection : this.connections) { + for (final ConnectionFilterToFilter connection : this.filter2filterConnections) { if (connection.isValid()) { connection.getOutputPort().getSubscribers().add(connection.getInputPort()); } } + + for (final ConnectionFilterToRepository connection : this.filter2repositoryConnections) { + if (connection.isValid()) { + connection.getOutputPort().setRepository(connection.getDestination()); + } + } } /** @@ -726,4 +759,7 @@ public final class CurrentWorkSpaceProjectBean { return this.portMap.get(string); } + public MIRepository getRepositoryByName(final String string) { + return this.repositoryMap.get(string); + } } diff --git a/Kieker.WebGUI/src/main/java/kieker/webgui/converter/MIRepositoryStringConverter.java b/Kieker.WebGUI/src/main/java/kieker/webgui/converter/MIRepositoryStringConverter.java new file mode 100644 index 00000000..36c71f5a --- /dev/null +++ b/Kieker.WebGUI/src/main/java/kieker/webgui/converter/MIRepositoryStringConverter.java @@ -0,0 +1,65 @@ +/*************************************************************************** + * Copyright 2012 by + * + Christian-Albrechts-University of Kiel + * + Department of Computer Science + * + Software Engineering Group + * and others. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + ***************************************************************************/ + +package kieker.webgui.converter; + +import javax.el.ELResolver; +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.faces.convert.FacesConverter; + +import kieker.webgui.beans.session.CurrentWorkSpaceProjectBean; + +/** + * This converter can be used to convert a given repository model instance to a string and vice versa (It uses the object's toString-method). + * + * @author Nils Christian Ehmke + * @version 1.0 + */ +@FacesConverter(value = MIRepositoryStringConverter.NAME) +public class MIRepositoryStringConverter implements Converter { + /** + * This is the name of this converter. + */ + public static final String NAME = "kieker.webgui.converter.MIRepositoryStringConverter"; + + /** + * Creates a new instance of this class. + */ + public MIRepositoryStringConverter() { + /* No code necessary. */ + } + + @Override + public Object getAsObject(final FacesContext fc, final UIComponent uic, final String string) { + final ELResolver el = FacesContext.getCurrentInstance() + .getApplication().getELResolver(); + final CurrentWorkSpaceProjectBean bean = (CurrentWorkSpaceProjectBean) el.getValue(FacesContext.getCurrentInstance() + .getELContext(), null, "currentWorkSpaceProjectBean"); + + return bean.getRepositoryByName(string); + } + + @Override + public String getAsString(final FacesContext fc, final UIComponent uic, final Object o) { + return o.toString(); + } +} diff --git a/Kieker.WebGUI/src/main/webapp/ProjectWorkSpace.xhtml b/Kieker.WebGUI/src/main/webapp/ProjectWorkSpace.xhtml index 28864518..1bf0f20b 100644 --- a/Kieker.WebGUI/src/main/webapp/ProjectWorkSpace.xhtml +++ b/Kieker.WebGUI/src/main/webapp/ProjectWorkSpace.xhtml @@ -37,6 +37,7 @@ <p:menuitem value="Reset Project" ajax="true" disabled="#{empty currentWorkSpaceProjectBean.project}"/> <p:separator/> <p:menuitem value="Manage Libraries" onclick="manageLibrariesDialog.show()" ajax="true" disabled="#{empty currentWorkSpaceProjectBean.project}"/> + <p:menuitem ajax="true" value="Edit Connections" update=":connectionDialogForm" onclick="connectionDialog.show();"/> <p:separator/> <p:menuitem value="Close Project" action="#{currentWorkSpaceProjectBean.clearProject()}" ajax="false"/> <p:separator/> @@ -66,8 +67,6 @@ <div class="ui-panel-titlebar ui-widget-header ui-corner-all"> <h:outputText style="font-weight: bold" value="#{plugin.getName()}"/> </div> - <p:commandLink ajax="true" value="Connections" update=":connectionDialogForm" onclick="connectionDialog.show();"/> - <br/> <p:commandLink ajax="true" value="Remove" action="#{currentWorkSpaceProjectBean.removePlugin(plugin)}" update=":propertiesForm :centerForm"/> </div> </ui:repeat> diff --git a/Kieker.WebGUI/src/main/webapp/dialogs/connectionDialog.xhtml b/Kieker.WebGUI/src/main/webapp/dialogs/connectionDialog.xhtml index e3d74ef3..905daa45 100644 --- a/Kieker.WebGUI/src/main/webapp/dialogs/connectionDialog.xhtml +++ b/Kieker.WebGUI/src/main/webapp/dialogs/connectionDialog.xhtml @@ -17,7 +17,7 @@ update=":connectionDialogForm" /> <br /> <br /> - <p:dataTable value="#{currentWorkSpaceProjectBean.connections}" + <p:dataTable value="#{currentWorkSpaceProjectBean.filterConnections}" var="connection" paginator="true" rows="10" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"> @@ -112,29 +112,38 @@ </p:tab> <p:tab title="Plugin -> Repository Connections"> -<p:commandButton value="Add Connection" ajax="true" - action="#{currentWorkSpaceProjectBean.addConnection()}" - update=":connectionDialogForm" /> - <br /> - <br /> - <p:dataTable value="#{currentWorkSpaceProjectBean.connections}" + <p:dataTable value="#{currentWorkSpaceProjectBean.repoConnections}" var="connection" paginator="true" rows="10" paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"> <p:column headerText="Source" style="width:125px"> - + <h:outputText value="#{connection.source.name}"/> </p:column> <p:column headerText="Repository Port" style="width:125px"> - + <h:outputText value="#{connection.outputPort.name}"/> </p:column> <p:column headerText="Destination" style="width:125px"> - + <p:cellEditor> + <f:facet name="output"> + <h:outputText value="#{empty connection.destination ? 'N/A' : connection.destination.name}" /> + </f:facet> + <f:facet name="input"> + <p:selectOneMenu converter="kieker.webgui.converter.MIRepositoryStringConverter" + value="#{connection.destination}" effectDuration="100"> + <f:selectItem value="#{null}" itemLabel="N/A" + itemValue="#{null}" /> + <f:selectItems value="#{currentWorkSpaceProjectBean.repositories}" + var="repo" itemLabel="#{repo.name}" itemValue="#{repo}" /> + <p:ajax event="change" update="validColumn" /> + </p:selectOneMenu> + </f:facet> + </p:cellEditor> </p:column> <p:column id="validColumn" headerText="Valid" style="width:50px"> - + <h:outputText value="#{connection.valid ? 'True' : 'False'}" /> </p:column> <p:column headerText="Options" style="width:50px"> -- GitLab