Lines 52-60
Link Here
|
52 |
import java.beans.beancontext.BeanContextChildComponentProxy; |
52 |
import java.beans.beancontext.BeanContextChildComponentProxy; |
53 |
import java.lang.ref.Reference; |
53 |
import java.lang.ref.Reference; |
54 |
import java.lang.ref.WeakReference; |
54 |
import java.lang.ref.WeakReference; |
|
|
55 |
import java.lang.reflect.Method; |
55 |
import java.util.ArrayList; |
56 |
import java.util.ArrayList; |
|
|
57 |
import java.util.Collections; |
56 |
import java.util.HashMap; |
58 |
import java.util.HashMap; |
57 |
import java.util.HashSet; |
59 |
import java.util.HashSet; |
|
|
60 |
import java.util.LinkedHashMap; |
58 |
import java.util.LinkedList; |
61 |
import java.util.LinkedList; |
59 |
import java.util.List; |
62 |
import java.util.List; |
60 |
import java.util.Map; |
63 |
import java.util.Map; |
Lines 71-76
Link Here
|
71 |
import org.netbeans.api.debugger.Properties; |
74 |
import org.netbeans.api.debugger.Properties; |
72 |
import org.netbeans.modules.debugger.ui.actions.DebuggerAction; |
75 |
import org.netbeans.modules.debugger.ui.actions.DebuggerAction; |
73 |
import org.netbeans.spi.debugger.ActionsProvider; |
76 |
import org.netbeans.spi.debugger.ActionsProvider; |
|
|
77 |
import org.netbeans.spi.debugger.ui.EngineComponentsProvider; |
78 |
import org.netbeans.spi.debugger.ui.EngineComponentsProvider.ComponentInfo; |
74 |
import org.openide.awt.Toolbar; |
79 |
import org.openide.awt.Toolbar; |
75 |
import org.openide.awt.ToolbarPool; |
80 |
import org.openide.awt.ToolbarPool; |
76 |
import org.openide.util.Exceptions; |
81 |
import org.openide.util.Exceptions; |
Lines 92-99
Link Here
|
92 |
private static final String PROPERTY_CLOSED_TC = "closedTopComponents"; // NOI18N |
97 |
private static final String PROPERTY_CLOSED_TC = "closedTopComponents"; // NOI18N |
93 |
|
98 |
|
94 |
private List<DebuggerEngine> openedGroups = new LinkedList<DebuggerEngine>(); |
99 |
private List<DebuggerEngine> openedGroups = new LinkedList<DebuggerEngine>(); |
95 |
private final Map<DebuggerEngine, List<? extends Component>> openedComponents = new HashMap<DebuggerEngine, List<? extends Component>>(); |
100 |
//private final Map<DebuggerEngine, List<? extends Component>> openedComponents = new HashMap<DebuggerEngine, List<? extends Component>>(); |
96 |
private Set<Reference<Component>> componentsInitiallyOpened = new HashSet<Reference<Component>>(); |
101 |
private final Map<DebuggerEngine, Map<EngineComponentsProvider, List<? extends ComponentInfo>>> openedComponents = |
|
|
102 |
new HashMap<DebuggerEngine, Map<EngineComponentsProvider, List<? extends ComponentInfo>>>(); |
103 |
private static final Set<Reference<Component>> componentsInitiallyOpened = new HashSet<Reference<Component>>(); |
97 |
private final Map<DebuggerEngine, List<? extends Component>> closedToolbarButtons = new HashMap<DebuggerEngine, List<? extends Component>>(); |
104 |
private final Map<DebuggerEngine, List<? extends Component>> closedToolbarButtons = new HashMap<DebuggerEngine, List<? extends Component>>(); |
98 |
private final Map<DebuggerEngine, List<? extends Component>> usedToolbarButtons = new HashMap<DebuggerEngine, List<? extends Component>>(); |
105 |
private final Map<DebuggerEngine, List<? extends Component>> usedToolbarButtons = new HashMap<DebuggerEngine, List<? extends Component>>(); |
99 |
private final Map<Component, Dimension> toolbarButtonsPrefferedSize = new HashMap<Component, Dimension>(); |
106 |
private final Map<Component, Dimension> toolbarButtonsPrefferedSize = new HashMap<Component, Dimension>(); |
Lines 101-107
Link Here
|
101 |
private ToolbarContainerListener toolbarContainerListener; |
108 |
private ToolbarContainerListener toolbarContainerListener; |
102 |
private static final RequestProcessor RP = new RequestProcessor("Debugger Engine Setup", 1); // NOI18N |
109 |
private static final RequestProcessor RP = new RequestProcessor("Debugger Engine Setup", 1); // NOI18N |
103 |
|
110 |
|
104 |
private static final List<Component> OPENED_COMPONENTS = new LinkedList<Component>(); |
111 |
private static final List<ComponentInfo> OPENED_COMPONENTS = new LinkedList<ComponentInfo>(); |
105 |
|
112 |
|
106 |
@Override |
113 |
@Override |
107 |
public void engineAdded (DebuggerEngine engine) { |
114 |
public void engineAdded (DebuggerEngine engine) { |
Lines 116-125
Link Here
|
116 |
} |
123 |
} |
117 |
final List<? extends BeanContextChildComponentProxy> componentProxies = |
124 |
final List<? extends BeanContextChildComponentProxy> componentProxies = |
118 |
engine.lookup(null, BeanContextChildComponentProxy.class); |
125 |
engine.lookup(null, BeanContextChildComponentProxy.class); |
|
|
126 |
final List<? extends EngineComponentsProvider> componentsProvidersL = engine.lookup(null, EngineComponentsProvider.class); |
119 |
//final List<? extends TopComponent> windowsToOpen = engine.lookup(null, TopComponent.class); |
127 |
//final List<? extends TopComponent> windowsToOpen = engine.lookup(null, TopComponent.class); |
120 |
if (componentProxies != null && !componentProxies.isEmpty()) { |
128 |
if (!componentProxies.isEmpty() || !componentsProvidersL.isEmpty()) { |
121 |
final List<Component> componentsToOpen = new ArrayList<Component>(componentProxies.size()); |
129 |
final Map<EngineComponentsProvider, List<? extends ComponentInfo>> componentsToOpen = |
122 |
componentsToOpen.add(new java.awt.Label("EMPTY")); |
130 |
new LinkedHashMap<EngineComponentsProvider, List<? extends ComponentInfo>>(); |
|
|
131 |
componentsToOpen.put(null, null); // Going to initialize... |
123 |
if (openedComponents.isEmpty() && openedGroups.isEmpty()) { |
132 |
if (openedComponents.isEmpty() && openedGroups.isEmpty()) { |
124 |
fillOpenedDebuggerComponents(componentsInitiallyOpened); |
133 |
fillOpenedDebuggerComponents(componentsInitiallyOpened); |
125 |
} |
134 |
} |
Lines 130-177
Link Here
|
130 |
rp.post (new Runnable () { |
139 |
rp.post (new Runnable () { |
131 |
@Override |
140 |
@Override |
132 |
public void run () { |
141 |
public void run () { |
133 |
List<Component> cs = new ArrayList<Component>(componentProxies.size()); |
142 |
final Map<EngineComponentsProvider, List<? extends ComponentInfo>> ecs = |
|
|
143 |
new LinkedHashMap<EngineComponentsProvider, List<? extends ComponentInfo>>(); |
144 |
final List<ComponentInfo> cs = new ArrayList<ComponentInfo>(); |
134 |
try { |
145 |
try { |
135 |
final List<TopComponent> topComponentsToOpen = new ArrayList<TopComponent>(componentProxies.size()); |
146 |
final List<? extends EngineComponentsProvider> componentsProviders; |
136 |
for (final BeanContextChildComponentProxy cp : componentProxies) { |
147 |
if (!componentProxies.isEmpty()) { |
137 |
final Component[] c = new Component[] { null }; |
148 |
BeanContextComponentProvider bccp = new BeanContextComponentProvider(componentProxies); |
138 |
final boolean[] doOpen = new boolean[] { false }; |
149 |
if (componentsProvidersL.isEmpty()) { |
139 |
try { |
150 |
componentsProviders = Collections.singletonList(bccp); |
140 |
SwingUtilities.invokeAndWait(new Runnable() { |
151 |
} else { |
141 |
@Override |
152 |
List<EngineComponentsProvider> cps = new ArrayList<EngineComponentsProvider>(componentsProvidersL.size() + 1); |
142 |
public void run() { |
153 |
cps.addAll(componentsProvidersL); |
143 |
c[0] = cp.getComponent(); |
154 |
cps.add(bccp); |
144 |
doOpen[0] = (cp instanceof DesignMode) ? ((DesignMode) cp).isDesignTime() : true; |
155 |
componentsProviders = Collections.unmodifiableList(cps); |
|
|
156 |
} |
157 |
} else { |
158 |
componentsProviders = componentsProvidersL; |
159 |
} |
160 |
final Map<TopComponent, ComponentInfo> topComponentsToOpen = new LinkedHashMap<TopComponent, ComponentInfo>(); |
161 |
for (EngineComponentsProvider ecp : componentsProviders) { |
162 |
List<ComponentInfo> cis = ecp.getComponents(); |
163 |
for (final ComponentInfo ci : cis) { |
164 |
if (ci.isOpened()) { |
165 |
try { |
166 |
SwingUtilities.invokeAndWait(new Runnable() { |
167 |
@Override |
168 |
public void run() { |
169 |
Component c = ci.getComponent(); |
170 |
if (c instanceof TopComponent) { |
171 |
topComponentsToOpen.put((TopComponent) c, ci); |
172 |
} else { |
173 |
c.setVisible(true); |
174 |
} |
175 |
} |
176 |
}); |
177 |
} catch (Exception ex) { |
178 |
Exceptions.printStackTrace(ex); |
179 |
continue; |
145 |
} |
180 |
} |
146 |
}); |
|
|
147 |
if (c[0] == null) { |
148 |
//throw new NullPointerException("No component from "+cp); |
149 |
continue; |
150 |
} |
181 |
} |
151 |
} catch (Exception ex) { |
182 |
cs.add(ci); |
152 |
Exceptions.printStackTrace(ex); |
|
|
153 |
continue; |
154 |
} |
183 |
} |
155 |
cs.add(c[0]); |
184 |
ecs.put(ecp, cis); |
156 |
if (c[0] instanceof TopComponent) { |
|
|
157 |
final TopComponent tc = (TopComponent) c[0]; |
158 |
boolean wasClosed = Properties.getDefault().getProperties(DebuggerManagerListener.class.getName()). |
159 |
getProperties(PROPERTY_CLOSED_TC).getBoolean(tc.getName(), false); |
160 |
boolean wasOpened = !Properties.getDefault().getProperties(DebuggerManagerListener.class.getName()). |
161 |
getProperties(PROPERTY_CLOSED_TC).getBoolean(tc.getName(), true); |
162 |
if (doOpen[0] && !wasClosed || !doOpen[0] && wasOpened) { |
163 |
topComponentsToOpen.add(tc); |
164 |
} |
165 |
} else { |
166 |
if (doOpen[0]) { |
167 |
SwingUtilities.invokeLater(new Runnable() { |
168 |
@Override |
169 |
public void run() { |
170 |
c[0].setVisible(true); |
171 |
} |
172 |
}); |
173 |
} |
174 |
} |
175 |
} |
185 |
} |
176 |
if (topComponentsToOpen.size() > 0) { |
186 |
if (topComponentsToOpen.size() > 0) { |
177 |
SwingUtilities.invokeLater(new Runnable() { |
187 |
SwingUtilities.invokeLater(new Runnable() { |
Lines 184-202
Link Here
|
184 |
} finally { |
194 |
} finally { |
185 |
synchronized (openedComponents) { |
195 |
synchronized (openedComponents) { |
186 |
componentsToOpen.clear(); |
196 |
componentsToOpen.clear(); |
187 |
componentsToOpen.addAll(cs); |
197 |
componentsToOpen.putAll(ecs); |
188 |
openedComponents.notifyAll(); |
198 |
openedComponents.notifyAll(); |
189 |
} |
199 |
} |
190 |
synchronized (OPENED_COMPONENTS) { |
200 |
synchronized (OPENED_COMPONENTS) { |
|
|
201 |
OPENED_COMPONENTS.addAll(cs); |
202 |
/* consider componentsInitiallyOpened when closing components from OPENED_COMPONENTS |
203 |
* instead of this: |
191 |
if (componentsInitiallyOpened.isEmpty()) { |
204 |
if (componentsInitiallyOpened.isEmpty()) { |
192 |
OPENED_COMPONENTS.addAll(cs); |
205 |
OPENED_COMPONENTS.addAll(cs); |
193 |
} else { |
206 |
} else { |
194 |
List<Component> ocs = new ArrayList<Component>(cs); |
207 |
List<ComponentInfo> ocs = new ArrayList<ComponentInfo>(cs); |
195 |
for (Reference<Component> cref : componentsInitiallyOpened) { |
208 |
for (Reference<Component> cref : componentsInitiallyOpened) { |
196 |
ocs.remove(cref.get()); |
209 |
ocs.remove(cref.get()); |
197 |
} |
210 |
} |
198 |
OPENED_COMPONENTS.addAll(ocs); |
211 |
OPENED_COMPONENTS.addAll(ocs); |
199 |
} |
212 |
} |
|
|
213 |
*/ |
200 |
} |
214 |
} |
201 |
} |
215 |
} |
202 |
} |
216 |
} |
Lines 231-241
Link Here
|
231 |
} |
245 |
} |
232 |
} |
246 |
} |
233 |
|
247 |
|
234 |
private void openTopComponents(List<TopComponent> components) { |
248 |
private void openTopComponents(Map<TopComponent, ComponentInfo> components) { |
235 |
assert SwingUtilities.isEventDispatchThread(); |
249 |
assert SwingUtilities.isEventDispatchThread(); |
236 |
Set<Mode> modesWithVisibleTC = new HashSet<Mode>(); |
250 |
Set<Mode> modesWithVisibleTC = new HashSet<Mode>(); |
237 |
for (TopComponent tc : components) { |
251 |
for (Map.Entry<TopComponent, ComponentInfo> tci : components.entrySet()) { |
|
|
252 |
TopComponent tc = tci.getKey(); |
253 |
ComponentInfo ci = tci.getValue(); |
238 |
tc.open(); |
254 |
tc.open(); |
|
|
255 |
if (ci.isMinimized()) { |
256 |
WindowManager.getDefault().setTopComponentMinimized(tc, true); |
257 |
} |
239 |
Mode mode = WindowManager.getDefault().findMode(tc); |
258 |
Mode mode = WindowManager.getDefault().findMode(tc); |
240 |
if (modesWithVisibleTC.add(mode)) { |
259 |
if (modesWithVisibleTC.add(mode)) { |
241 |
TopComponent tcSel = mode.getSelectedTopComponent(); |
260 |
TopComponent tcSel = mode.getSelectedTopComponent(); |
Lines 375-404
Link Here
|
375 |
public void engineRemoved (DebuggerEngine engine) { |
394 |
public void engineRemoved (DebuggerEngine engine) { |
376 |
//boolean doCloseToolbar = false; |
395 |
//boolean doCloseToolbar = false; |
377 |
synchronized (openedComponents) { |
396 |
synchronized (openedComponents) { |
378 |
List<? extends Component> openedWindows = openedComponents.remove(engine); |
397 |
final Map<EngineComponentsProvider, List<? extends ComponentInfo>> openedWindowsByProvider = openedComponents.remove(engine); |
379 |
if (openedWindows != null) { |
398 |
if (openedWindowsByProvider != null) { |
380 |
// If it's not filled yet by AWT, wait... |
399 |
// If it's not filled yet by AWT, wait... |
381 |
if (openedWindows.size() == 1 && openedWindows.get(0) instanceof java.awt.Label) { |
400 |
if (openedWindowsByProvider.size() == 1 && openedWindowsByProvider.get(0) == null) { |
382 |
try { |
401 |
try { |
383 |
openedComponents.wait(); |
402 |
openedComponents.wait(); |
384 |
} catch (InterruptedException iex) {} |
403 |
} catch (InterruptedException iex) {} |
385 |
} |
404 |
} |
|
|
405 |
List<ComponentInfo> openedWindows = new ArrayList<ComponentInfo>(); |
406 |
for (List<? extends ComponentInfo> lci : openedWindowsByProvider.values()) { |
407 |
openedWindows.addAll(lci); |
408 |
} |
386 |
// Check whether the component is opened by some other engine... |
409 |
// Check whether the component is opened by some other engine... |
387 |
final List<Component> retainOpened = new ArrayList<Component>(); |
410 |
final List<ComponentInfo> retainOpened = new ArrayList<ComponentInfo>(); |
388 |
for (List<? extends Component> ltc : openedComponents.values()) { |
411 |
for (Map<EngineComponentsProvider, List<? extends ComponentInfo>> meci : openedComponents.values()) { |
389 |
retainOpened.addAll(ltc); |
412 |
for (List<? extends ComponentInfo> lci : meci.values()){ |
|
|
413 |
retainOpened.addAll(lci); |
414 |
} |
390 |
} |
415 |
} |
391 |
final List<Component> windowsToClose = new ArrayList<Component>(openedWindows); |
416 |
final List<Component> initiallyOpened = new ArrayList<Component>(); |
392 |
windowsToClose.removeAll(retainOpened); |
|
|
393 |
for (Reference<Component> cref : componentsInitiallyOpened) { |
417 |
for (Reference<Component> cref : componentsInitiallyOpened) { |
394 |
windowsToClose.remove(cref.get()); |
418 |
Component c = cref.get(); |
|
|
419 |
if (c != null) { |
420 |
initiallyOpened.add(c); |
421 |
} |
395 |
} |
422 |
} |
396 |
if (!windowsToClose.isEmpty()) { |
423 |
final List<ComponentInfo> windowsToClose = new ArrayList<ComponentInfo>(openedWindows); |
397 |
SwingUtilities.invokeLater (new Runnable () { |
424 |
//windowsToClose.removeAll(retainOpened); |
|
|
425 |
try { |
426 |
SwingUtilities.invokeAndWait(new Runnable() { |
398 |
@Override |
427 |
@Override |
399 |
public void run () { |
428 |
public void run() { |
|
|
429 |
List<Component> retainOpenedComponents = new ArrayList<Component>(retainOpened.size()); |
430 |
for (ComponentInfo ci : retainOpened) { |
431 |
retainOpenedComponents.add(ci.getComponent()); |
432 |
} |
433 |
for (Component c : initiallyOpened) { |
434 |
if (c != null) { |
435 |
retainOpenedComponents.add(c); |
436 |
} |
437 |
} |
438 |
List<ComponentInfo> windowsToCloseCopy = (ArrayList<ComponentInfo>) ((ArrayList) windowsToClose).clone(); |
439 |
for (ComponentInfo ci : windowsToCloseCopy) { |
440 |
Component c = ci.getComponent(); |
441 |
if (retainOpenedComponents.contains(c)) { |
442 |
windowsToClose.remove(ci); |
443 |
} |
444 |
} |
445 |
for (EngineComponentsProvider ecp : openedWindowsByProvider.keySet()) { |
446 |
List<? extends ComponentInfo> cis = openedWindowsByProvider.get(ecp); |
447 |
List<ComponentInfo> closing = new ArrayList<ComponentInfo>(cis); |
448 |
closing.retainAll(windowsToClose); |
449 |
ecp.willCloseNotify(closing); |
450 |
} |
400 |
final List<TopComponent> topComponentsToClose = new ArrayList<TopComponent>(windowsToClose.size()); |
451 |
final List<TopComponent> topComponentsToClose = new ArrayList<TopComponent>(windowsToClose.size()); |
401 |
for (Component c : windowsToClose) { |
452 |
for (ComponentInfo ci : windowsToClose) { |
|
|
453 |
Component c = ci.getComponent(); |
402 |
if (c instanceof TopComponent) { |
454 |
if (c instanceof TopComponent) { |
403 |
TopComponent tc = (TopComponent) c; |
455 |
TopComponent tc = (TopComponent) c; |
404 |
boolean isOpened = tc.isOpened(); |
456 |
boolean isOpened = tc.isOpened(); |
Lines 414-419
Link Here
|
414 |
closeTopComponentsList(topComponentsToClose); |
466 |
closeTopComponentsList(topComponentsToClose); |
415 |
} |
467 |
} |
416 |
}); |
468 |
}); |
|
|
469 |
} catch (Exception exc) { |
470 |
Exceptions.printStackTrace(exc); |
417 |
} |
471 |
} |
418 |
synchronized (OPENED_COMPONENTS) { |
472 |
synchronized (OPENED_COMPONENTS) { |
419 |
OPENED_COMPONENTS.removeAll(windowsToClose); |
473 |
OPENED_COMPONENTS.removeAll(windowsToClose); |
Lines 435-440
Link Here
|
435 |
} |
489 |
} |
436 |
if (openedComponents.isEmpty() && openedGroups.isEmpty()) { |
490 |
if (openedComponents.isEmpty() && openedGroups.isEmpty()) { |
437 |
componentsInitiallyOpened.clear(); |
491 |
componentsInitiallyOpened.clear(); |
|
|
492 |
synchronized (OPENED_COMPONENTS) { |
493 |
OPENED_COMPONENTS.clear(); |
494 |
} |
438 |
/*doCloseToolbar = true; |
495 |
/*doCloseToolbar = true; |
439 |
SwingUtilities.invokeLater (new Runnable () { |
496 |
SwingUtilities.invokeLater (new Runnable () { |
440 |
public void run () { |
497 |
public void run () { |
Lines 568-581
Link Here
|
568 |
group.close (); |
625 |
group.close (); |
569 |
} |
626 |
} |
570 |
synchronized (OPENED_COMPONENTS) { |
627 |
synchronized (OPENED_COMPONENTS) { |
571 |
for (Component c : OPENED_COMPONENTS) { |
628 |
final List<Component> initiallyOpened; |
|
|
629 |
if (componentsInitiallyOpened.isEmpty()) { |
630 |
initiallyOpened = Collections.EMPTY_LIST; |
631 |
} else { |
632 |
initiallyOpened = new ArrayList<Component>(); |
633 |
for (Reference<Component> cref : componentsInitiallyOpened) { |
634 |
Component c = cref.get(); |
635 |
if (c != null) { |
636 |
initiallyOpened.add(c); |
637 |
} |
638 |
} |
639 |
} |
640 |
for (ComponentInfo ci : OPENED_COMPONENTS) { |
641 |
Component c = ci.getComponent(); |
642 |
if (initiallyOpened.contains(c)) { |
643 |
continue; |
644 |
} |
572 |
if (c instanceof TopComponent) { |
645 |
if (c instanceof TopComponent) { |
|
|
646 |
/* To check which components we're closing: |
647 |
try { |
648 |
Method pid = TopComponent.class.getDeclaredMethod("preferredID"); |
649 |
pid.setAccessible(true); |
650 |
System.err.println("doCloseDebuggerUI("+pid.invoke(c)+")"); |
651 |
} catch (Exception ex) { |
652 |
ex.printStackTrace(); |
653 |
} |
654 |
*/ |
573 |
((TopComponent) c).close(); |
655 |
((TopComponent) c).close(); |
574 |
} else { |
656 |
} else { |
575 |
c.setVisible(false); |
657 |
c.setVisible(false); |
576 |
} |
658 |
} |
577 |
} |
659 |
} |
578 |
OPENED_COMPONENTS.clear(); |
660 |
OPENED_COMPONENTS.clear(); |
|
|
661 |
componentsInitiallyOpened.clear(); |
579 |
} |
662 |
} |
580 |
ToolbarPool.getDefault().waitFinished(); |
663 |
ToolbarPool.getDefault().waitFinished(); |
581 |
if (ToolbarPool.getDefault().getConfiguration().equals("Debugging")) { // NOI18N |
664 |
if (ToolbarPool.getDefault().getConfiguration().equals("Debugging")) { // NOI18N |
Lines 672-676
Link Here
|
672 |
} |
755 |
} |
673 |
|
756 |
|
674 |
} |
757 |
} |
|
|
758 |
|
759 |
private static class BeanContextComponentProvider implements EngineComponentsProvider { |
760 |
|
761 |
private final List<? extends BeanContextChildComponentProxy> componentProxies; |
762 |
|
763 |
public BeanContextComponentProvider(List<? extends BeanContextChildComponentProxy> componentProxies) { |
764 |
this.componentProxies = componentProxies; |
765 |
} |
766 |
|
767 |
@Override |
768 |
public List<ComponentInfo> getComponents() { |
769 |
return ComponentInfoFromBeanContext.transform(componentProxies); |
770 |
} |
771 |
|
772 |
@Override |
773 |
public void willCloseNotify(List<ComponentInfo> components) { |
774 |
ComponentInfoFromBeanContext.closing(components); |
775 |
} |
776 |
|
777 |
} |
675 |
|
778 |
|
676 |
} |
779 |
} |