Search in sources :

Example 1 with ContainerNode

use of com.cubrid.cubridmanager.ui.replication.editor.model.ContainerNode in project cubrid-manager by CUBRID.

the class ReplicationEditor method initConnection.

/**
	 * initialize the connection
	 * 
	 */
private void initConnection() {
    if (diagram != null) {
        MasterNode master = null;
        DistributorNode dist = null;
        SlaveNode slave = null;
        List<ContainerNode> containerNodeList = diagram.getChildNodeList();
        for (int i = 0; containerNodeList != null && i < containerNodeList.size(); i++) {
            ContainerNode containerNode = containerNodeList.get(i);
            if (containerNode != null) {
                List<LeafNode> leafNodeList = containerNode.getChildNodeList();
                for (int j = 0; j < leafNodeList.size(); j++) {
                    LeafNode leafNode = leafNodeList.get(j);
                    if (leafNode instanceof MasterNode) {
                        master = (MasterNode) leafNode;
                    } else if (leafNode instanceof DistributorNode) {
                        dist = (DistributorNode) leafNode;
                    }
                }
            }
        }
        //connection from master to dist
        if (master != null && dist != null) {
            new ArrowConnection(master, dist);
        }
        for (int i = 0; containerNodeList != null && i < containerNodeList.size(); i++) {
            ContainerNode containerNode = containerNodeList.get(i);
            if (containerNode != null) {
                List<LeafNode> leafNodeList = containerNode.getChildNodeList();
                for (int j = 0; j < leafNodeList.size(); j++) {
                    LeafNode leafNode = leafNodeList.get(j);
                    if (leafNode instanceof SlaveNode) {
                        slave = (SlaveNode) leafNode;
                        //connection from dist to slave
                        if (dist != null && slave != null) {
                            new ArrowConnection(dist, slave);
                        }
                    }
                }
            }
        }
    }
}
Also used : MasterNode(com.cubrid.cubridmanager.ui.replication.editor.model.MasterNode) SlaveNode(com.cubrid.cubridmanager.ui.replication.editor.model.SlaveNode) LeafNode(com.cubrid.cubridmanager.ui.replication.editor.model.LeafNode) ArrowConnection(com.cubrid.cubridmanager.ui.replication.editor.model.ArrowConnection) ContainerNode(com.cubrid.cubridmanager.ui.replication.editor.model.ContainerNode) Point(org.eclipse.draw2d.geometry.Point) DistributorNode(com.cubrid.cubridmanager.ui.replication.editor.model.DistributorNode)

Example 2 with ContainerNode

use of com.cubrid.cubridmanager.ui.replication.editor.model.ContainerNode in project cubrid-manager by CUBRID.

the class DeleteNodeCommand method undo.

/**
	 * @see org.eclipse.gef.commands.Command#undo()
	 */
public void undo() {
    if (parent instanceof Diagram) {
        Diagram diagram = (Diagram) parent;
        diagram.addNode((ContainerNode) node);
    } else if (parent instanceof ContainerNode) {
        ContainerNode containerNode = (ContainerNode) parent;
        containerNode.addChildNode((LeafNode) node);
    }
}
Also used : LeafNode(com.cubrid.cubridmanager.ui.replication.editor.model.LeafNode) ContainerNode(com.cubrid.cubridmanager.ui.replication.editor.model.ContainerNode) Diagram(com.cubrid.cubridmanager.ui.replication.editor.model.Diagram)

Example 3 with ContainerNode

use of com.cubrid.cubridmanager.ui.replication.editor.model.ContainerNode in project cubrid-manager by CUBRID.

the class DiagramLayoutEditPolicy method getCreateCommand.

/**
	 * @see org.eclipse.gef.editpolicies.LayoutEditPolicy#getCreateCommand(org.eclipse.gef.requests.CreateRequest)
	 * @param request the CreateRequest
	 * @return a Command to perform a create
	 */
protected Command getCreateCommand(CreateRequest request) {
    if (!(request.getNewObject() instanceof Node)) {
        return null;
    }
    if (!(request.getNewObject() instanceof ContainerNode)) {
        return null;
    }
    CreateContainerNodeCommand cmd = new CreateContainerNodeCommand();
    cmd.setDiagram((Diagram) getHost().getModel());
    cmd.setNode((ContainerNode) request.getNewObject());
    Rectangle constraint = (Rectangle) getConstraintFor(request);
    cmd.setLocation(constraint.getLocation());
    return cmd;
}
Also used : CreateContainerNodeCommand(com.cubrid.cubridmanager.ui.replication.editor.commands.CreateContainerNodeCommand) ContainerNode(com.cubrid.cubridmanager.ui.replication.editor.model.ContainerNode) Node(com.cubrid.cubridmanager.ui.replication.editor.model.Node) Rectangle(org.eclipse.draw2d.geometry.Rectangle) ContainerNode(com.cubrid.cubridmanager.ui.replication.editor.model.ContainerNode)

Example 4 with ContainerNode

use of com.cubrid.cubridmanager.ui.replication.editor.model.ContainerNode in project cubrid-manager by CUBRID.

