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 179526
Collapse All | Expand All

(-)a/core.windows/src/org/netbeans/core/windows/model/DefaultModel.java (-3 / +14 lines)
Lines 65-70 Link Here
65
import org.netbeans.core.windows.TopComponentGroupImpl;
65
import org.netbeans.core.windows.TopComponentGroupImpl;
66
import org.netbeans.core.windows.WindowManagerImpl;
66
import org.netbeans.core.windows.WindowManagerImpl;
67
import org.netbeans.core.windows.WindowSystemSnapshot;
67
import org.netbeans.core.windows.WindowSystemSnapshot;
68
import org.openide.windows.RetainLocation;
68
import org.openide.windows.TopComponent;
69
import org.openide.windows.TopComponent;
69
70
70
71
Lines 249-257 Link Here
249
            modesSubModel.addMode(mode, constraints);
250
            modesSubModel.addMode(mode, constraints);
250
        }
251
        }
251
    }
252
    }
252
    
253
253
254
    
254
255
255
    // XXX
256
    // XXX
256
    public void addModeToSide(ModeImpl mode, ModeImpl attachMode, String side) {
257
    public void addModeToSide(ModeImpl mode, ModeImpl attachMode, String side) {
257
        synchronized(LOCK_MODES) {
258
        synchronized(LOCK_MODES) {
Lines 784-790 Link Here
784
    public boolean isModePermanent(ModeImpl mode) {
785
    public boolean isModePermanent(ModeImpl mode) {
785
        ModeModel modeModel = getModelForMode(mode);
786
        ModeModel modeModel = getModelForMode(mode);
786
        if(modeModel != null) {
787
        if(modeModel != null) {
787
            return modeModel.isPermanent();
788
            boolean result = modeModel.isPermanent();
789
            if (!result) {
790
                for (TopComponent tc : mode.getTopComponents()) {
791
                    result |= tc.getClass().getAnnotation(RetainLocation.class)
792
                            != null;
793
                    if (result) {
794
                        break;
795
                    }
796
                }
797
            }
798
            return result;
788
        } else {
799
        } else {
789
            return false;
800
            return false;
790
        }
801
        }
(-)a/openide.windows/apichanges.xml (-1 / +33 lines)
Lines 48-54 Link Here
48
</apidefs>
48
</apidefs>
49
<changes>
49
<changes>
50
50
51
51
<change id="retain.non.persistent.topcomponent.locations">
52
    <api name="winsys"/>
53
    <summary>Annotation to retain the location of non-persistent TopComponents
54
    if the user drags them to another location on the screen.
55
    </summary>
56
    <version major="6" minor="32"/>
57
    <date day="14" month="1" year="2010"/>
58
    <author login="tboudreau"/>
59
    <compatibility addition="yes" binary="compatible" source="compatible"
60
    semantic="compatible" deprecation="no" deletion="no" modification="no"/>
61
    <description>
62
        Added an annotation, <code>org.openide.windows.RetainLocation</code>
63
        which can be applied to TopComponents whose
64
        persistence type is PERSISTENCE_NEVER.  There has been a long-term
65
        problem that such components can be defined as singleton components,
66
        and the first time they are opened, they appear in the correct place.
67
        However, on restart or after the first time they are closed, their
68
        persistence information, including the containing Mode, is lost, and
69
        thereafter they open in the editor area.
70
        <p/>
71
        This patch does not affect the current behavior of such components.
72
        However, if you add this annotation to the component, it will remember
73
        (storage in NbPreferences) the ID of its last known parent mode.  A
74
        minor patch to the window system's code for deciding if a Mode should
75
        be persistent causes it to now interpret any Mode containing a
76
        TopComponent annotated with <code>RetainLocation</code> as being one
77
        it should persist, so that if the user creates a transient Mode by
78
        dragging the window to a new location on screen, the data about that
79
        location is not lost on shutdown.
80
    </description>
81
    <class package="org.openide.windows" name="RetainLocation"/>
82
    <issue number="168060"/>
83
</change>
52
<change id="wm_openedtcs">
84
<change id="wm_openedtcs">
53
    <api name="winsys"/>
85
    <api name="winsys"/>
54
    <summary>New method to retrieve the list of TopComponents opened in a Mode.</summary>
86
    <summary>New method to retrieve the list of TopComponents opened in a Mode.</summary>
(-)a/openide.windows/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.windows
2
OpenIDE-Module: org.openide.windows
3
OpenIDE-Module-Specification-Version: 6.31
3
OpenIDE-Module-Specification-Version: 6.32
4
OpenIDE-Module-Localizing-Bundle: org/openide/windows/Bundle.properties
4
OpenIDE-Module-Localizing-Bundle: org/openide/windows/Bundle.properties
5
AutoUpdate-Essential-Module: true
5
AutoUpdate-Essential-Module: true
6
6
(-)a/openide.windows/src/org/openide/windows/RetainLocation.java (+63 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
5
 *
6
 * The contents of this file are subject to the terms of either the GNU
7
 * General Public License Version 2 only ("GPL") or the Common
8
 * Development and Distribution License("CDDL") (collectively, the
9
 * "License"). You may not use this file except in compliance with the
10
 * License. You can obtain a copy of the License at
11
 * http://www.netbeans.org/cddl-gplv2.html
12
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
 * specific language governing permissions and limitations under the
14
 * License.  When distributing the software, include this License Header
15
 * Notice in each file and include the License file at
16
 * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
17
 * particular file as subject to the "Classpath" exception as provided
18
 * by Sun in the GPL Version 2 section of the License file that
19
 * accompanied this code. If applicable, add the following below the
20
 * License Header, with the fields enclosed by brackets [] replaced by
21
 * your own identifying information:
22
 * "Portions Copyrighted [year] [name of copyright owner]"
23
 *
24
 * If you wish your version of this file to be governed by only the CDDL
25
 * or only the GPL Version 2, indicate your decision by adding
26
 * "[Contributor] elects to include this software in this distribution
27
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
28
 * single choice of license, a recipient has the option to distribute
29
 * your version of this file under either the CDDL, the GPL Version 2 or
30
 * to extend the choice of license to its licensees as provided above.
31
 * However, if you add GPL Version 2 code and therefore, elected the GPL
32
 * Version 2 license, then the option applies only if the new code is
33
 * made subject to such option by the copyright holder.
34
 *
35
 * Contributor(s):
36
 *
37
 * Portions Copyrighted 2010 Sun Microsystems, Inc.
38
 */
39
40
package org.openide.windows;
41
42
import java.lang.annotation.ElementType;
43
import java.lang.annotation.Target;
44
import java.lang.annotation.Retention;
45
import static java.lang.annotation.RetentionPolicy.*;
46
47
/**
48
 * Annotation which can be applied to TopComponents whose persistence type
49
 * is PERSISTENCE_NEVER to allow them to remember the location they were
50
 * docked into
51
 *
52
 * @since 6.32
53
 * @author Tim Boudreau
54
 */
55
@Retention (RUNTIME)
56
@Target (ElementType.TYPE)
57
public @interface RetainLocation {
58
    /** The name of the docking location (Mode) this component should be
59
     * docked into by default, if there is no stored value.
60
     * @return The Mode name
61
     */
62
    String value();
63
}
(-)a/openide.windows/src/org/openide/windows/TopComponent.java (-1 / +53 lines)
Lines 91-100 Link Here
91
import org.openide.util.HelpCtx;
91
import org.openide.util.HelpCtx;
92
import org.openide.util.Lookup;
92
import org.openide.util.Lookup;
93
import org.openide.util.NbBundle;
93
import org.openide.util.NbBundle;
94
import org.openide.util.NbPreferences;
94
import org.openide.util.Utilities;
95
import org.openide.util.Utilities;
95
import org.openide.util.WeakListeners;
96
import org.openide.util.WeakListeners;
96
import org.openide.util.WeakSet;
97
import org.openide.util.WeakSet;
97
import org.openide.util.actions.NodeAction;
98
import org.openide.util.actions.SystemAction;
98
import org.openide.util.actions.SystemAction;
99
99
100
/**
100
/**
Lines 243-248 Link Here
243
     */
243
     */
244
    public static final String PROP_MAXIMIZATION_DISABLED = "netbeans.winsys.tc.maximization_disabled"; //NOI18N
244
    public static final String PROP_MAXIMIZATION_DISABLED = "netbeans.winsys.tc.maximization_disabled"; //NOI18N
245
245
246
    private transient String modeName;
247
246
    /** Create a top component.
248
    /** Create a top component.
247
    */
249
    */
248
    public TopComponent() {
250
    public TopComponent() {
Lines 270-275 Link Here
270
        initActionMap(lookup);
272
        initActionMap(lookup);
271
    }
273
    }
272
274
275
    private static final String MODE_ID_PREFERENCES_KEY_INFIX = "_modeId_"; //NOI18N
276
    @Override
277
    public void addNotify() {
278
        super.addNotify();
279
        if (isPersistLocation()) {
280
            Mode m = WindowManager.getDefault().findMode(this);
281
            if (m != null) {
282
                modeName = m.getName();
283
                if (modeName == null) {
284
                    modeName = getClass().getAnnotation(
285
                               RetainLocation.class).value();
286
                }
287
                NbPreferences.forModule(getClass()).put(getModeIdKey(), modeName);
288
            }
289
        }
290
    }
291
292
    private boolean isPersistLocation() {
293
        boolean result = getPersistenceType() == PERSISTENCE_NEVER &&
294
               getClass().getAnnotation(RetainLocation.class) != null;
295
        assert annotationAndPersistenceTypeAreCompatible();
296
        return result;
297
    }
298
299
    private boolean annotationAndPersistenceTypeAreCompatible() {
300
        if (getPersistenceType() != PERSISTENCE_NEVER &&
301
            getClass().getAnnotation(RetainLocation.class) != null) {
302
            Logger.getLogger(TopComponent.class.getName()).log(Level.WARNING,
303
                "Useless to annotate a TopComponent with @RetainLocation if " + //NOI18N
304
                "its persistence type is not PERSISTENCE_NEVER: {0}", //NOI18N
305
                new Object[] { getClass().getName() });
306
        }
307
        return true;
308
    }
309
310
    private String getModeIdKey() {
311
        return getClass().getName() + MODE_ID_PREFERENCES_KEY_INFIX + preferredID();
312
    }
313
273
    // It is necessary so the old actions (clone and close from org.openide.actions package) remain working.
314
    // It is necessary so the old actions (clone and close from org.openide.actions package) remain working.
274
315
275
    /** Initialized <code>ActionMap</code> of this <code>TopComponent</code>.
316
    /** Initialized <code>ActionMap</code> of this <code>TopComponent</code>.
Lines 432-437 Link Here
432
     * @deprecated Use {@link #open()} instead. */
473
     * @deprecated Use {@link #open()} instead. */
433
    @Deprecated
474
    @Deprecated
434
    public void open(Workspace workspace) {
475
    public void open(Workspace workspace) {
476
        if (isPersistLocation()) {
477
            modeName = NbPreferences.forModule(getClass()).get(getModeIdKey(), null);
478
            if (modeName == null) {
479
                modeName = getClass().getAnnotation(
480
                           RetainLocation.class).value();
481
            }
482
            Mode mode = WindowManager.getDefault().findMode(modeName);
483
            if (mode != null) {
484
                mode.dockInto(this);
485
            }
486
        }
435
        WindowManager.getDefault().topComponentOpen(this);
487
        WindowManager.getDefault().topComponentOpen(this);
436
    }
488
    }
437
    
489
    

Return to bug 179526