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 |
|