the class ReplicationEditor method doSave.

/**
	 * @see org.eclipse.ui.part.EditorPart#doSave(org.eclipse.core.runtime.IProgressMonitor)
	 * @param monitor IProgressMonitor
	 */
public void doSave(IProgressMonitor monitor) {
    List<ContainerNode> hostNodeList = diagram.getChildNodeList();
    int hostSize = 0;
    if (hostNodeList != null) {
        hostSize = hostNodeList.size();
    }
    //check the host number,2 at less
    if (hostSize <= 1) {
        CommonUITool.openErrorBox(this.getSite().getShell(), Messages.errInvalidReplDesign);
        monitor.setCanceled(true);
        return;
    }
    //check the host and replication component information integrity
    for (int i = 0; i < hostSize; i++) {
        HostNode host = (HostNode) hostNodeList.get(i);
        if (!host.isValid()) {
            CommonUITool.openErrorBox(this.getSite().getShell(), Messages.bind(Messages.errInvalidHost, host.getName()));
            monitor.setCanceled(true);
            return;
        }
        List<LeafNode> leafNodeList = host.getChildNodeList();
        for (int j = 0; j < leafNodeList.size(); j++) {
            LeafNode node = leafNodeList.get(j);
            if (!node.isValid()) {
                CommonUITool.openErrorBox(this.getSite().getShell(), Messages.bind(Messages.errInvalidReplComponent, node.getName()));
                monitor.setCanceled(true);
                return;
            }
        }
    }
    //check the replication component connection validity
    List<List<Node>> replicationsList = new ArrayList<List<Node>>();
    for (int i = 0; i < hostSize; i++) {
        HostNode host = (HostNode) hostNodeList.get(i);
        List<LeafNode> leafNodeList = host.getChildNodeList();
        for (int j = 0; j < leafNodeList.size(); j++) {
            LeafNode node = leafNodeList.get(j);
            if (node instanceof MasterNode) {
                List<ArrowConnection> connList = node.getOutgoingConnections();
                if (connList == null || connList.isEmpty()) {
                    CommonUITool.openErrorBox(this.getSite().getShell(), Messages.bind(Messages.errInvalidMasterConn1, node.getName()));
                    monitor.setCanceled(true);
                    return;
                } else {
                    for (int k = 0; k < connList.size(); k++) {
                        LOGGER.debug("Replication chain" + k);
                        LOGGER.debug(node.getName());
                        List<Node> replicationList = new ArrayList<Node>();
                        replicationList.add(node);
                        HostNode masterHost = (HostNode) node.getParent();
                        ArrowConnection conn = connList.get(k);
                        HostNode distHost = (HostNode) conn.getTarget().getParent();
                        if (masterHost.getName().equals(distHost.getName())) {
                            CommonUITool.openErrorBox(this.getSite().getShell(), Messages.bind(Messages.errInvalidMasterConn2, new String[] { node.getName(), conn.getTarget().getName() }));
                            monitor.setCanceled(true);
                            return;
                        }
                        createReplChain(replicationList, conn);
                        replicationsList.add(replicationList);
                    }
                }
            } else if (node instanceof DistributorNode) {
                if (node.getIncomingConnections() == null || node.getIncomingConnections().size() == 0) {
                    CommonUITool.openErrorBox(this.getSite().getShell(), Messages.bind(Messages.errInvalidDistConn1, node.getName()));
                    monitor.setCanceled(true);
                    return;
                }
                if (node.getOutgoingConnections() == null || node.getOutgoingConnections().size() == 0) {
                    CommonUITool.openErrorBox(this.getSite().getShell(), Messages.bind(Messages.errInvalidDistConn2, node.getName()));
                    monitor.setCanceled(true);
                    return;
                }
            } else if (node instanceof SlaveNode && (node.getIncomingConnections() == null || node.getIncomingConnections().isEmpty())) {
                CommonUITool.openErrorBox(this.getSite().getShell(), Messages.bind(Messages.errInvalidSlaveConn, node.getName()));
                monitor.setCanceled(true);
                return;
            }
        }
    }
    int count = replicationsList.size();
    if (count <= 0) {
        CommonUITool.openErrorBox(this.getSite().getShell(), Messages.errInvalidReplDesign);
        monitor.setCanceled(true);
        return;
    }
    for (int i = 0; i < count; i++) {
        List<Node> replcationlist = replicationsList.get(i);
        int size = replcationlist.size();
        if (size < 3) {
            CommonUITool.openErrorBox(this.getSite().getShell(), Messages.errInvalidReplDesign);
            monitor.setCanceled(true);
            return;
        }
        if (!(replcationlist.get(size - 1) instanceof SlaveNode)) {
            CommonUITool.openErrorBox(this.getSite().getShell(), Messages.errInvalidReplDesign);
            monitor.setCanceled(true);
            return;
        }
        //check the connection validity,
        for (int j = 1; j + 1 < size; j++) {
            Node node1 = (Node) replcationlist.get(j).getParent();
            Node node2 = (Node) replcationlist.get(j + 1).getParent();
            //from the slave to the distributor can not in the same host
            if (j % 2 == 0) {
                if (node1.getName().equals(node2.getName())) {
                    CommonUITool.openErrorBox(this.getSite().getShell(), Messages.bind(Messages.errInvalidConn1, new String[] { node1.getName(), node2.getName() }));
                    monitor.setCanceled(true);
                    return;
                }
            } else {
                //from the distributor to the slave must be in the same host
                if (!node1.getName().equals(node2.getName())) {
                    CommonUITool.openErrorBox(this.getSite().getShell(), Messages.bind(Messages.errInvalidConn2, new String[] { node1.getName(), node2.getName() }));
                    monitor.setCanceled(true);
                    return;
                }
            }
        }
    }
    if (!CommonUITool.openConfirmBox(Messages.msgConfirmCreateRepl)) {
        return;
    }
    isEditable = false;
    getCommandStack().flush();
    setDirty(false);
    createReplication(replicationsList);
}
Also used : MasterNode(com.cubrid.cubridmanager.ui.replication.editor.model.MasterNode) SlaveNode(com.cubrid.cubridmanager.ui.replication.editor.model.SlaveNode) HostNode(com.cubrid.cubridmanager.ui.replication.editor.model.HostNode) ContainerNode(com.cubrid.cubridmanager.ui.replication.editor.model.ContainerNode) SlaveNode(com.cubrid.cubridmanager.ui.replication.editor.model.SlaveNode) ICubridNode(com.cubrid.common.ui.spi.model.ICubridNode) MasterNode(com.cubrid.cubridmanager.ui.replication.editor.model.MasterNode) Node(com.cubrid.cubridmanager.ui.replication.editor.model.Node) LeafNode(com.cubrid.cubridmanager.ui.replication.editor.model.LeafNode) DistributorNode(com.cubrid.cubridmanager.ui.replication.editor.model.DistributorNode) HostNode(com.cubrid.cubridmanager.ui.replication.editor.model.HostNode) ArrayList(java.util.ArrayList) Point(org.eclipse.draw2d.geometry.Point) LeafNode(com.cubrid.cubridmanager.ui.replication.editor.model.LeafNode) ArrowConnection(com.cubrid.cubridmanager.ui.replication.editor.model.ArrowConnection) ContainerNode(com.cubrid.cubridmanager.ui.replication.editor.model.ContainerNode) List(java.util.List) ArrayList(java.util.ArrayList) DistributorNode(com.cubrid.cubridmanager.ui.replication.editor.model.DistributorNode)

Example 5 with ContainerNode

use of com.cubrid.cubridmanager.ui.replication.editor.model.ContainerNode in project cubrid-manager by CUBRID.

the class SetHostInfoDialog method checkHostExist.

/**
	 * Check whether the host exist
	 * 
	 * @param ip the ip address
	 * @param port the port
	 * @return <code>true</code> if exist;<code>false</code>otherwise
	 */
private boolean checkHostExist(String ip, String port) {
    boolean isHostExist = false;
    Diagram diagram = (Diagram) hostInfo.getParent();
    List<ContainerNode> nodeList = diagram.getChildNodeList();
    for (int i = 0; nodeList != null && i < nodeList.size(); i++) {
        ContainerNode node = nodeList.get(i);
        if (node instanceof HostNode) {
            HostNode host = (HostNode) node;
            String name = host.getName();
            if (name.equals(ip + ":" + port) && !host.equals(hostInfo)) {
                isHostExist = true;
                break;
            }
        }
    }
    return isHostExist;
}
Also used : HostNode(com.cubrid.cubridmanager.ui.replication.editor.model.HostNode) ContainerNode(com.cubrid.cubridmanager.ui.replication.editor.model.ContainerNode) Diagram(com.cubrid.cubridmanager.ui.replication.editor.model.Diagram)

Aggregations

ContainerNode (com.cubrid.cubridmanager.ui.replication.editor.model.ContainerNode)7 LeafNode (com.cubrid.cubridmanager.ui.replication.editor.model.LeafNode)4 Diagram (com.cubrid.cubridmanager.ui.replication.editor.model.Diagram)3 Point (org.eclipse.draw2d.geometry.Point)3 ArrowConnection (com.cubrid.cubridmanager.ui.replication.editor.model.ArrowConnection)2 DistributorNode (com.cubrid.cubridmanager.ui.replication.editor.model.DistributorNode)2 HostNode (com.cubrid.cubridmanager.ui.replication.editor.model.HostNode)2 MasterNode (com.cubrid.cubridmanager.ui.replication.editor.model.MasterNode)2 Node (com.cubrid.cubridmanager.ui.replication.editor.model.Node)2 SlaveNode (com.cubrid.cubridmanager.ui.replication.editor.model.SlaveNode)2 ICubridNode (com.cubrid.common.ui.spi.model.ICubridNode)1 CreateContainerNodeCommand (com.cubrid.cubridmanager.ui.replication.editor.commands.CreateContainerNodeCommand)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1