001: package newprocess.diagram.cust.policies;
002:
003: import java.util.List;
004:
005: import newprocess.diagram.edit.parts.ConditionTermConditionProxyEditPart;
006: import newprocess.diagram.edit.parts.ConditionTermEditPart;
007: import newprocess.diagram.edit.parts.OperatorTermSubTermEditPart;
008:
009: import org.eclipse.gef.EditPart;
010: import org.eclipse.gef.editpolicies.SelectionEditPolicy;
011:
012: /**
013: * @author sh & ts
014: * highlights the link when it is selected
015: */
016: public class HighlightEditPolicy extends SelectionEditPolicy {
017:
018: /**
019: * removes the highlighting of the figure chain
020: */
021: @Override
022: protected void hideSelection() {
023: makeSelection(0);
024: }
025:
026: /**
027: * does the highlighting of the figure chain
028: */
029: @Override
030: protected void showSelection() {
031: makeSelection(2);
032: }
033:
034: private void makeSelection(int value) {
035: EditPart host = getHost();
036: ConditionTermConditionProxyEditPart ppEP = null;
037: ConditionTermEditPart cpEP = null;
038: OperatorTermSubTermEditPart subtermEP = null;
039:
040: if (host instanceof ConditionTermConditionProxyEditPart) {
041: ppEP = (ConditionTermConditionProxyEditPart) host;
042: cpEP = getConditionTermEditPart(ppEP);
043: subtermEP = getOperatorTermSubTermEditPart(cpEP);
044: }
045:
046: if (host instanceof ConditionTermEditPart) {
047: cpEP = (ConditionTermEditPart) host;
048: ppEP = getConditionTermConditionProxyEditPart(cpEP);
049: subtermEP = getOperatorTermSubTermEditPart(cpEP);
050: }
051:
052: if (host instanceof OperatorTermSubTermEditPart) {
053: subtermEP = (OperatorTermSubTermEditPart) host;
054: cpEP = getConditionTermEditpart(subtermEP);
055: ppEP = getConditionTermConditionProxyEditPart(cpEP);
056: }
057:
058: if (ppEP != null && ppEP.getSelected() != value)
059: ppEP.setSelected(value);
060:
061: if (cpEP != null && cpEP.getSelected() != value)
062: cpEP.setSelected(value);
063:
064: if (subtermEP != null && subtermEP.getSelected() != value)
065: subtermEP.setSelected(value);
066: }
067:
068: /**
069: * returns the ConditionTermProxyEditPart of the given ConditionTermEditPart
070: * @param portEP
071: * @return
072: */
073: private ConditionTermConditionProxyEditPart getConditionTermConditionProxyEditPart(
074: ConditionTermEditPart portEP) {
075: if (portEP == null)
076: return null;
077: List ppList = portEP.getSourceConnections();
078: if (ppList == null || ppList.isEmpty())
079: return null;
080: if (ppList.get(0) instanceof ConditionTermConditionProxyEditPart)
081: return (ConditionTermConditionProxyEditPart) ppList.get(0);
082: return null;
083: }
084:
085: /**
086: * returns the OperatorTermSubTermEditPart of the given TermEditPart
087: * @param portEP
088: * @return
089: */
090: private OperatorTermSubTermEditPart getOperatorTermSubTermEditPart(
091: ConditionTermEditPart portEP) {
092: if (portEP == null)
093: return null;
094: List opList = portEP.getTargetConnections();
095: if (opList == null || opList.isEmpty())
096: return null;
097: if (opList.get(0) instanceof OperatorTermSubTermEditPart)
098: return (OperatorTermSubTermEditPart) opList.get(0);
099: return null;
100: }
101:
102: private ConditionTermEditPart getConditionTermEditPart(
103: ConditionTermConditionProxyEditPart ppEP) {
104: if (ppEP == null)
105: return null;
106: EditPart source = ppEP.getSource();
107: if (source instanceof ConditionTermEditPart == false)
108: return null;
109: return (ConditionTermEditPart) source;
110: }
111:
112: private ConditionTermEditPart getConditionTermEditpart(
113: OperatorTermSubTermEditPart subtermEP) {
114: EditPart target = subtermEP.getTarget();
115: if (target instanceof ConditionTermEditPart)
116: return (ConditionTermEditPart) target;
117: else
118: return null;
119: }
120: }
|