📄 ifconstraintspaneladvanced.java
字号:
if (conditionsTabbedPane.getTabCount() == 0) {
if (nodeToModify == null) return true;
xmlED.deleteItem(((Element)nodeToModify), (Element)parentTargetAccess);
return true;
}
if (nodeToModify == null) {
xmlED.addItem(child, (Element)parentTargetAccess);
} else {
xmlED.replaceNode((Element)parentTargetAccess, ((Element)nodeToModify), child);
}
return true;
}
public Element createElement(String type) {
Element result = xmlED.DOM.createElement(type);
for (int i = 0; i < conditionsTabbedPane.getTabCount(); i++) {
Element nested = null;
if (type.intern().equals("OR"))
nested = xmlED.DOM.createElement("AND");
else nested = xmlED.DOM.createElement("OR");
result.appendChild((Node)nested);
for (int j = 0; j < ((AdvancedConditionsTable)conditionTables.get(i)).table.getRowCount(); j++) {
Element notElement = null;
AdvancedConditionsTable act = ((AdvancedConditionsTable)conditionTables.get(i));
String operator = ((String)((JComboBox)act.column2Store.get(j)).getSelectedItem());
String tmpType = ((ConditionOnComboBox)act.column1Store.get(j)).types[((JComboBox)act.column1Store.get(j)).getSelectedIndex()];
String tmpName = ((ConditionOnComboBox)act.column1Store.get(j)).getParams()[((JComboBox)act.column1Store.get(j)).getSelectedIndex()];
String tmpValue = ((String)((JTextField)act.column3Store.get(j)).getText());
if (operator == null || tmpName == null || tmpValue == null || tmpValue.intern().equals("")) {
JOptionPane.showMessageDialog(xmlED, errorMSG1+" "+tmpName+" "+operator, errorHeader, JOptionPane.ERROR_MESSAGE);
return null;
}
operator = getXMLOperator(act, operator, tmpType);
if (operator.charAt(0) == '!') {
operator = operator.substring(1);
notElement = xmlED.DOM.createElement("NOT");
notElement.appendChild(createElementSection(act, operator, tmpType, tmpName, tmpValue, j));
nested.appendChild((Node)notElement);
} else {
nested.appendChild(createElementSection(act, operator, tmpType, tmpName, tmpValue, j));
}
}
}
return result;
}
public Element createElementSection(AdvancedConditionsTable act, String operator, String tmpType, String tmpName, String tmpValue, int j) {
Element newOperator = xmlED.DOM.createElement(operator);
Element newArg = null;
String srcString = ((ConditionOnComboBox)act.column1Store.get(j)).variable[((JComboBox)act.column1Store.get(j)).getSelectedIndex()];
if (srcString.intern().equalsIgnoreCase(rbl.getString("ConditionsTable_DropDown_Source1"))) {
newArg = xmlED.DOM.createElement("Environment");
} else if (srcString.intern().equalsIgnoreCase(rbl.getString("ConditionsTable_DropDown_Source2"))) {
newArg = xmlED.DOM.createElement("Arg");
}
newOperator.appendChild((Node)newArg);
Element newConstant = xmlED.DOM.createElement("Constant");
newOperator.appendChild((Node)newConstant);
newArg.setAttribute("Name", tmpName);
newArg.setAttribute("Type", tmpType);
newConstant.setAttribute("Type", tmpType);
newConstant.setAttribute("Value", tmpValue);
if (tmpType.equalsIgnoreCase(rb.getString("type1")) || tmpType.equalsIgnoreCase(rb.getString("type2")) ||
tmpType.equalsIgnoreCase(rb.getString("type7")) || tmpType.equalsIgnoreCase(rb.getString("type9"))) {
newArg.setAttribute("Type", rb.getString("type1"));
newConstant.setAttribute("Type", rb.getString("type1"));
newConstant.setAttribute("Value", getAbsoluteTime(tmpValue));
}
return newOperator;
}
public String getAbsoluteTime(String s) {
if (s.indexOf(":") == -1) { //it is a date
return s+"T**:**:**";
} else if (s.indexOf("-") == -1) { //it is a time
return "****-**-**T"+s;
} else return s; //it is an absolute
}
public void getTabNames() {
String baseName, borderName;
if (andSelected.isSelected()) {
borderName = oneConditionsListCaption;
baseName = oneOfTheFollowingCaption;
} else {
borderName = allConditionsListCaption;
baseName = allOfTheFollowingCaption;
}
if (conditionsTabbedPane == null) return;
for (int i = 0; i < conditionsTabbedPane.getTabCount(); i++) {
conditionsTabbedPane.setTitleAt(i, baseName + " " + (i+1));
((AdvancedConditionsTable)conditionTables.get(i)).tableView.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), borderName));
}
}
/**
* This method, changes the descriptive part of the operator, that is
* seen in the table, and returns it into a Tag that can be
* inserted in the XML.
*
* @param row the row the descriptive operator is on.
* @param operator the descriptive value as obtained in String form.
* @return the relevant XML tag, that describes the operation done.
*/
public String getXMLOperator(AdvancedConditionsTable act, String operator, String type) {
Vector tmpItems = (Vector)act.varTypeLinks.get(type);
for (int y = 0; y < tmpItems.size(); y++) {
String tmpString[] = ((String[])tmpItems.get(y));
if (tmpString[0].intern().equalsIgnoreCase(operator)) {
operator = tmpString[1];
}
}
return operator;
}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand().intern().equals("ADD_BLOCK")) {
AdvancedConditionsTable newTable = new AdvancedConditionsTable(this.xmlED, this.index, this.owner);
this.conditionTables.add(newTable);
constraints.gridx = 0; constraints.gridy = 0;
constraints.weightx = 1; constraints.weighty = 1;
constraints.gridwidth = 1; constraints.gridheight = 1;
constraints.anchor = GridBagConstraints.CENTER;
constraints.fill = GridBagConstraints.BOTH;
this.conditionsTabbedPane.add(((AdvancedConditionsTable)conditionTables.get(conditionTables.size()-1)).getContentPanel());
newTable.addRow(0);
conditionsTabbedPane.setSelectedIndex(conditionTables.size()-1);
deleteConditionsBlocks.setEnabled(true);
} else if (e.getActionCommand().intern().equals("DELETE_BLOCK")) {
this.conditionTables.remove(conditionsTabbedPane.getSelectedIndex());
conditionsTabbedPane.remove(conditionsTabbedPane.getSelectedIndex());
if (conditionsTabbedPane.getTabCount() == 0)
deleteConditionsBlocks.setEnabled(false);
refreshTabColours(conditionsTabbedPane);
}
getTabNames();
}
public void stateChanged(ChangeEvent e) {
refreshTabColours((JTabbedPane)e.getSource());
}
public void refreshTabColours(JTabbedPane jPane) {
for (int i = 0; i < jPane.getTabCount(); i++) {
jPane.setForegroundAt(i, Color.BLACK);
}
if (jPane.getSelectedIndex() > -1)
jPane.setForegroundAt(jPane.getSelectedIndex(), Color.BLUE);
}
public void itemStateChanged(ItemEvent e) {
getTabNames();
}
public void refresh() {
if (xmlED.DOM == null) return;
NodeList nodesInPolicy = xmlED.DOM.getElementsByTagName("TargetAccessPolicy");
Element root = ((Element)nodesInPolicy.item(0));
NodeList targetAccess = DomainPolicyEditor.getChildElements(root);
Node sectionalRoot = targetAccess.item(index);
NodeList section = DomainPolicyEditor.getChildElements(sectionalRoot);
if (section.getLength() < 3 ) {
actionPerformed(new ActionEvent(this,0,"ADD_BLOCK"));
return;
}
NodeList types = DomainPolicyEditor.getChildElements(section.item(2));
Element typeAndOr = ((Element)types.item(0));
if (typeAndOr.getTagName() == "OR")
orSelected.setSelected(true);
else if (typeAndOr.getTagName() == "AND")
andSelected.setSelected(true);
NodeList andOrs = DomainPolicyEditor.getChildElements(typeAndOr);
for (int i = 0; i < andOrs.getLength(); i++) {
NodeList operators = DomainPolicyEditor.getChildElements(andOrs.item(i));
actionPerformed(new ActionEvent(this,0,"ADD_BLOCK"));
for (int j = 0; j < operators.getLength(); j++) {
String operator = ((Element)operators.item(j)).getTagName();
NodeList argsConstant = DomainPolicyEditor.getChildElements((Element)operators.item(j));
if (operator.equals("NOT")) {
Element notElement = (Element)DomainPolicyEditor.getChildElements((Element)operators.item(j)).item(0);
operator = "!"+notElement.getTagName();
argsConstant = DomainPolicyEditor.getChildElements(notElement);
}
if (argsConstant.getLength() == 0) return;
String sourceType = ((Element)argsConstant.item(0)).getTagName();
String argName = ((Element)argsConstant.item(0)).getAttribute("Name");
String argType = ((Element)argsConstant.item(0)).getAttribute("Type");
operator = getOperatorDescription(operator, argType);
String constantType = ((Element)argsConstant.item(1)).getAttribute("Type");
String constantValue = ((Element)argsConstant.item(1)).getAttribute("Value");
if (constantValue.indexOf("****-**-**T") > -1) { //it is a time
argType = rb.getString("type1");
constantValue = constantValue.substring(constantValue.indexOf("T")+1);
} else if (constantValue.indexOf("T**:**:**") > -1) { //it is a date
argType = rb.getString("type2");
constantValue = constantValue.substring(0, constantValue.indexOf("T"));
} else { //its an absolute time
argType = rb.getString("type7");
}
if (j > 0) ((AdvancedConditionsTable)conditionTables.get(i)).addRow(j);
((AdvancedConditionsTable)conditionTables.get(i)).table.setEditingRow(j);
((JComboBox)((AdvancedConditionsTable)conditionTables.get(i)).column1Store.get(j)).setSelectedItem(argName);
((JComboBox)((AdvancedConditionsTable)conditionTables.get(i)).column2Store.get(j)).setSelectedItem(operator);
((JTextField)((AdvancedConditionsTable)conditionTables.get(i)).column3Store.get(j)).setText(constantValue);
}
}
conditionsTabbedPane.setSelectedIndex(0);
}
/**
* This method, changes the XML Tag of the operator, in a more readable
* human form. The Value is obtained from the hash table that is
* populater in Conditions Table.
*
* @param operator the descriptive value as obtained in String form.
* @param type the Variable Type (String/Integer/Time/Boolean/Real)
* @return the relevant XML tag, that describes the operation done.
*/
public String getOperatorDescription(String operator, String type) {
Vector tmpItems = (Vector)((AdvancedConditionsTable)conditionTables.get(0)).varTypeLinks.get(type);
for (int y = 0; y < tmpItems.size(); y++) {
String tmpString[] = ((String[])tmpItems.get(y));
if (tmpString[1].intern().equalsIgnoreCase(operator)) {
operator = tmpString[0];
}
}
return operator;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -