📄 casehandler.java
字号:
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
/*
* $Author$
* $Date$
* $Revision$
*/
package eti.bi.alphaminer.core.handler;
import java.io.File;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.Vector;
import javax.swing.JOptionPane;
import com.prudsys.pdm.Core.MiningException;
import com.prudsys.pdm.Models.Clustering.Cluster;
import com.prudsys.pdm.Models.Clustering.ClusteringMiningModel;
import eti.bi.alphaminer.core.Node.NodeLoader;
import eti.bi.alphaminer.core.observer.Observer;
import eti.bi.alphaminer.operation.operator.NodeInfo;
import eti.bi.alphaminer.operation.operator.Operator;
import eti.bi.alphaminer.tools.SystemTools.CaseHelpToolBarHandler;
import eti.bi.alphaminer.ui.CaseDiagramPanel;
import eti.bi.alphaminer.ui.CaseWindow;
import eti.bi.alphaminer.ui.ICaseDiagram;
import eti.bi.alphaminer.ui.IMessageDialog;
import eti.bi.alphaminer.ui.ISystemMessageHandler;
import eti.bi.alphaminer.ui.SystemMessagePanel;
import eti.bi.alphaminer.ui.dialog.MessageDialog;
import eti.bi.alphaminer.vo.BICase;
import eti.bi.alphaminer.vo.CaseFactory;
import eti.bi.alphaminer.vo.INode;
import eti.bi.alphaminer.vo.IOperatorNode;
import eti.bi.alphaminer.vo.Node;
import eti.bi.alphaminer.vo.NodeFactory;
import eti.bi.alphaminer.vo.OperatorNode;
import eti.bi.common.Locale.Resource;
import eti.bi.common.System.SysConfig;
import eti.bi.exception.AppException;
import eti.bi.exception.BaseException;
import eti.bi.exception.CaseNotFoundException;
import eti.bi.exception.SysException;
/**
* CaseHandler is a class storing case detail of retrieved cases
* in the KBBI server.
*
* The class is responsible for communicating with the communication handler to
* retrieve case detail.
*/
public class CaseHandler implements ICaseHandler {
/**
* An instance of CaseHandler.
*/
private static CaseHandler m_CaseHandler;
/**
* Most current NodeID used.
*/
//private static int m_NodeIDGenerator;
/**
* A hashtable storing retrived case detail.
*/
private Hashtable m_CaseList;
/**
* A vector for storing observer instances that are to be notified after
* certain operation in CaseHandler.
*/
private Vector m_Observers;
/**
* Constructs a CaseHandler.
*/
private CaseHandler() {
}
private IMessageDialog m_MessageDialog = new MessageDialog();
/**
* Creates a new case by copying an existing case.
* @param a_CaseID ID of the source case to be copied.
* @return ID of the newly created case.
*/
public String copyCase(String a_CaseID) throws BaseException {
Object[] obj = {a_CaseID};
try
{
/* Retrieve source case locally */
BICase sourceCase = getCase(a_CaseID, false);
/* Create a new case instace and store it locally */
BICase newCase = CaseFactory.createCase(sourceCase);
setCase(newCase);
return newCase.getCaseID();
}
catch (AppException ae)
{
throw new AppException(ae, obj);
}
catch (Exception e)
{
throw new SysException(e, obj);
}
}
/**
* Creates a new blank case.
* @return ID of the newly created case.
*/
public String createCase() {
BICase newCase = CaseFactory.createCase();
setCase(newCase);
return newCase.getCaseID();
}
/**
* Creates connection between two nodes.
* @param a_CaseID ID of the case of the two nodes.
* @param a_HeadNodeID ID of the parent node.
* @param a_TailNodeID ID of the child node.
* @return true if the Connection is successfully created; false otherwise.
*/
public boolean createConnection(
String a_CaseID,
String a_HeadNodeID,
String a_TailNodeID)
throws BaseException {
Object[] obj = { a_CaseID, a_HeadNodeID, a_TailNodeID};
try
{
boolean success = false;
BICase selectedCase = getCase(a_CaseID, false);
Operator headOperator = getOperator(a_CaseID, a_HeadNodeID);
Operator tailOperator = getOperator(a_CaseID, a_TailNodeID);
if (tailOperator.acceptParent(headOperator) && headOperator.acceptChild(tailOperator))
{
success = selectedCase.insertConnection(a_HeadNodeID, a_TailNodeID);
setCase(selectedCase);
}
return success;
}
catch (AppException ae)
{
throw new AppException(ae, obj);
}
catch (Exception e)
{
throw new SysException(e, obj);
}
}
/**
* Creates a specific type of node.
* @param a_CaseID ID of the case of this newly created node.
* @param a_NodeType type of the node.
* @return ID of a Node instance.
*/
public String createNode(String a_CaseID, String a_OperatorDefinitionID)
throws BaseException {
Object[] obj = { a_CaseID, a_OperatorDefinitionID};
try
{
BICase selectedCase = getCase(a_CaseID, false);
NodeInfo nodeInfo = NodeLoader.getNodeInfo(a_OperatorDefinitionID);
Node newNode = NodeFactory.createOperatorNode(a_CaseID, nodeInfo);
newNode.setNodeID("node" + selectedCase.getNextAvailableNodeID("node"));
//newNode.setNodeID("node" + m_NodeIDGenerator);
//m_NodeIDGenerator++;
selectedCase.setNode(newNode);
setCase(selectedCase);
return newNode.getNodeID();
}
catch (AppException ae)
{
throw new AppException(ae, obj);
}
catch (Exception e)
{
throw new SysException(e, obj);
}
}
/**
* Get the number of connected parents
* @param a_CaseID
* @param a_NodeID
* @return
* @throws SysException
*/
public int getNumParents(String a_CaseID, String a_NodeID) throws SysException
{
//CaseHandler caseHandler = CaseHandler.getInstance();
BICase selectedCase;
try {
selectedCase = getCase(a_CaseID, false);
} catch (BaseException e) {
throw new SysException("Invalid Case Handle.");
}
if (selectedCase == null)
{
throw new SysException("Invalid Case Handle.");
}
Vector parentNodeIDs = selectedCase.getParentOfNodes(a_NodeID);
if (parentNodeIDs == null)
{
throw new SysException("Invalid parent nodes");
}
return parentNodeIDs.size();
}
/**
* Return a all parent operator node objects in vector by given case ID and node ID
* @param a_CaseID ID of the case of the node.
* @param a_NodeID ID of the node being executed.
**/
@SuppressWarnings("unchecked")
public Vector<IOperatorNode> getParentOperatorNodes(String a_CaseID, String a_NodeID) throws SysException
{
Vector<IOperatorNode> parentOperatorNodes = new Vector<IOperatorNode>();
// Get caseHandler instance
BICase selectedCase = null;
// Get case object instance
try {
selectedCase = getCase(a_CaseID, false);
} catch (BaseException e) {
throw new SysException("Case Handler Execution Error.");
}
// Get parent node IDs from case object
Vector parentNodeIDs = selectedCase.getParentOfNodes(a_NodeID);
if (parentNodeIDs == null || parentNodeIDs.size()==0)
{
return parentOperatorNodes;
}else
{
// Get operators using the node IDs
for (int i=0;i<parentNodeIDs.size();i++)
{
parentOperatorNodes.add(getOperatorNode(a_CaseID,(String)parentNodeIDs.elementAt(i)));
}
}
return parentOperatorNodes;
}
/**
* Return a all parent operator objects in vector by given case ID and node ID
* @param a_CaseID ID of the case of the node.
* @param a_NodeID ID of the node being executed.
**/
public Vector<Operator> getParentOperators(String a_CaseID, String a_NodeID) throws SysException
{
Vector<Operator> parentOperators = new Vector<Operator>();
// Get caseHandler instance
//CaseHandler caseHandler = CaseHandler.getInstance();
BICase selectedCase = null;
// Get case object instance
try {
selectedCase = getCase(a_CaseID, false);
} catch (BaseException e) {
throw new SysException("Case Handler Execution Error.");
}
// Get parent node IDs from case object
Vector parentNodeIDs = selectedCase.getParentOfNodes(a_NodeID);
if (parentNodeIDs == null || parentNodeIDs.size()==0)
{
return parentOperators;
}else
{
// Get operators using the node IDs
for (int i=0;i<parentNodeIDs.size();i++)
{
parentOperators.add(getOperator(a_CaseID,(String)parentNodeIDs.elementAt(i)));
}
}
return parentOperators;
}
/**
* Return a all child operator objects in vector by given case ID and node ID
* @param a_CaseID ID of the case of the node.
* @param a_NodeID ID of the node being executed.
**/
@SuppressWarnings("unchecked")
public Vector<Operator> getChildOperators(String a_CaseID, String a_NodeID) throws SysException
{
Vector<Operator> childOperators = new Vector<Operator>();
// Get caseHandler instance
//CaseHandler caseHandler = CaseHandler.getInstance();
BICase selectedCase = null;
// Get case object instance
try {
// selectedCase = caseHandler.getCase(a_CaseID, false);
selectedCase = getCase(a_CaseID, false);
} catch (BaseException e) {
throw new SysException("Case Handler Execution Error.");
}
// Get parent node IDs from case object
Vector parentNodeIDs = selectedCase.getChildrenOfNode(a_NodeID);
if (parentNodeIDs == null || parentNodeIDs.size()==0)
{
return childOperators;
}else
{
// Get operators using the node IDs
for (int i=0;i<parentNodeIDs.size();i++)
{
try
{
childOperators.add(getOperator(a_CaseID,(String)parentNodeIDs.elementAt(i)));
}catch(Exception e)
{
// Do Nothing
}
}
}
return childOperators;
}
/**
* Return a operator object by given case ID and node ID
* @param a_CaseID ID of the case of the node.
* @param a_NodeID ID of the node being executed.
**/
public Operator getOperator(String a_CaseID, String a_NodeID) throws SysException
{
CaseDiagramPanel caseDiagramPanel = CaseDiagramPanel.getCaseDiagramPanel(a_CaseID);
if (caseDiagramPanel == null )
{
throw new SysException("Invalid Case Diagram Handle. CaseID: [" + a_CaseID + "]");
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -