01: /*
02: * The contents of this file are subject to the terms of the Common Development
03: * and Distribution License (the License). You may not use this file except in
04: * compliance with the License.
05: *
06: * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
07: * or http://www.netbeans.org/cddl.txt.
08: *
09: * When distributing Covered Code, include this CDDL Header Notice in each file
10: * and include the License file at http://www.netbeans.org/cddl.txt.
11: * If applicable, add the following below the CDDL Header, with the fields
12: * enclosed by brackets [] replaced by your own identifying information:
13: * "Portions Copyrighted [year] [name of copyright owner]"
14: *
15: * The Original Software is NetBeans. The Initial Developer of the Original
16: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17: * Microsystems, Inc. All Rights Reserved.
18: */
19: package org.netbeans.modules.bpel.design.phmode;
20:
21: import java.util.Collections;
22: import java.util.List;
23: import org.netbeans.modules.bpel.design.DesignView;
24: import org.netbeans.modules.bpel.design.model.DiagramModel;
25: import org.netbeans.modules.bpel.design.selection.EntitySelectionModel;
26: import org.netbeans.modules.bpel.design.selection.PlaceHolder;
27: import org.netbeans.modules.bpel.design.selection.PlaceHolderManager;
28:
29: /**
30: *
31: * @author Vitaly Bychkov
32: */
33: public class PlaceHolderIteratorImpl implements PlaceHolderIterator {
34:
35: private PlaceHolderManager phManager;
36: private PlaceHolderSelectionModel selectionModel;
37:
38: public PlaceHolderIteratorImpl(PlaceHolderManager phManager,
39: PlaceHolderSelectionModel selectionModel) {
40: assert phManager != null && selectionModel != null;
41:
42: this .phManager = phManager;
43: this .selectionModel = selectionModel;
44: }
45:
46: public PlaceHolder next() {
47: PlaceHolder nextPh = getNextPlaceHolder(selectionModel
48: .getSelectedPlaceHolder());
49:
50: return nextPh;
51: }
52:
53: public PlaceHolder previous() {
54: PlaceHolder ph = selectionModel.getSelectedPlaceHolder();
55:
56: return getPreviousPlaceHolder(ph);
57: }
58:
59: // TODO m
60: private PlaceHolder getNextPlaceHolder(PlaceHolder ph) {
61: PlaceHolder nextPh = null;
62: List<PlaceHolder> phs = phManager.getPlaceHolders();
63: if (phs != null && phs.size() > 0) {
64: if (ph == null) {
65: nextPh = phs.get(0);
66: } else {
67: int phIndex = phs.indexOf(ph);
68: int nextPhIndex = phIndex < phs.size() - 1 ? phIndex + 1
69: : 0;
70: nextPh = phs.get(nextPhIndex);
71: }
72: }
73: return nextPh;
74: }
75:
76: // TODO m
77: private PlaceHolder getPreviousPlaceHolder(PlaceHolder ph) {
78: PlaceHolder prevPh = null;
79: List<PlaceHolder> phs = phManager.getPlaceHolders();
80: if (phs != null && phs.size() > 0) {
81: if (ph == null) {
82: prevPh = phs.get(phs.size() - 1);
83: } else {
84: int phIndex = phs.indexOf(ph);
85: int prevPhIndex = phIndex > 0 ? phIndex - 1 : phs
86: .size() - 1;
87: prevPh = phs.get(prevPhIndex);
88: }
89: }
90: return prevPh;
91: }
92:
93: }
|