EngineComponentsProvider
interface added.
+ EngineComponentsProvider
interface introduced
+ to provide GUI components that are associated with a debugger
+ engine. EngineComponentsProvider.ComponentInfo
+ provides information about the associated component.
+
+ * The provided components are checked when the appropriate debugger engine is started
+ * and opened if necessary. After the debugger engine is finished,
+ * {@link EngineComponentsProvider#willCloseNotify(java.util.List)} is called
+ * with components that are not used by other running engines and which are subsequently
+ * closed.
+ *
+ * @author Martin Entlicher
+ * @since 2.35
+ */
+public interface EngineComponentsProvider {
+
+ /**
+ * Provide a list of components associated with the debugger engine.
+ * The components are opened when the debugger engine starts and closed
+ * when the debugger engine finishes.
+ *
+ * @return The list of components associated with the debugger engine.
+ */
+ Listtrue
when this component is to be opened on engine start,
+ * false
otherwise.
+ */
+ public boolean isOpened() {
+ return opened;
+ }
+
+ /**
+ * Test if the component is to be opened in a minimized state when the
+ * debugger engine starts.
+ * @return true
when this component is to be opened in a minimized state,
+ * false
otherwise.
+ */
+ public boolean isMinimized() {
+ return minimized;
+ }
+
+ /* can be added when needed
+ public void setOrder(int order) {
+ this.order = order;
+ }
+
+ public int getOrder() {
+ return order;
+ }
+ */
+
+ /* When generic Component support is required
+ public static ComponentInfo create(ComponentProvider componentProvider) {
+ return new ComponentInfo(componentProvider);
+ }
+ */
+
+ /**
+ * Create a component information about a {@link TopComponent},
+ * which is opened by default.
+ * @param tcName The ID of the {@link TopComponent}
+ * @return A component information.
+ */
+ public static ComponentInfo create(String tcId) {
+ return create(tcId, true);
+ }
+
+ /**
+ * Create a component information about a {@link TopComponent}.
+ * @param tcName The ID of the {@link TopComponent}
+ * @param opened true
if the component should be opened,
+ * false
otherwise.
+ * @return A component information.
+ */
+ public static ComponentInfo create(String tcId, boolean opened) {
+ return create(tcId, opened, false);
+ }
+
+ /**
+ * Create a component information about a {@link TopComponent}.
+ * @param tcName The ID of the {@link TopComponent}
+ * @param opened true
if the component should be opened,
+ * false
otherwise.
+ * @param minimized true
if the component should be opened in a minimized state,
+ * false
otherwise.
+ * @return A component information.
+ */
+ public static ComponentInfo create(String tcId, boolean opened, boolean minimized) {
+ return new ComponentInfo(new TopComponentProvider(tcId), opened, minimized);
+ }
+
+ private static void initHelperTransform() {
+ ComponentInfoFromBeanContext.TRANSFORM = new ComponentInfoFromBeanContext.Transform() {
+ @Override
+ public ComponentInfo transform(final Component c, boolean opened) {
+ return new ComponentInfo(new ComponentProvider() {
+ @Override
+ public Component getComponent() {
+ return c;
+ }
+ }, opened, false);
+ }
+ };
+ }
+
+ }
+
+ /*public - when generic Component suport is required. */
+ static interface ComponentProvider {
+
+ Component getComponent();
+ }
+
+ static class TopComponentProvider implements ComponentProvider {
+
+ private final String tcId;
+
+ private TopComponentProvider(String tcId) {
+ this.tcId = tcId;
+ }
+
+ @Override
+ public java.awt.Component getComponent() {
+ return WindowManager.getDefault().findTopComponent(tcId);
+ }
+ }
+
+}
diff --git a/spi.debugger.ui/test/unit/src/org/netbeans/spi/debugger/ui/EngineComponentsProviderTest.java b/spi.debugger.ui/test/unit/src/org/netbeans/spi/debugger/ui/EngineComponentsProviderTest.java
new file mode 100644
--- /dev/null
+++ b/spi.debugger.ui/test/unit/src/org/netbeans/spi/debugger/ui/EngineComponentsProviderTest.java
@@ -0,0 +1,116 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2012 Sun Microsystems, Inc.
+ */
+package org.netbeans.spi.debugger.ui;
+
+import java.awt.Component;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import javax.swing.SwingUtilities;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import org.netbeans.api.debugger.DebuggerApiTestBase;
+import org.netbeans.junit.NbModuleSuite;
+import org.netbeans.spi.debugger.ui.EngineComponentsProvider.ComponentInfo;
+import org.openide.windows.TopComponent;
+
+/**
+ *
+ * @author Martin
+ */
+public class EngineComponentsProviderTest extends DebuggerApiTestBase {
+
+ public EngineComponentsProviderTest(String s) {
+ super(s);
+ }
+
+ public static Test suite() {
+ return EngineComponentsProviderTest.createTestSuite(EngineComponentsProviderTest.class);
+ }
+
+ public void testCreateTC() throws Throwable {
+ ComponentInfo ciVar = EngineComponentsProvider.ComponentInfo.create("localsView");
+ checkComponentInfo(ciVar, true, false, "org.netbeans.modules.debugger.ui.views.LocalsView");
+
+ ComponentInfo ciWatch = EngineComponentsProvider.ComponentInfo.create("watchesView", false);
+ checkComponentInfo(ciWatch, false, false, "org.netbeans.modules.debugger.ui.views.WatchesView");
+
+ ComponentInfo ciCS = EngineComponentsProvider.ComponentInfo.create("callstackView", false, true);
+ checkComponentInfo(ciCS, false, true, "org.netbeans.modules.debugger.ui.views.CallStackView");
+ }
+
+ private void checkComponentInfo(final ComponentInfo ci,
+ boolean opened, boolean minimized,
+ final String ID) throws Throwable {
+ assertEquals("Opened", opened, ci.isOpened());
+ assertEquals("Minimized", minimized, ci.isMinimized());
+ try {
+ SwingUtilities.invokeAndWait(new Runnable() {
+ @Override
+ public void run() {
+ Component c = ci.getComponent();
+ assertTrue("Is TopComponent:", c instanceof TopComponent);
+ TopComponent tc = (TopComponent) c;
+ try {
+ Method pid = TopComponent.class.getDeclaredMethod("preferredID");
+ pid.setAccessible(true);
+ String tcId = (String) pid.invoke(tc);
+ //System.err.println("tcId = "+tcId);
+ assertEquals("TopComponent preferredID:", ID, tcId);
+ } catch (Exception ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+ });
+ } catch (InvocationTargetException itex) {
+ Thread.dumpStack();
+ throw itex.getTargetException();
+ }
+ }
+
+ public static Test createTestSuite(Class extends TestCase> clazz) {
+ NbModuleSuite.Configuration suiteConfiguration = NbModuleSuite.createConfiguration(clazz);
+ suiteConfiguration = suiteConfiguration.gui(false);
+ //suiteConfiguration = suiteConfiguration.reuseUserDir(false);
+ return NbModuleSuite.create(suiteConfiguration);
+ }
+
+}
diff --git a/web.javascript.debugger/src/org/netbeans/modules/web/javascript/debugger/EngineComponentsProviderImpl.java b/web.javascript.debugger/src/org/netbeans/modules/web/javascript/debugger/EngineComponentsProviderImpl.java
new file mode 100644
--- /dev/null
+++ b/web.javascript.debugger/src/org/netbeans/modules/web/javascript/debugger/EngineComponentsProviderImpl.java
@@ -0,0 +1,123 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License. When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2012 Sun Microsystems, Inc.
+ */
+package org.netbeans.modules.web.javascript.debugger;
+
+import java.awt.Component;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.prefs.Preferences;
+import org.netbeans.api.debugger.Properties;
+import org.netbeans.spi.debugger.ContextProvider;
+import org.netbeans.spi.debugger.DebuggerServiceRegistration;
+import org.netbeans.spi.debugger.ui.EngineComponentsProvider;
+import org.openide.util.NbPreferences;
+import org.openide.windows.TopComponent;
+
+/**
+ * Provider of debugger GUI components needed for JavaScript Debugger,
+ * minimized initially.
+ *
+ * @author Martin Entlicher
+ */
+@DebuggerServiceRegistration(path="javascript-debuggerengine", types=EngineComponentsProvider.class)
+public class EngineComponentsProviderImpl implements EngineComponentsProvider {
+
+ private static final String PROPERTY_CLOSED_TC = "closedTopComponents"; // NOI18N
+ private static final String PROPERTY_BASE_NAME = "javascript-debuggerengine.EngineComponentsProvider"; // NOI18N
+
+ private static final String[] DBG_COMPONENTS_OPENED = {
+ "localsView", "watchesView", "callstackView", "breakpointsView",
+ };
+ private static final String[] DBG_COMPONENTS_CLOSED = {
+ "evaluator", "resultsView", "sessionsView",
+ };
+
+ @Override
+ public List