📄 envparametersconfiguration.java
字号:
* 'pe.cfg' file.
*/
public boolean isInPolicy(Element childToCheck)
{
NodeList nlist1 = ((Element)getParentNode()).getElementsByTagName("EnvironmentVariable");
for (int i = 0; i < nlist.getLength() ; i++)
{
Element child = (Element)nlist1.item(i);
if ((childToCheck.getAttribute("Name").equals(child.getAttribute("Name"))))
{
return true;
}
}
return false;
}
/**
* Reads the Fields from the TextBoxes. Checks that the required entries
* to create a valid connection are not empty fields. Then adds the
* new Directory to the XML document.
*/
public void addItem()
{
if (nameTextField.getText().intern().equals(""))
{
JOptionPane.showMessageDialog(xmlED, envParamsConfigError1, errorHeader, JOptionPane.ERROR_MESSAGE);
return;
}
if (dataTypeField.getSelectedIndex() <= 0)
{
JOptionPane.showMessageDialog(xmlED, envParamsConfigError1, errorHeader, JOptionPane.ERROR_MESSAGE);
return;
}
Element child = xmlED.DOM.createElement("EnvironmentVariable");
child.setAttribute("Name", nameTextField.getText());
if (isInPolicy(child))
{
JOptionPane.showMessageDialog(xmlED, envParamsConfigError2, errorHeader, JOptionPane.ERROR_MESSAGE);
return;
}
child.setAttribute("Type", (String)dataTypeField.getSelectedItem());
xmlED.addItem(child, (Element)getParentNode());
nameTextField.grabFocus();
}
/**
* Deletes the Currently Selected node from the NodeList.
*/
public void deleteItem()
{
if (this.getSelectedNode() != null)
{
xmlED.deleteItem((Element)this.getSelectedNode(), ((Element)getParentNode()));
//Set the TextFields to an empty value
clearTextFields();
}
}
/**
* Method that resets all the Textfields to empty or a predefined value.
*/
public void clearTextFields()
{
nameTextField.setText("");
dataTypeField.setSelectedIndex(0);
}
/**
* Method that replaces a Selected Node with the contents of the textfields,
* Provided that the required fields have a valid Variable Definition, are not
* empty.
*/
public void replaceItem()
{
if (this.getSelectedNode() != null)
{
if (!nameTextField.getText().intern().equals("") && dataTypeField.getSelectedIndex() > 0)
{
//Setting the New Attributes to Replace --
String attribs[] = { "Name", "Type" };
String values[] = { nameTextField.getText(), (String)dataTypeField.getSelectedItem() };
Element child = xmlED.DOM.createElement("EnvironmentVariable");
child.setAttribute("Name", nameTextField.getText());
if (isInPolicy(child) && !((Element)this.getSelectedNode()).getAttribute("Name").equals(nameTextField.getText()))
{
JOptionPane.showMessageDialog(xmlED, envParamsConfigError2, errorHeader, JOptionPane.ERROR_MESSAGE);
return;
}
xmlED.setAttributeValue((Element)this.getSelectedNode(), attribs, values);
//----------------------------------------
}
else
{
JOptionPane.showMessageDialog(xmlED, envParamsConfigError1, errorHeader, JOptionPane.ERROR_MESSAGE);
return;
}
}
}
/**
* Method That Populates the NodeList with the current Environment Variables.
*/
public void refreshView()
{
if (xmlED == null || xmlED.DOM == null) return;
if (getParentNode() != null)
{
NodeList nlist = ((Element)getParentNode()).getElementsByTagName("EnvironmentVariable");
Node n;
String envNames[] = new String[nlist.getLength()];
for (int i = 0 ; i < nlist.getLength(); i++)
{
n = nlist.item(i);
envNames[i] = (((Element)n).getAttribute("Name"));
}
setNodeList(nlist, envNames);
}
}
/**
* When the NodeItemList has a selected Element, the contents of that node,
* will populate the textfields, so the user will see exactly what the
* Environment Variable has as a defined type.
* <p>
* Users might then want to modify the Selected node, and therefore the
* refreshed textfields, would just need to be modified.
* <p>
* If nothing is selected in the NodeItemList, the textfields are reset
* using the clearTextFields() method.
*/
public void itemSelected()
{
Element selectedNode;
super.itemSelected();
addButton.setEnabled(false);
replaceButton.setEnabled(false);
if (getSelectedNode() == null)
{
clearTextFields();
}
else
{
selectedNode = (Element)getSelectedNode();
nameTextField.setText(selectedNode.getAttribute("Name"));
dataTypeField.setSelectedItem(selectedNode.getAttribute("Type"));
}
}
/**
* The root node of the Current Document.
*
* @return a node with the root Element of the 'pe.cfg' XML file.
*/
public Node getParentNode()
{
return xmlED.DOM.getElementsByTagName("EnvironmentParameters").item(0);
}
public void keyTyped(KeyEvent e)
{
}
/**
* Method That enables/disables the appropriate buttons when the Text Fields
* are being typed into.
*/
public void keyPressed(KeyEvent e)
{
}
public void keyReleased(KeyEvent e)
{
if (e.getSource() == nameTextField)
{
if (this.listBox.getSelectedValue() == null &&
!nameTextField.getText().intern().equals("") &&
dataTypeField.getSelectedIndex() > 0)
{
addButton.setEnabled(true);
}
else if (!nameTextField.getText().intern().equals("") &&
dataTypeField.getSelectedIndex() > 0)
{
replaceButton.setEnabled(true);
addButton.setEnabled(true);
}
else if (nameTextField.getText().intern().equals("") ||
dataTypeField.getSelectedIndex() <= 0)
{
replaceButton.setEnabled(false);
addButton.setEnabled(false);
}
}
}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand().intern().equals("name_tf") && !nameTextField.getText().intern().equals(""))
{
dataTypeField.grabFocus();
}
else super.actionPerformed(e);
}
public void itemStateChanged(ItemEvent e)
{
if (dataTypeField.getSelectedIndex() <= 0)
{
replaceButton.setEnabled(false);
addButton.setEnabled(false);
return;
}
if (getSelectedIndex() >= 0 && e.getStateChange() == ItemEvent.SELECTED)
{
replaceButton.setEnabled(true);
}
else if (listBox.getSelectedValue() == null &&
!nameTextField.getText().intern().equals("") &&
!((String)dataTypeField.getSelectedItem()).equals("") &&
getSelectedIndex() < 0)
addButton.setEnabled(true);
else if (!nameTextField.getText().intern().equals("") &&
!((String)dataTypeField.getSelectedItem()).equals("") &&
getSelectedIndex() < 0)
{
replaceButton.setEnabled(true);
addButton.setEnabled(true);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -