|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2004 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.core.execution; import java.awt.*; import java.lang.ref.*; import java.net.URL; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.swing.SwingUtilities; import org.openide.ErrorManager; import org.openide.util.HelpCtx; import org.openide.util.NbBundle; import org.openide.util.actions.CallableSystemAction; import org.openide.explorer.ExplorerPanel; import org.openide.explorer.ExplorerManager; import org.openide.windows.TopComponent; import org.openide.windows.WindowManager; import org.openide.util.Utilities; import org.openide.windows.Workspace; import org.openide.windows.TopComponentGroup; /** Execution view action. * * @author Jan Jancura, Ian Formanek */ public final class ExecutionViewAction extends CallableSystemAction { public String getName() { return NbBundle.getMessage(ExecutionViewAction.class, "ExecutionView"); } public HelpCtx getHelpCtx() { return new HelpCtx (ExecutionViewAction.class); } protected String iconResource () { return "org/netbeans/core/resources/actions/executionView.gif"; // NOI18N } public void performAction () { TopComponent tc = ExecutionView.getInstance(); // display view tc.open(); tc.requestActive(); } protected boolean asynchronous() { return false; } private static ExecListener execListener = new ExecListener(); public static void installExecutionListener() { ExecutionEngine ee = ExecutionEngine.getExecutionEngine(); if(ee == null) { ErrorManager.getDefault().notify(new IllegalStateException("No Execution Engine")); // NOI18N } else { ee.addExecutionListener(execListener); } } public static void uninstallExecutionListener() { ExecutionEngine ee = ExecutionEngine.getExecutionEngine(); if(ee == null) { ErrorManager.getDefault().notify(new IllegalStateException("No Execution Engine")); // NOI18N } else { ee.removeExecutionListener(execListener); } } /** Listens to start/stop of executables, performs logic for automatic * opening/closing of execution view */ private static class ExecListener implements ExecutionListener, Runnable { ExecListener() {} /** number of running executables at a time */ private int execCount = 0; /** sync access to data */ private final Object dataLock = new Object(); /** called after begin of new execution */ public void startedExecution(ExecutionEvent ev) { synchronized (dataLock) { execCount++; } SwingUtilities.invokeLater(this); } /** called after end of execution */ public void finishedExecution(ExecutionEvent ev) { boolean closeGroup = false; synchronized (dataLock) { execCount--; if (execCount == 0) { closeGroup = true; } } if(closeGroup) SwingUtilities.invokeLater(this); } public void run() { boolean close; synchronized (dataLock) { close = (execCount == 0); } TopComponentGroup group = WindowManager.getDefault() .findTopComponentGroup("execution"); // NOI18N if(group != null) { if (close) { group.close(); } else { group.open(); } } } } // end of ExecListener /** The top component which shows execution view */ public static final class ExecutionView extends ExplorerPanel { // Attributes private boolean initialized = false; private static String ID = "execution"; // NOI18N private static Reference instance; /** serial version UID */ static final long serialVersionUID = 3712218929995126077L; static synchronized ExecutionView getInstance() { ExecutionView view = (ExecutionView)WindowManager.getDefault().findTopComponent(ID); if (view == null) view = getDefault(); return view; } public static synchronized ExecutionView getDefault() { ExecutionView view = null; if (instance != null) view = (ExecutionView)instance.get(); if (view == null) { view = new ExecutionView(); instance = new WeakReference(view); } return view; } /** Default constructor */ ExecutionView () { super(); ExecutionEngine ee = ExecutionEngine.getExecutionEngine(); if (ee == null) throw new IllegalStateException("No ExecutionEngine"); // NOI18N ExplorerManager em = getExplorerManager (); em.setRootContext (ProcessNode.getExecutionNode()); org.openide.explorer.view.ListView list = new org.openide.explorer.view.ListView(); add (list, BorderLayout.CENTER); setName(ID); setDisplayName (NbBundle.getMessage(ExecutionViewAction.class, "CTL_Execution_view_title")); setIcon (Utilities.loadImage("org/netbeans/core/resources/actions/executionView.gif")); // NOI18N setToolTipText(NbBundle.getMessage(ExecutionViewAction.class, "HINT_Execution_view")); list.getAccessibleContext().setAccessibleName(NbBundle.getMessage(ExecutionViewAction.class, "ACSN_ExecutionList")); list.getAccessibleContext().setAccessibleDescription(NbBundle.getMessage(ExecutionViewAction.class, "ACSD_ExecutionList")); } protected String preferredID() { return ID; } public HelpCtx getHelpCtx () { return super.getHelpCtx (getExplorerManager ().getSelectedNodes (), new HelpCtx ("execution.view.window")); } /** Does nothing - overriden to keep the title unchanged */ protected void updateTitle () { } /** Overriden to explicitely set persistence type of ExecutionView * to PERSISTENCE_ALWAYS */ public int getPersistenceType() { return TopComponent.PERSISTENCE_ALWAYS; } /** Writes a resolvable */ protected Object writeReplace() { return new Resolvable(); } } static class Resolvable implements java.io.Serializable { static final long serialVersionUID =8143238035030034549L; private Object readResolve() { return ExecutionView.getDefault(); } } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.