alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

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-2003 Sun
 * Microsystems, Inc. All Rights Reserved.
 */
package org.netbeans.modules.xml.core.scenario;

import java.awt.Component;
import java.awt.Container;
import org.openide.DialogDescriptor;
import org.openide.util.HelpCtx;

import org.netbeans.modules.xml.api.scenario.*;

import java.awt.Dialog;
import java.util.HashMap;
import java.util.Vector;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.openide.NotifyDescriptor;
import org.openide.DialogDisplayer;
import org.openide.loaders.DataObject;

/**
 * This panel allows the user to edit scenarios for a particular DataObject.
 *
 * @author  asgeir@dimonsoftware.com
 */
public class ScenarioPanel extends javax.swing.JPanel {
    
    /** The list model which represents the scenarios */
    private DefaultComboBoxModel scenarioModel;
    
    /** The selected scenario, one of the Scenario objects in scenarioModel
     * @supplierCardinality 0..**/
    private Scenario selectedScenario;
    
    /** The svenario that was selected at startup */
    private Scenario selectedScenarioAtStartup;
    
    /** The DataObject which owns the scenarios */
    private DataObject dataObject;
    
    /** Mapping from scenario to a UI component for that scenario */
    private HashMap uiCompMap = new HashMap();
    
    /** Creates new form ScenarioPanel */
    public ScenarioPanel(DataObject dataObject, DefaultComboBoxModel scenarioModel) {
        this.scenarioModel = scenarioModel;
        this.dataObject = dataObject;
        
        initComponents();
        
        scenarioList.setModel(scenarioModel);
        selectedScenarioAtStartup = selectedScenario = (Scenario)scenarioModel.getSelectedItem();
        scenarioList.setSelectedValue(selectedScenario, true);
        
    }
    
     public boolean createScenario() {
        Scenario s = NewScenarioPanel.createScenario(dataObject, scenarioModel);
        if (s != null) {
            scenarioList.setSelectedValue(s, true);
            enableControls();
            m_addedScenarios.add(s);
            return true;
        }
        
        return false;
    }
    
    public void rollBackAddedAndRemovedScenarios() {
        for(int i=0; i= 0) {
            scenarioList.setSelectedIndex(selInd);
        }
        
        enableControls();
        
    }//GEN-LAST:event_removeButtonActionPerformed
    
    private void addButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_addButtonActionPerformed
        createScenario();
    }//GEN-LAST:event_addButtonActionPerformed
    

    
    /** A list of Scenarios deleted since dialog startup, needed to rollback actions when "Cancel" pressed */
    private Vector m_deletedScenarios = new Vector();
    /** A list of Scenarios added since dialog startup, needed to rollback actions when "Cancel" pressed */
    private Vector m_addedScenarios = new Vector();
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPanel curScenarioPanel;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JList scenarioList;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JButton addButton;
    private javax.swing.JButton renameButton;
    private javax.swing.JButton removeButton;
    // End of variables declaration//GEN-END:variables
    
    
    private void enableControls() {
        removeButton.setEnabled(selectedScenario != null);
        renameButton.setEnabled(selectedScenario != null);
    }
    
    
    private class NamePanel extends JPanel {
        private JTextField nameField;
        
        public NamePanel() {
            add(new JLabel(Util.THIS.getString("LBL_Rename_panel_name")));
            
            nameField = new JTextField(30);
            add(nameField);
        }
        
        public void setName(String name) {
            nameField.setText(name);
        }
        
        public String getName() {
            return nameField.getText();
        }
    }
}
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

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.