This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 232316
Collapse All | Expand All

(-)a/openide.io/apichanges.xml (+17 lines)
Lines 107-112 Link Here
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
107
    <!-- ACTUAL CHANGES BEGIN HERE: -->
108
108
109
<changes>
109
<changes>
110
    <change id="enhancedFoldHandleApi">
111
      <api name="io"/>
112
      <summary>Created new user-friendly methods for working with FoldHandle instances.</summary>
113
      <version major="1" minor="42"/>
114
      <date day="17" month="7" year="2013"/>
115
      <author login="jhavlin"/>
116
      <compatibility addition="yes" binary="compatible" semantic="compatible" />
117
      <description>
118
          <p>
119
              Added methods that provide better info about state of fold
120
              handles, and methods that handle unexpected situations silently
121
              instead of throwing exceptions.
122
          </p>
123
      </description>
124
      <class package="org.openide.windows" name="FoldHandle"/>
125
      <issue number="232316" />
126
    </change>
110
    <change id="coloredLoggingText">
127
    <change id="coloredLoggingText">
111
      <api name="io"/>
128
      <api name="io"/>
112
      <summary>Added LOG_SUCCESS, LOG_FAILURE, LOG_WARNING and LOG_DEBUG into IOColors.OutputType to be able to specify a color of logging messages.</summary>
129
      <summary>Added LOG_SUCCESS, LOG_FAILURE, LOG_WARNING and LOG_DEBUG into IOColors.OutputType to be able to specify a color of logging messages.</summary>
(-)a/openide.io/manifest.mf (-1 / +1 lines)
Lines 1-6 Link Here
1
Manifest-Version: 1.0
1
Manifest-Version: 1.0
2
OpenIDE-Module: org.openide.io
2
OpenIDE-Module: org.openide.io
3
OpenIDE-Module-Specification-Version: 1.41
3
OpenIDE-Module-Specification-Version: 1.42
4
OpenIDE-Module-Localizing-Bundle: org/openide/io/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/openide/io/Bundle.properties
5
OpenIDE-Module-Recommends: org.openide.windows.IOProvider, org.openide.windows.IOContainer$Provider
5
OpenIDE-Module-Recommends: org.openide.windows.IOProvider, org.openide.windows.IOContainer$Provider
6
AutoUpdate-Essential-Module: true
6
AutoUpdate-Essential-Module: true
(-)a/openide.io/src/org/openide/windows/FoldHandle.java (-2 / +100 lines)
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
}
(-)a/openide.io/test/unit/src/org/openide/windows/IOFoldingTest.java (-1 / +43 lines)
Lines 96-101 Link Here
96
        assertFalse(IOFolding.isSupported(new DummyInputOutput()));
96
        assertFalse(IOFolding.isSupported(new DummyInputOutput()));
97
    }
97
    }
98
98
99
    @Test
100
    public void testIsFinished() {
101
        InputOutputWithFolding io = new InputOutputWithFolding();
102
        FoldHandle fold1 = IOFolding.startFold(io, true);
103
        assertFalse(fold1.isFinished());
104
        FoldHandle fold2 = fold1.startFold(true);
105
        assertFalse(fold2.isFinished());
106
        fold2.finish();
107
        assertTrue(fold2.isFinished());
108
        fold1.finish();
109
        assertTrue(fold1.isFinished());
110
    }
111
112
    @Test
113
    public void testSilentFinish() {
114
        InputOutputWithFolding io = new InputOutputWithFolding();
115
        FoldHandle fold1 = IOFolding.startFold(io, true);
116
        FoldHandle fold2 = fold1.startFold(true);
117
        fold1.silentFinish();
118
        assertTrue(fold2.isFinished());
119
        fold1.silentFinish(); // no exception when calling again
120
        fold1.silentFinish(); // still no exception
121
    }
122
123
    @Test
124
    public void testSilentFoldStart() {
125
        InputOutputWithFolding io = new InputOutputWithFolding();
126
        FoldHandle fold1 = IOFolding.startFold(io, true);
127
        FoldHandle fold2 = fold1.startFold(true);
128
        FoldHandle fold3 = fold1.silentStartFold(true);
129
        assertTrue(fold2.isFinished());
130
        assertNotNull(fold3);
131
        fold1.silentFinish();
132
        assertTrue(fold1.isFinished());
133
        FoldHandle fold4 = fold1.silentStartFold(true);
134
        assertNull(fold4);
135
    }
136
99
    /**
137
    /**
100
     * Dummy InputOutput that supports folding.
138
     * Dummy InputOutput that supports folding.
101
     */
139
     */
Lines 129-134 Link Here
129
167
130
                private DummyFoldHandleDef nested = null;
168
                private DummyFoldHandleDef nested = null;
131
                private final DummyFoldHandleDef parent;
169
                private final DummyFoldHandleDef parent;
170
                private boolean finished = false;
132
171
133
                public DummyFoldHandleDef(DummyFoldHandleDef parent) {
172
                public DummyFoldHandleDef(DummyFoldHandleDef parent) {
134
                    this.parent = parent;
173
                    this.parent = parent;
Lines 144-154 Link Here
144
                        parent.nested = null;
183
                        parent.nested = null;
145
                    }
184
                    }
146
                    currentLevel--;
185
                    currentLevel--;
186
                    finished = true;
147
                }
187
                }
148
188
149
                @Override
189
                @Override
150
                public FoldHandleDefinition startFold(boolean expanded) {
190
                public FoldHandleDefinition startFold(boolean expanded) {
151
                    if (nested != null) {
191
                    if (finished) {
192
                        throw new IllegalStateException("Already finished.");
193
                    } else if (nested != null) {
152
                        throw new IllegalStateException("Last fold not finished.");
194
                        throw new IllegalStateException("Last fold not finished.");
153
                    } else {
195
                    } else {
154
                        nested = new DummyFoldHandleDef(this);
196
                        nested = new DummyFoldHandleDef(this);

Return to bug 232316