popupaddclass.java

来自「Semantic Web Ontology Editor」· Java 代码 · 共 1,635 行 · 第 1/5 页

JAVA
1,635
字号
                        cla = (OWLClass) resClassBox.getSelectedItem();                        //********************************************                        //Added for Econn                        //********************************************                        if (propType.equals("Link"))                            foreignEnt.add(cla);                        //********************************************                    } else {                        // user-specified class name/uri                        String claStr = resClassBox.getSelectedItem()                                .toString();                        claStr = claStr.replaceAll(" ","_");                        if (!isURI(claStr))                            claStr = swoopModel.getSelectedOntology()                                    .getLogicalURI()                                    + "#" + claStr;                        URI claURI = new URI(claStr);                        cla = swoopModel.getSelectedOntology()                                .getOWLDataFactory().getOWLClass(claURI);                        //********************************************                        //Added for Econn                        //********************************************                        if (propType.equals("Link"))                            foreignEnt.add(cla);                        //********************************************                    }                }            } else if (resNameCombo.getSelectedIndex() == 3) {                if (propType.equals("Data")) {                    // get data value                    // has value for datatype property                    String dtURIStr = resDTypeBox.getSelectedItem().toString();                    URI dtURI = new URI(dtURIStr);                    String dValStr = resDTypeFld.getText();                    dVal = ontDF.getOWLConcreteData(dtURI, "EN", dValStr);                } else {                    // get individual                    if (restrClassOntologyCombo.getSelectedIndex() != 0) {                        ind = (OWLIndividual) resClassBox.getSelectedItem();                    } else {                        String indStr = resClassBox.getSelectedItem()                                .toString();                        if (!isURI(indStr))                            indStr = swoopModel.getSelectedOntology()                                    .getLogicalURI()                                    + "#" + indStr;                        URI indURI = new URI(indStr);                        ind = swoopModel.getSelectedOntology()                                .getOWLDataFactory().getOWLIndividual(indURI);                    }                    //********************************************                    //Added for Econn                    //********************************************                    if (propType.equals("Link"))                        foreignEnt.add(ind);                    //********************************************                }            } else {                // get cardinality                try {                    cardinality = Integer.parseInt(resClassBox                            .getSelectedItem().toString());                    if (cardinality < 0) {                        popupError("Invalid Integer Argument");                        return;                    }                } catch (Exception ex) {                    popupError("Invalid Integer Argument");                    return;                }            }            //--------------------------------------------            // create restriction based on user selections            OWLRestriction res = null;            switch (resNameCombo.getSelectedIndex()) {                case 0 :                    // cardinality restriction                    if (userPropURI != null) {                        // create new property as Object Property - default                        prop = ontDF.getOWLObjectProperty(userPropURI);                        propType = "Object";                    }                    if (propType.equals("Data"))                        res = ontDF.getOWLDataCardinalityRestriction(                                (OWLDataProperty) prop, cardinality,                                cardinality);                    else                        res = ontDF.getOWLObjectCardinalityRestriction(                                (OWLObjectProperty) prop, cardinality,                                cardinality);                    break;                case 1 :                    // minCardinality restriction                    if (userPropURI != null) {                        // create new property as Object Property - default                        prop = ontDF.getOWLObjectProperty(userPropURI);                        propType = "Object";                    }                    if (propType.equals("Data"))                        res = ontDF.getOWLDataCardinalityAtLeastRestriction(                                (OWLDataProperty) prop, cardinality);                    else                        res = ontDF.getOWLObjectCardinalityAtLeastRestriction(                                (OWLObjectProperty) prop, cardinality);                    break;                case 2 :                    // maxCardinality restriction                    if (userPropURI != null) {                        // create new property as Object Property - default                        prop = ontDF.getOWLObjectProperty(userPropURI);                        propType = "Object";                    }                    if (propType.equals("Data"))                        res = ontDF.getOWLDataCardinalityAtMostRestriction(                                (OWLDataProperty) prop, cardinality);                    else                        res = ontDF.getOWLObjectCardinalityAtMostRestriction(                                (OWLObjectProperty) prop, cardinality);                    break;                case 3 :                    // hasValue restriction                    if (propType.equals("Data")) {                        URI uri = new URI(resDTypeBox.getSelectedItem().toString());                        if (dVal == null)                        {                            popupError("'hasValue' restriction on Datatype property must have range of Data-Value");                            return;                        }                        boolean flag = DataValueChecker.isValidValue(this, uri, resDTypeFld.getText());                        if (!flag)                            return;                        res = ontDF.getOWLDataValueRestriction(                                (OWLDataProperty) prop, dVal);                    } else {                        if (ind == null) {                            popupError("'hasValue' restriction on Object property must have range of Instance");                            return;                        }                        res = ontDF.getOWLObjectValueRestriction(                                (OWLObjectProperty) prop, ind);                    }                    break;                case 4 :                    // someValuesFrom restriction                    if (propType.equals("Data")) {                        if (userPropURI != null)                            prop = ontDF.getOWLDataProperty(userPropURI);                        if (dRan == null) {                            popupError("'someValuesFrom' restriction on Datatype property must have range of Datatype");                            return;                        }                        res = ontDF.getOWLDataSomeRestriction(                                (OWLDataProperty) prop, dRan);                    } else {                        if (userPropURI != null)                            prop = ontDF.getOWLObjectProperty(userPropURI);                        if (cla == null) {                            popupError("'someValuesFrom' restriction on Object property must have range of Class");                            return;                        }                        res = ontDF.getOWLObjectSomeRestriction((OWLObjectProperty) prop, cla);                    }                    break;                case 5 :                    // allValuesFrom restriction                    if (propType.equals("Data")) {                        if (userPropURI != null)                            prop = ontDF.getOWLDataProperty(userPropURI);                        if (dRan == null) {                            popupError("'allValuesFrom' restriction on Datatype property must have range of Datatype");                            return;                        }                        res = ontDF.getOWLDataAllRestriction(                                (OWLDataProperty) prop, dRan);                    } else {                        if (userPropURI != null)                            prop = ontDF.getOWLObjectProperty(userPropURI);                        if (cla == null) {                            popupError("'allValuesFrom' restriction on Object property must have range of Class");                            return;                        }                        res = ontDF.getOWLObjectAllRestriction((OWLObjectProperty) prop, cla);                    }                    break;            }            //************************************************            //Added for Econn            //************************************************            Iterator iter = foreignEnt.iterator();            while (iter.hasNext()) {                OWLEntity entit = (OWLEntity) iter.next();                OntologyChange oc = null;                if (!(swoopModel.getSelectedOntology().getForeignEntities()                        .containsKey(entit)))                    oc = new AddForeignEntity(swoopModel.getSelectedOntology(),                            entit, ((OWLObjectProperty) prop).getLinkTarget(),                            null);                changes.add(oc);            }            //******************************************           makeChange(res);            Iterator j = foreignEnt.iterator();            while (j.hasNext()) {                OWLEntity entit = (OWLEntity) j.next();                OntologyChange oc = null;                oc = new RemoveEntity(swoopModel.getSelectedOntology(), entit,                        null);                swoopModel.getSelectedOntology().getForeignEntities().put(                        entit, ((OWLObjectProperty) prop).getLinkTarget());                changes.add(oc);            }            swoopModel.addUncommittedChanges(changes);            changes = new ArrayList(); // reset it after changes have been added                    } catch (Exception ex) {            ex.printStackTrace();        }    }    private void popupError(String msg) {        JOptionPane.showMessageDialog(this, msg,                "Error creating OWL Description", JOptionPane.ERROR_MESSAGE);    }        public void actionPerformed(ActionEvent e) {    	if (e.getSource() == classBar) {    		if (e.getActionCommand().equals(AddCloseBar.ADD)) {    			addClassChange();    		}    		if (e.getActionCommand().equals(AddCloseBar.ADDCLOSE)) {    			addClassChange();    			dispose();    		}    		if (e.getActionCommand().equals(AddCloseBar.CLOSE)) {    			dispose();    		}    	}    	else if (e.getSource() == restrictionBar) {    		if (e.getActionCommand().equals(AddCloseBar.ADD)) {    			addRestrictionChange();    		}    		if (e.getActionCommand().equals(AddCloseBar.ADDCLOSE)) {    			addRestrictionChange();    			dispose();    		}    		if (e.getActionCommand().equals(AddCloseBar.CLOSE)) {    			dispose();    		}    	}    	else if (e.getSource() == ceBar) {    		if (e.getActionCommand().equals(AddCloseBar.ADD)) {    			addCEChange();    		}    		if (e.getActionCommand().equals(AddCloseBar.ADDCLOSE)) {    			addCEChange();        		if (currClassExpr!=null) dispose();    		}    		if (e.getActionCommand().equals(AddCloseBar.CLOSE)) {    			dispose();    		}    	}    	else if (e.getSource() == cancelBtn3) {    		dispose();    	}    	else if (e.getSource() == addCEBtn) {            if (this.typeIntCode == -1) {            	// just added LHS of GCI            	this.addLHSGCI();            	            }            else if (this.typeIntCode == -2) {            	// just added RHS of GCI            	this.addRHSGCI();            }        	else {        		// adding class expression normally        		addCEChange();        		if (currClassExpr!=null) dispose();        	}                    }    	else if ((e.getSource() instanceof AddCloseBar)     			&& e.getActionCommand().equals(AddCloseBar.CLOSE)) {    		dispose();    	}        else if (e.getSource() == someBtn) {        	this.createCE(SOME);        }        else if (e.getSource() == allBtn) {        	this.createCE(ALL);        }        else if (e.getSource() == equBtn) {        	this.createCE(EQU);			        }        else if (e.getSource() == maxBtn) {        	this.createCE(MAX);        }        else if (e.getSource() == minBtn) {        	this.createCE(MIN);        }        else if (e.getSource() == intBtn) {        	this.createCE(INT);        }        else if (e.getSource() == uniBtn) {        	this.createCE(UNI);			        }        else if (e.getSource() == oneBtn) {        	this.createCE(ONE);			        }        else if (e.getSource() == negBtn) {        	this.createCE(NEG);        }        else if (e.getSource() == clearSelBtn1) {        	propList.clearSelection();        }        else if (e.getSource() == clearSelBtn2) {        	valList.clearSelection();        }        else if (e.getSource() == clearSelBtn3) {        	ceList.clearSelection();        }            }        /*     * Create a CE based on user selection and button pressed

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?