/// <summary>
        /// Saves the input back into the dataset. </summary>
        /// <returns> true if the data was saved successfuly.  False if not. </returns>
        private bool saveData()
        {
            string routine = "StateMod_Reservoir_Owner_JFrame.saveData";

            if (!__worksheet.stopEditing())
            {
                // don't save if there are errors.
                Message.printWarning(1, routine, "There are errors in the data " + "that must be corrected before data can be saved.", this);
                return(false);
            }

            if (checkInput() > 0)
            {
                return(false);
            }

            // now only save data if any are different.
            bool needToSave = false;

            // if the Vectors are differently-sized, they're different
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @SuppressWarnings("unchecked") java.util.List<StateMod_ReservoirAccount> wv = (java.util.List<StateMod_ReservoirAccount>)__worksheet.getAllData();
            IList <StateMod_ReservoirAccount> wv = (IList <StateMod_ReservoirAccount>)__worksheet.getAllData(); // w for worksheet
            IList <StateMod_ReservoirAccount> rv = __currentRes.getAccounts();                                  // i for instream flow

            needToSave = !(StateMod_ReservoirAccount.Equals(wv, rv));

            Message.printStatus(1, routine, "Saving? .........[" + needToSave + "]");

            if (!needToSave)
            {
                // there's nothing different -- users may even have deleted
                // some rights and added back in identical values
                return(true);
            }

            // now add the elements from the new Vector to the reservoirRights
            // Vector.
            int size = wv.Count;
            IList <StateMod_ReservoirAccount> clone = new List <StateMod_ReservoirAccount>();
            StateMod_ReservoirAccount         ra;

            for (int i = 0; i < size; i++)
            {
                ra = (StateMod_ReservoirAccount)wv[i].clone();
                clone.Add(ra);
            }

            __currentRes.setAccounts(clone);
            __dataset.setDirty(StateMod_DataSet.COMP_RESERVOIR_STATIONS, true);
            return(true);
        }
