Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright 2008-2010 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 2008-2009 Sun Microsystems, Inc.
  */
 
 package org.netbeans.modules.bugtracking.ui.issue;
 
 import java.awt.Font;
 import java.util.Set;
Top component that displays information about one issue.

Author(s):
Jan Stola, Tomas Stupka
 
 public final class IssueTopComponent extends TopComponent implements PropertyChangeListener {
    
Set of opened IssueTopComponents.
 
     private static Set<IssueTopComponentopenIssues = new HashSet<IssueTopComponent>();
    
Issue displayed by this top-component.
 
     private Issue issue;
     private RequestProcessor rp = new RequestProcessor("Bugtracking issue", 1, true); // NOI18N
     private Task prepareTask;
     private RepositoryComboSupport rs;
     private Node[] context;

    
Creates new IssueTopComponent.
 
     public IssueTopComponent() {
         initComponents();
         BugtrackingConnector[] connectors = BugtrackingManager.getInstance().getConnectors();
        for (BugtrackingConnector c : connectors) {
            c.addPropertyChangeListener(this);
        }
        .setVisible(false);
            @Override
            public void actionPerformed(ActionEvent e) {
                onNewClick();
            }
        });
        JComponent findBar = FindSupport.create(this).getFindBar();
        findBar.setVisible(false);
        .add(findBar.);
    }

    
Returns issue displayed by this top-component.

Returns:
issue displayed by this top-component.
    public Issue getIssue() {
        return ;
    }
    public void initNewIssue(Repository toSelectNode[] context) {
        initNewIssue(toSelectfalsecontext);
    }
    public void initNewIssue(Repository defaultRepositoryboolean suggestedSelectionOnlyNode[] context) {
        BugtrackingUtil.logBugtrackingUsage(defaultRepository"ISSUE_EDIT"); // NOI18N
        this. = context;
        Font f = new JLabel().getFont();
        int s = f.getSize();
        .setFont(.getFont().deriveFont(s * 1.7f));
        if ((defaultRepository != null) && !suggestedSelectionOnly) {
            /* fixed selection that cannot be changed by user */
            DefaultComboBoxModel  repoModel = new DefaultComboBoxModel();
            repoModel.addElement(defaultRepository);
            .setModel(repoModel);
            .setSelectedItem(defaultRepository);
            .setEnabled(false);
            .setEnabled(false);
            onRepoSelected();
        } else {
            if(defaultRepository == null) {
                 = RepositoryComboSupport.setup(thisfalse);
            } else {
                 = RepositoryComboSupport.setup(thisdefaultRepository);
            }
        }
            @Override
            public void itemStateChanged(ItemEvent e) {
                if(e.getStateChange() == .) {
                    onRepoSelected();
                }
            }
        });
        setNameAndTooltip();
    }
    public void initNoIssue(final String issueId) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                .setVisible(true);
                .setVisible(false);
                if(issueId != null) {
                    String desc = NbBundle.getMessage(IssueTopComponent.class"LBL_OPENING_ISSUE"new Object[]{issueId});
                    .setText(desc);
                    setName(NbBundle.getMessage(IssueTopComponent.class"LBL_LOADING_ISSUE"new Object[]{issueId}));
                    setToolTipText(desc);
                } else {
                    setNameAndTooltip();
                }
            }
        });
    }

    
Sets issue displayed by this top-component.

Parameters:
issue displayed by this top-component.
    public void setIssue(Issue issue) {
        assert (this. == null);
        BugtrackingUtil.logBugtrackingUsage(issue.getRepository(), "ISSUE_EDIT"); // NOI18N
        this. = issue;
        .setVisible(false);
        .setVisible(false);
        setNameAndTooltip();
        issue.addPropertyChangeListener(this);
    }

    
