Hi,
I tried everything but it doesn’t work. so here is the relevant code. The client and server side and the class which calls the widget.
this is the server side component.
/*
* The DecidR Development Team licenses this file to you 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 de.decidr.ui.data;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpSession;
import org.apache.log4j.Logger;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.output.XMLOutputter;
import com.vaadin.data.Item;
import com.vaadin.terminal.PaintException;
import com.vaadin.terminal.PaintTarget;
import com.vaadin.ui.AbstractComponent;
import de.decidr.model.acl.roles.Role;
import de.decidr.model.annotations.Reviewed;
import de.decidr.model.annotations.Reviewed.State;
import de.decidr.model.exceptions.TransactionException;
import de.decidr.model.facades.TenantFacade;
import de.decidr.model.facades.WorkflowModelFacade;
import de.decidr.model.logging.DefaultLogger;
import de.decidr.ui.view.Main;
import de.decidr.ui.view.windows.TransactionErrorDialogComponent;
/**
* This class represents the server side component of the modeling tool widget
* which is integrated into the Vaadin web portal. It is used to communicate
* with the client side of the modeling tool widget. The modeling tool is an
* abstract component which is wrapped by a window and displayed to the user.
*
* @author AT
* @author Jonas Schlaak
*/
@Reviewed(reviewers = { "RR" }, lastRevision = "2353", currentReviewState = State.Passed)
public class ModelingTool extends AbstractComponent {
private static final long serialVersionUID = -2284244108529453836L;
private Logger logger = DefaultLogger.getLogger(ModelingTool.class);
private HttpSession session = null;
private Long tenantId = null;
private Role role = null;
private TenantFacade tenantFacade = null;
private WorkflowModelFacade workflowModelFacade = null;
private Long workflowModelId = null;
private HashMap<Long, String> userMap = null;
private String name = "";
private String description = "";
/**
* Initializes the server side components which are needed to gain access to
* the database.
*/
public ModelingTool(Long workflowModelId) {
super();
session = Main.getCurrent().getSession();
role = (Role) session.getAttribute("role");
tenantId = (Long) Main.getCurrent().getSession().getAttribute(
"tenantId");
tenantFacade = new TenantFacade(role);
workflowModelFacade = new WorkflowModelFacade(role);
this.workflowModelId = workflowModelId;
this.setSizeFull();
this.setImmediate(true);
this.setDebugId("modelingTool");
Main.getCurrent().getUIDirector().getTemplateView().getContent()
.getWidth();
}
@Override
public String getTag() {
return "modelingtool";
}
/*
* (non-Javadoc)
*
* @see com.vaadin.ui.AbstractComponent#changeVariables(java.lang.Object,
* java.util.Map)
*/
@SuppressWarnings("unchecked")
@Override
public void changeVariables(Object source, Map variables) {
super.changeVariables(source, variables);
logger.debug("[Modeling Tool]
Trying to store the DWDL...");
if (variables.containsKey("dwdl")) {
String dwdl = variables.get("dwdl").toString();
byte[] dwdlByte = dwdl.getBytes();
try {
workflowModelFacade.saveWorkflowModel(workflowModelId, name,
description, dwdlByte);
logger.debug("[Modeling Tool]
DWDL stored successfully.");
} catch (TransactionException e) {
Main.getCurrent().addWindow(
new TransactionErrorDialogComponent(e));
logger.debug("[Modeling Tool]
DWDL storing failed.");
}
} else {
logger.debug("[Modeling Tool]
Client variables did not"
+ " contain a dwdl key.");
}
}
/**
* Converts a user map into an XML string. This has to be done because the
* Vaadin interface can only transmit simple types.
*
* @param userMap
* list of tenant users as map
* @return xml formatted user list
*/
private String convertUserMapToString(HashMap<Long, String> userMap) {
Document doc = new Document();
doc.setRootElement(new Element("userlist"));
for (Long userId : userMap.keySet()) {
Element user = new Element("user");
user.setAttribute("id", userId.toString());
user.setAttribute("name", userMap.get(userId));
doc.getRootElement().addContent(user);
}
return new XMLOutputter().outputString(doc);
}
private String getDWDL() {
try {
Item workflowModel = workflowModelFacade
.getWorkflowModel(workflowModelId);
name = workflowModel.getItemProperty("name").getValue().toString();
description = workflowModel.getItemProperty("description")
.getValue().toString();
logger.debug("[Modeling Tool]
Retrieving dwdl document was"
+ " successfull");
return new String((byte[]) workflowModel.getItemProperty("dwdl")
.getValue());
} catch (TransactionException e) {
Main.getCurrent().addWindow(new TransactionErrorDialogComponent(e));
logger.debug("[Modeling Tool]
Retrieving dwdl document failed");
return null;
}
}
private String getUsers() {
userMap = new HashMap<Long, String>();
try {
logger.debug("[Modeling Tool]
Trying to get "
+ "the tenant user list...");
List<Item> users = tenantFacade.getUsersOfTenant(tenantId, null);
for (Item item : users) {
if (item.getItemProperty("username") == null
|| item.getItemProperty("username").getValue() == null
|| item.getItemProperty("username").getValue().equals(
"")) {
/*
* If the username is empty, we want to display the email
* address as username.
*/
userMap.put((Long) item.getItemProperty("id").getValue(),
(String) item.getItemProperty("email").getValue());
} else {
/*
* username is not empty, but we want to set the username to
* a more "fancy" string, for example: John Doe (jdoe42)
*/
Long id = (Long) item.getItemProperty("id").getValue();
String username = (String) item.getItemProperty("username")
.getValue();
userMap.put(id, username);
}
}
logger.debug("[Modeling Tool]
Succeded retrieving "
+ "tenant user list. No. of users: " + userMap.size());
String userXMLString = convertUserMapToString(userMap);
return userXMLString;
} catch (TransactionException exception) {
Main.getCurrent().addWindow(
new TransactionErrorDialogComponent(exception));
logger.debug("[Modeling Tool]
Failed retrieving tenant user list.");
return null;
}
}
/*
* (non-Javadoc)
*
* @see
* com.vaadin.ui.AbstractComponent#paintContent(com.vaadin.terminal.PaintTarget
* )
*/
@Override
public void paintContent(PaintTarget target) throws PaintException {
super.paintContent(target);
target.addVariable(this, "dwdl", getDWDL());
target.addVariable(this, "users", getUsers());
/*
* Set width of the modeling too scroll panel. Height is a constant
* because the getHeight() values are wrong
*/
int width = new Float(Main.getCurrent().getUIDirector()
.getTemplateView().getContent().getWidth()).intValue();
target.addVariable(this, "width", width);
// Main.getCurrent().getUIDirector().getTemplateView().getContent().getHeight();
target.addVariable(this, "height", 500);
}
}
This is the client side component.
/*
* The DecidR Development Team licenses this file to you 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 de.decidr.ui.view.client.ui;
import com.vaadin.terminal.gwt.client.ApplicationConnection;
import com.vaadin.terminal.gwt.client.Paintable;
import com.vaadin.terminal.gwt.client.UIDL;
import de.decidr.modelingtool.client.ModelingToolWidget;
/**
* This class represents the client side from the modeling tool integrated in
* the web portal
*
* @author AT
* @author JS
*/
public class VModelingTool extends ModelingToolWidget implements Paintable {
/** Set the tagname used to statically resolve the widget from UIDL. */
public static final String TAGNAME = "modelingtool";
/** Set the CSS class name to allow styling. */
public static final String CLASSNAME = "v-" + TAGNAME;
/** Component identifier in UIDL communications. */
String uidlId;
/** Reference to the server connection object. */
ApplicationConnection client;
/**
* The constructor should first call super() to initialize the component and
* then handle any initialization relevant to Vaadin.
*/
public VModelingTool() {
super();
// This method call of the Paintable interface sets the component
// style name in DOM tree
setStyleName(CLASSNAME);
}
@Override
public void sendDWDLtoServer(String dwdl) {
super.sendDWDLtoServer(dwdl);
// Updating the state to the server can not be done
// before the server connection is known, i.e., before
// updateFromUIDL() has been called.
if ((uidlId == null) || (client == null)) {
return;
}
// Communicate the user interaction parameters to server.
// This call will initiate an AJAX request to the server.
client.updateVariable(uidlId, "dwdl", dwdl, true);
}
public void updateFromUIDL(UIDL uidl, ApplicationConnection client) {
// This call should be made first. Ensure correct implementation,
// and let the containing layout manage caption, etc.
if (client.updateComponent(this, uidl, true)) {
return;
}
// Save reference to server connection object to be able to send
// user interaction later
this.client = client;
// Save the UIDL identifier for the component
uidlId = uidl.getId();
// Set the DWDL document received from server
setDWDL(uidl.getStringVariable("dwdl"));
// Set the user list received from server
setUsers(uidl.getStringVariable("users"));
// Set the scroll panel to the size given by the server
setScrollPanelSize(uidl.getIntVariable("width"), uidl
.getIntVariable("height"));
}
}
And this is the method where i call the widget.
/*
* The DecidR Development Team licenses this file to you 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 de.decidr.ui.controller.show;
import java.util.Iterator;
import java.util.Set;
import com.vaadin.data.Item;
import com.vaadin.ui.Table;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import de.decidr.model.annotations.Reviewed;
import de.decidr.model.annotations.Reviewed.State;
import de.decidr.ui.controller.UIDirector;
import de.decidr.ui.data.ModelingTool;
import de.decidr.ui.view.Main;
import de.decidr.ui.view.SiteFrame;
import de.decidr.ui.view.windows.InformationDialogComponent;
/**
* Opens the modeling tool.
*
* @author AT
*/
@Reviewed(reviewers = { "RR" }, lastRevision = "2348", currentReviewState = State.Passed)
public class ShowModelingToolAction implements ClickListener {
private static final long serialVersionUID = 1L;
UIDirector uiDirector = Main.getCurrent().getUIDirector();
SiteFrame siteFrame = uiDirector.getTemplateView();
private Table table = null;
/**
* Constructor which stores the table where the workflow model is selected.
*/
public ShowModelingToolAction(Table table) {
this.table = table;
}
/*
* (non-Javadoc)
*
* @seecom.vaadin.ui.Button.ClickListener#buttonClick(com.vaadin.ui.Button.
* ClickEvent)
*/
@Override
public void buttonClick(ClickEvent event) {
Set<?> set = (Set<?>) table.getValue();
if (table.getValue() != null && set.size() == 1) {
Iterator<?> iter = set.iterator();
while (iter.hasNext()) {
Item item = (Item) iter.next();
siteFrame.setContent(new ModelingTool((Long) table
.getItem(item).getItemProperty("id").getValue()));
}
} else {
Main.getCurrent().getMainWindow().addWindow(
new InformationDialogComponent(
"Please select exactly one workflow model",
"Information"));
}
}
}
I hope this will help you. If not I can give you more information.
With best regards