blob: b95f6da8126c32b012d2948cd9b6a5ee0ad87b52 [file] [log] [blame]
/*
*
* Copyright (c) 2011 - 2017 - Loetz GmbH & Co KG, 69115 Heidelberg, Germany
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Initial contribution:
* Loetz GmbH & Co. KG
*
*/
package org.eclipse.osbp.runtime.common.event;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.osgi.framework.eventmgr.CopyOnWriteIdentityMap;
/**
* The Class EventDispatcherEvent.
*/
public class EventDispatcherEvent {
/**
* The Enum EventDispatcherCommand.
*/
public enum EventDispatcherCommand {
/** something was selected. */
SELECT,
/** something requested a refresh. */
REFRESH,
/** The user saved. */
SAVE,
/** The user deleted. */
DELETE,
/** The user wants change info */
INFO,
/** The user started an action. */
ACTION,
/** Process finished. */
FINISHED,
/** Answer is yes. */
YES,
/** Answer is no. */
NO,
/** Close window. */
CLOSE,
/** Answer is ok. */
OK,
/** show bpmn. */
BPMN
}
/**
* The Enum EventDispatcherDataTag.
*/
public enum EventDispatcherDataTag {
/** The id. values are of type id or uuid */
ID,
/** The id of the pressed action button */
BUTTON_ID,
/** The id of an started human task (bpmn) */
TASK_ID,
/** The list of objects. */
LIST,
/** a filled dto object. */
DTO,
/** an IUser object. */
USER,
/** any object. */
OBJECT
}
/** The command. */
private EventDispatcherCommand command;
/** The sender class. */
private String sender;
/** The topic. */
private String topic;
/** The data. */
private Map<EventDispatcherDataTag, Object> data = new CopyOnWriteIdentityMap<>();
/**
* Instantiates a new event dispatcher event.
*
* @param command the command
* @param topic the topic
*/
public EventDispatcherEvent(EventDispatcherCommand command, String topic, String sender) {
this.command = command;
this.topic = topic;
this.sender = sender;
}
/**
* Gets the command.
*
* @return the command
*/
public EventDispatcherCommand getCommand() {
return command;
}
/**
* Sets the command.
*
* @param command the new command
*/
public void setCommand(EventDispatcherCommand command) {
this.command = command;
}
/**
* Gets the topic.
*
* @return the topic
*/
public String getTopic() {
return topic;
}
/**
* Sets the topic.
*
* @param topic the new topic
*/
public void setTopic(String topic) {
this.topic = topic;
}
/**
* Gets the data.
*
* @return the data
*/
public Map<EventDispatcherDataTag, Object> getData() {
return data;
}
/**
* Sets the data.
*
* @param data the data
*/
public void setData(Map<EventDispatcherDataTag, Object> data) {
this.data = data;
}
/**
* Adds the item data.
*
* @param tag the tag
* @param item the item
*/
@SuppressWarnings("unchecked")
public void addItem(EventDispatcherDataTag tag, Object item) {
if(tag == EventDispatcherDataTag.LIST) {
if(!data.containsKey(EventDispatcherDataTag.LIST)) {
data.put(EventDispatcherDataTag.LIST, new CopyOnWriteArrayList<String>());
}
((List<String>)data.get(EventDispatcherDataTag.LIST)).add((String)item);
} else {
data.put(tag, item);
}
}
@SuppressWarnings("unchecked")
public void addData(List<IDualData> selectedData) {
if(!data.containsKey(EventDispatcherDataTag.LIST)) {
data.put(EventDispatcherDataTag.LIST, new CopyOnWriteArrayList<String>());
}
for(IDualData dd : selectedData){
((List<String>)data.get(EventDispatcherDataTag.LIST)).add(dd.getSelectionValue());
}
}
/**
* Gets the sender.
*
* @return the sender id
*/
public String getSender() {
return sender;
}
/**
* Sets the sender id.
*
* @param sender the new sender
*/
public void setSender(String sender) {
this.sender = sender;
}
}