This method is called from within the constructor to initialize the form. WARNING: Do NOT modify this code. The content of this method is always regenerated by the Form Editor.
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
         = new javax.swing.JPanel();
         = new javax.swing.JComboBox();
         = new javax.swing.JLabel();
         = new javax.swing.JLabel();
         = new javax.swing.JPanel();
         = new javax.swing.JPanel();
         = new javax.swing.JLabel();
        .setBackground(javax.swing.UIManager.getDefaults().getColor("EditorPane.background"));
        org.openide.awt.Mnemonics.setLocalizedText(, org.openide.util.NbBundle.getMessage(IssueTopComponent.class"IssueTopComponent.findIssuesLabel.text")); // NOI18N
        org.openide.awt.Mnemonics.setLocalizedText(, org.openide.util.NbBundle.getMessage(IssueTopComponent.class"IssueTopComponent.repoLabel.text")); // NOI18N
        .setFocusCycleRoot(true);
        .setOpaque(false);
        org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout();
        .setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 64, .)
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(0, 8, .)
        );
        org.openide.awt.Mnemonics.setLocalizedText(, org.openide.util.NbBundle.getMessage(IssueTopComponent.class"IssueTopComponent.newButton.text")); // NOI18N
        org.jdesktop.layout.GroupLayout repoPanelLayout = new org.jdesktop.layout.GroupLayout();
        .setLayout(repoPanelLayout);
        repoPanelLayout.setHorizontalGroup(
            repoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(repoPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(repoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(repoPanelLayout.createSequentialGroup()
                        .add()
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 225, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add())
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, .))
        );
        repoPanelLayout.setVerticalGroup(
            repoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(repoPanelLayout.createSequentialGroup()
                .add(50, 50, 50)
                .add(, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
            .add(repoPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add()
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(repoPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add()
                    .add(, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
        );
        .setBackground(javax.swing.UIManager.getDefaults().getColor("EditorPane.background"));
        .setLayout(new java.awt.BorderLayout());
        org.openide.awt.Mnemonics.setLocalizedText(, org.openide.util.NbBundle.getMessage(IssueTopComponent.class"IssueTopComponent.preparingLabel.text")); // NOI18N
        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, .)
            .add(, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, .)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, .))
        );
    }// </editor-fold>//GEN-END:initComponents
    private void onNewClick() {
        Repository repo = BugtrackingUtil.createRepository();
        if(repo != null) {
            .addItem(repo);
            .setSelectedItem(repo);
        }
    }
    private void onRepoSelected() {
        if( != null) {
            .cancel();
        }
        Cancellable c = new Cancellable() {
            @Override
            public boolean cancel() {
                if( != null) {
                    .cancel();
                }
                return true;
            }
        };
        final ProgressHandle handle = ProgressHandleFactory.createHandle(NbBundle.getMessage(IssueTopComponent.class"CTL_PreparingIssue"), c); // NOI18N
         = .post(new Runnable() {
            @Override
            public void run() {
                try {
                    handle.start();
                    .setVisible(true);
                    Repository repo = getRepository();
                    if (repo == null) {
                        return;
                    }
                    if( != null) {
                        if( != null.remove(.getComponent());
                        .removePropertyChangeListener(IssueTopComponent.this);
                    }
                     = repo.createIssue();
                    if ( == null) {
                        return;
                    }
                    IssueAccessor.getInstance().setSelection();
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                             = .getController();
                            .add(.getComponent(), .);
                            .addPropertyChangeListener(IssueTopComponent.this);
                            revalidate();
                            repaint();
                            focusFirstEnabledComponent();
                        }
                    });
                } finally {
                    .setVisible(false);
                    handle.finish();
                     = null;
                }
            }
        });
    }
    private Repository getRepository() {
        Object item = .getSelectedItem();
        if (item == null || !(item instanceof Repository)) {
            return null;
        }
        return (Repositoryitem;
    }
    private void focusFirstEnabledComponent() {
        if(!.isEnabled()) {
            .requestFocusInWindow();
            if(!.isEnabled()) {
                .transferFocus();
            }
        }
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel issuePanel;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JLabel preparingLabel;
    private javax.swing.JLabel repoLabel;
    private javax.swing.JPanel repoPanel;
    // End of variables declaration//GEN-END:variables
    @Override
    public int getPersistenceType() {
        return .;
    }
    @Override
    public void componentOpened() {
        .add(this);
        if( != null) {
            .getController().opened();
        }
        ..log(."IssueTopComponent Opened {0}", ( != null ? .getID() : "null")); // NOI18N
    }
    @Override
    public void componentClosed() {
        .remove(this);
        if( != null) {
            .removePropertyChangeListener(this);
            .getController().closed();
        }
        if( != null) {
            .cancel();
        }
        ..log(."IssueTopComponent Closed {0}", ( != null ? .getID() : "null")); // NOI18N
    }

    
Returns top-component that should display the given issue.

Parameters:
issue issue for which the top-component should be found.
Returns:
top-component that should display the given issue.
    public static synchronized IssueTopComponent find(Issue issue) {
        return find(issuetrue);
    }

    
Returns top-component that should display the given issue.

Parameters:
issue issue for which the top-component should be found.
forceCreate determines wheter a TopComponent is created if none available yet
Returns:
top-component that should display the given issue.
    public static synchronized IssueTopComponent find(Issue issueboolean forceCreate) {
        for (IssueTopComponent tc : ) {
            if (issue.equals(tc.getIssue())) {
                return tc;
            }
        }
        if(!forceCreate) {
            return null;
        }
        IssueTopComponent tc = new IssueTopComponent();
        tc.setIssue(issue);
        return tc;
    }

    
Returns top-component that should display the issue with the given issueId.

Parameters:
issueId
Returns:
    public static synchronized IssueTopComponent find(String issueId) {
        assert issueId != null;
        for (IssueTopComponent tc : ) {
            Issue i = tc.getIssue();
            if(i == nullcontinue;
            if (issueId.equals(i.getID())) {
                return tc;
            }
        }
        IssueTopComponent tc = new IssueTopComponent();
        return tc;
    }
    private void setNameAndTooltip() throws MissingResourceException {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                if( != null) {
                    setName(.getShortenedDisplayName());
                    setToolTipText(.getTooltip());
                } else {
                    setName(NbBundle.getMessage(IssueTopComponent.class"CTL_IssueTopComponent")); // NOI18N
                    setToolTipText(NbBundle.getMessage(IssueTopComponent.class"CTL_IssueTopComponent")); // NOI18N
                }
            }
        });
    }
    @Override
    public void propertyChange(PropertyChangeEvent evt) {
            .setVisible(false);
            setNameAndTooltip();
            if(!.isEnabled()) {
                // well, looks like there shuold be only one repository available
                return;
            }
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    if( != null) {
                        .refreshRepositoryModel();
                    }
                }
            });
        }
    }
    @Override
    public boolean requestFocusInWindow() {
        if ( == null) {
            return .requestFocusInWindow();
        } else {
            return .getController().getComponent().requestFocusInWindow();
        }
    }
New to GrepCode? Check out our FAQ X