Lines 42-47
Link Here
|
42 |
|
42 |
|
43 |
package org.openide.windows; |
43 |
package org.openide.windows; |
44 |
|
44 |
|
|
|
45 |
import java.util.logging.Level; |
46 |
import java.util.logging.Logger; |
47 |
import org.netbeans.api.annotations.common.CheckForNull; |
45 |
import org.openide.windows.IOFolding.FoldHandleDefinition; |
48 |
import org.openide.windows.IOFolding.FoldHandleDefinition; |
46 |
|
49 |
|
47 |
/** |
50 |
/** |
Lines 54-59
Link Here
|
54 |
public final class FoldHandle { |
57 |
public final class FoldHandle { |
55 |
|
58 |
|
56 |
private final FoldHandleDefinition definition; |
59 |
private final FoldHandleDefinition definition; |
|
|
60 |
private static final Logger LOG = Logger.getLogger(FoldHandle.class.getName()); |
61 |
private FoldHandle currentChild; |
62 |
private boolean finished = false; |
57 |
|
63 |
|
58 |
FoldHandle(FoldHandleDefinition definition) { |
64 |
FoldHandle(FoldHandleDefinition definition) { |
59 |
this.definition = definition; |
65 |
this.definition = definition; |
Lines 67-72
Link Here
|
67 |
*/ |
73 |
*/ |
68 |
public void finish() { |
74 |
public void finish() { |
69 |
definition.finish(); |
75 |
definition.finish(); |
|
|
76 |
finished = true; |
70 |
} |
77 |
} |
71 |
|
78 |
|
72 |
/** |
79 |
/** |
Lines 75-84
Link Here
|
75 |
* @param expanded True to expand the new fold, false to collapse it, parent |
82 |
* @param expanded True to expand the new fold, false to collapse it, parent |
76 |
* folds will not be collapsed/expanded. |
83 |
* folds will not be collapsed/expanded. |
77 |
* @return Handle for the newly created fold. |
84 |
* @return Handle for the newly created fold. |
78 |
* @throws IllegalStateException if the fold has been already finished. |
85 |
* @throws IllegalStateException if the fold has been already finished, or |
|
|
86 |
* if an unfinished nested fold exists. |
79 |
*/ |
87 |
*/ |
80 |
public FoldHandle startFold(boolean expanded) { |
88 |
public FoldHandle startFold(boolean expanded) { |
81 |
return new FoldHandle(definition.startFold(expanded)); |
89 |
currentChild = new FoldHandle(definition.startFold(expanded)); |
|
|
90 |
return currentChild; |
82 |
} |
91 |
} |
83 |
|
92 |
|
84 |
/** |
93 |
/** |
Lines 91-94
Link Here
|
91 |
public void setExpanded(boolean expanded) { |
100 |
public void setExpanded(boolean expanded) { |
92 |
definition.setExpanded(expanded); |
101 |
definition.setExpanded(expanded); |
93 |
} |
102 |
} |
|
|
103 |
|
104 |
/** |
105 |
* Check whether this fold handle has been finished. |
106 |
* |
107 |
* @return True if {@link #finish()} or {@link #silentFinish()} has been |
108 |
* already called on this fold handle, false otherwise. |
109 |
* |
110 |
* @since openide.io/1.42 |
111 |
*/ |
112 |
public boolean isFinished() { |
113 |
return finished; |
114 |
} |
115 |
|
116 |
/** |
117 |
* Get handle created by the last invocation of {@link #startFold(boolean)} |
118 |
* or {@link #silentStartFold(boolean)}. The handle can be finished or |
119 |
* unfinished. |
120 |
* |
121 |
* @return The last started nested fold. Can be null. |
122 |
* |
123 |
* @since openide.io/1.42 |
124 |
*/ |
125 |
public @CheckForNull FoldHandle getLastNestedFold() { |
126 |
return currentChild; |
127 |
} |
128 |
|
129 |
/** |
130 |
* Get current nested fold. Similar to {@link #getLastNestedFold()}, but |
131 |
* returns null if the last nested fold has been already finished. |
132 |
* |
133 |
* @return The last unfinished nested fold or null. |
134 |
* |
135 |
* @since openide.io/1.42 |
136 |
*/ |
137 |
public @CheckForNull FoldHandle getCurrentNestedFold() { |
138 |
return (currentChild != null && !currentChild.isFinished()) |
139 |
? currentChild |
140 |
: null; |
141 |
} |
142 |
|
143 |
/** |
144 |
* Similar to {@link #finish()}, but no exception is thrown if the fold |
145 |
* handle has been already finished. If an unfinished child fold exists, it |
146 |
* will be finished too. Any exception that could happen will be caught and |
147 |
* logged. |
148 |
* |
149 |
* @since openide.io/1.42 |
150 |
*/ |
151 |
public void silentFinish() { |
152 |
if (!finished) { |
153 |
if (currentChild != null && !currentChild.finished) { |
154 |
currentChild.silentFinish(); |
155 |
} |
156 |
try { |
157 |
finish(); |
158 |
} catch (Exception e) { |
159 |
LOG.log(Level.FINE, null, e); |
160 |
} |
161 |
} |
162 |
} |
163 |
|
164 |
/** |
165 |
* Similar to {@link #startFold(boolean)}, but no exception is thrown if the |
166 |
* fold is already finished, as well as if an unfinished nested fold exists. |
167 |
* If an unfinished nested fold exists, it will be finished before creation |
168 |
* of the new one. |
169 |
* |
170 |
* @param expanded True to expand the new fold, false to collapse it, parent |
171 |
* folds will not be collapsed/expanded. |
172 |
* @return The new fold handle, or null if it cannot be created. |
173 |
* |
174 |
* @since openide.io/1.42 |
175 |
*/ |
176 |
public @CheckForNull FoldHandle silentStartFold(boolean expanded) { |
177 |
if (!finished) { |
178 |
if (currentChild != null && !currentChild.finished) { |
179 |
currentChild.silentFinish(); |
180 |
} |
181 |
try { |
182 |
return startFold(expanded); |
183 |
} catch (Exception e) { |
184 |
LOG.log(Level.FINE, null, e); |
185 |
return null; |
186 |
} |
187 |
} else { |
188 |
LOG.log(Level.FINE, "silentStartFold - already finished"); //NOI18N |
189 |
return null; |
190 |
} |
191 |
} |
94 |
} |
192 |
} |