示例#2
0
        /// <summary>
        /// Constructor. </summary>
        /// <param name="data"> the data to display in the worksheet.  Can be null or empty, in
        /// which case an empty worksheet is shown. </param>
        /// <param name="titleString"> the String to display as the GUI title. </param>
        /// <param name="editable"> whether the data in the JFrame can be edited or not.  If true
        /// the data can be edited, if false they can not. </param>
        /// <exception cref="Exception"> if there is an error building the worksheet. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public StateMod_ReservoirAccount_Data_JFrame(java.util.List data, String titleString, boolean editable) throws Exception
        public StateMod_ReservoirAccount_Data_JFrame(System.Collections.IList data, string titleString, bool editable) : base()
        {
            int j     = 0;
            int size  = 0;
            int size2 = 0;
            StateMod_Reservoir        r = null;
            StateMod_ReservoirAccount a = null;

            System.Collections.IList accounts = null;
            System.Collections.IList v        = new List <object>();

            if (data != null)
            {
                size = data.Count;
            }

            for (int i = 0; i < size; i++)
            {
                r        = (StateMod_Reservoir)data[i];
                accounts = r.getAccounts();
                if (accounts == null)
                {
                    continue;
                }

                size2 = accounts.Count;

                for (j = 0; j < size2; j++)
                {
                    a = (StateMod_ReservoirAccount)accounts[j];
                    a.setCgoto(r.getID());
                    v.Add(a);
                }
            }

            initialize(v, titleString, editable);
            setSize(691, getHeight());
        }
        /// <summary>
        /// Creates a list of the available IDs for a Vector of StateMod_Data-extending
        /// objects.  Reservoirs will include an identifier for each reservoir total and each account for the reservoir. </summary>
        /// <param name="nodes"> the nodes for which to create a list of IDs. </param>
        /// <param name="include_accounts"> If true, the </param>
        /// <returns> a Vector of Strings, each of which contains an ID followed by the name of Structure in parentheses </returns>
        private System.Collections.IList createAvailableIDsList(System.Collections.IList nodes)
        {
            System.Collections.IList v = new List <object>();

            int  num          = 0;
            bool is_reservoir = false;     // To allow check below

            if (nodes != null)
            {
                num = nodes.Count;
                if ((num > 0) && ((StateMod_Data)nodes[0]) is StateMod_Reservoir)
                {
                    is_reservoir = true;
                }
            }

            StateMod_Reservoir res = null;     // These are used if reservoirs.
            int nowner             = 0;
            int ia = 0;

            for (int i = 0; i < num; i++)
            {
                // Add the normal item...
                v.Add(StateMod_Util.formatDataLabel(((StateMod_Data)nodes[i]).getID(), ((StateMod_Data)nodes[i]).getName()));
                if (is_reservoir)
                {
                    // Also add reservoir owner/accounts...
                    res    = (StateMod_Reservoir)nodes[i];
                    nowner = res.getAccounts().Count;
                    for (ia = 0; ia < nowner; ia++)
                    {
                        v.Add(StateMod_Util.formatDataLabel(res.getID() + "-" + (ia + 1), res.getName() + " - " + res.getAccount(ia).getName()));
                    }
                }
            }
            return(v);
        }
        /// <summary>
        /// Sets up the GUI.
        /// </summary>
        public virtual void setupGUI()
        {
            string routine = "setupGUI";

            addWindowListener(this);

            PropList p = new PropList("StateMod_Reservoir_JFrame.JWorksheet");

            p.add("JWorksheet.AllowCopy=true");
            p.add("JWorksheet.CellFont=Courier");
            p.add("JWorksheet.CellStyle=Plain");
            p.add("JWorksheet.CellSize=11");
            p.add("JWorksheet.HeaderFont=Arial");
            p.add("JWorksheet.HeaderStyle=Plain");
            p.add("JWorksheet.HeaderSize=11");
            p.add("JWorksheet.HeaderBackground=LightGray");
            p.add("JWorksheet.RowColumnPresent=false");
            p.add("JWorksheet.ShowPopupMenu=true");
            p.add("JWorksheet.SelectionMode=SingleRowSelection");

            int[]            widths = null;
            JScrollWorksheet jsw    = null;

            try
            {
                IList <StateMod_ReservoirAccount> accounts = __currentRes.getAccounts();
                IList <string>            v3   = new List <string>();
                int                       size = accounts.Count;
                StateMod_ReservoirAccount ra   = null;
                for (int i = 0; i < size; i++)
                {
                    ra = accounts[i];
                    v3.Add("" + ra.getID() + " - " + ra.getName());
                }
                for (int i = 1; i < size; i++)
                {
                    v3.Add("-" + (i + 1) + " - Fill first " + (i + 1) + " accounts");
                }

                IList <StateMod_ReservoirRight> v  = new List <StateMod_ReservoirRight>();
                IList <StateMod_ReservoirRight> v2 = __currentRes.getRights();
                StateMod_ReservoirRight         rr;
                for (int i = 0; i < v2.Count; i++)
                {
                    rr = (StateMod_ReservoirRight)v2[i].clone();
                    v.Add(rr);
                }
                StateMod_ReservoirRight_TableModel   tmr = new StateMod_ReservoirRight_TableModel(v, __editable);
                StateMod_ReservoirRight_CellRenderer crr = new StateMod_ReservoirRight_CellRenderer(tmr);

                jsw         = new JScrollWorksheet(crr, tmr, p);
                __worksheet = jsw.getJWorksheet();

                IList <string> onOff = StateMod_ReservoirRight.getIrsrswChoices(true);
                __worksheet.setColumnJComboBoxValues(StateMod_ReservoirRight_TableModel.COL_ON_OFF, onOff, false);
                __worksheet.setColumnJComboBoxValues(StateMod_ReservoirRight_TableModel.COL_ACCOUNT_DIST, v3, false);
                IList <string> rightTypes = StateMod_ReservoirRight.getItyrsrChoices(true);
                __worksheet.setColumnJComboBoxValues(StateMod_ReservoirRight_TableModel.COL_RIGHT_TYPE, rightTypes, false);
                IList <string> fillTypes = StateMod_ReservoirRight.getN2fillChoices(true);
                __worksheet.setColumnJComboBoxValues(StateMod_ReservoirRight_TableModel.COL_FILL_TYPE, fillTypes, false);

                widths = crr.getColumnWidths();
            }
            catch (Exception e)
            {
                Message.printWarning(2, routine, e);
                jsw         = new JScrollWorksheet(0, 0, p);
                __worksheet = jsw.getJWorksheet();
            }
            __worksheet.setPreferredScrollableViewportSize(null);

            __worksheet.setHourglassJFrame(this);
            __worksheet.addMouseListener(this);
            __worksheet.addKeyListener(this);

            __addRight    = new JButton(__BUTTON_ADD_RIGHT);
            __deleteRight = new JButton(__BUTTON_DEL_RIGHT);
            __deleteRight.setEnabled(false);
            __helpJButton = new JButton(__BUTTON_HELP);
            __helpJButton.setEnabled(false);
            __closeJButton = new JButton(__BUTTON_CLOSE);
            JButton cancelJButton = new JButton(__BUTTON_CANCEL);
            JButton applyJButton  = new JButton(__BUTTON_APPLY);

            GridBagLayout gb       = new GridBagLayout();
            JPanel        bigPanel = new JPanel();

            bigPanel.setLayout(gb);

            FlowLayout fl = new FlowLayout(FlowLayout.RIGHT);
            JPanel     p1 = new JPanel();

            p1.setLayout(fl);

            GridLayout gl         = new GridLayout(2, 2, 1, 1);
            JPanel     info_panel = new JPanel();

            info_panel.setLayout(gl);

            JPanel main_panel = new JPanel();

            main_panel.setLayout(new BorderLayout());

            info_panel.add(new JLabel("Reservoir:"));
            info_panel.add(new JLabel(__currentRes.getID()));
            info_panel.add(new JLabel("Reservoir name:"));
            info_panel.add(new JLabel(__currentRes.getName()));

            if (__editable)
            {
                p1.add(__addRight);
                p1.add(__deleteRight);
            }
            p1.add(applyJButton);
            p1.add(cancelJButton);
            //	p1.add(__helpJButton);
            p1.add(__closeJButton);

            main_panel.add(jsw, "Center");
            main_panel.add(p1, "South");

            JGUIUtil.addComponent(bigPanel, info_panel, 0, 0, 1, 1, 0, 0, GridBagConstraints.NONE, GridBagConstraints.NORTHWEST);
            JGUIUtil.addComponent(bigPanel, main_panel, 0, 1, 10, 10, 1, 1, GridBagConstraints.BOTH, GridBagConstraints.SOUTH);
            __addRight.addActionListener(this);
            __deleteRight.addActionListener(this);
            __helpJButton.addActionListener(this);
            __closeJButton.addActionListener(this);
            applyJButton.addActionListener(this);
            cancelJButton.addActionListener(this);

            getContentPane().add(bigPanel);

            JPanel bottomJPanel = new JPanel();

            bottomJPanel.setLayout(gb);
            __messageJTextField = new JTextField();
            __messageJTextField.setEditable(false);
            JGUIUtil.addComponent(bottomJPanel, __messageJTextField, 0, 0, 7, 1, 1.0, 0.0, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST);
            __statusJTextField = new JTextField(5);
            __statusJTextField.setEditable(false);
            JGUIUtil.addComponent(bottomJPanel, __statusJTextField, 7, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NONE, GridBagConstraints.WEST);
            getContentPane().add("South", bottomJPanel);

            pack();
            setSize(760, 400);
            JGUIUtil.center(this);
            setVisible(true);
            if (widths != null)
            {
                __worksheet.setColumnWidths(widths);
            }
        }