popupaddclass.java

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

JAVA
1,635
字号
        restrPropOntologyCombo.removeItemListener(this);        restrClassOntologyCombo.removeItemListener(this);        ontList.removeListSelectionListener(this);        ontPropBox.removeItemListener(this);        ontValBox.removeItemListener(this);                // fill starting entries in ontCombo boxes        simpleClassOntologyCombo.addItem("/New term or URI");        restrPropOntologyCombo.addItem("/New term or URI");        restrClassOntologyCombo.addItem("/New term or URI");        Set sortedOntSet = new TreeSet(OntologyComparator.INSTANCE);        sortedOntSet.addAll(swoopModel.getOntologyURIs());        ontList.setListData(sortedOntSet.toArray());        Iterator iter = sortedOntSet.iterator();        while (iter.hasNext()) {            String uri = iter.next().toString();            simpleClassOntologyCombo.addItem(uri);            restrClassOntologyCombo.addItem(uri);            restrPropOntologyCombo.addItem(uri);            ontPropBox.addItem(uri);        	ontValBox.addItem(uri);        }                // turn on listeners        simpleClassOntologyCombo.addItemListener(this);        restrPropOntologyCombo.addItemListener(this);        restrClassOntologyCombo.addItemListener(this);        ontList.addListSelectionListener(this);        ontPropBox.addItemListener(this);        ontValBox.addItemListener(this);                // select current displayed ontology        try {            String currOntURI = swoopModel.getSelectedOntology().getURI()                    .toString();            simpleClassOntologyCombo.setSelectedItem(currOntURI);            restrPropOntologyCombo.setSelectedItem(currOntURI);            restrClassOntologyCombo.setSelectedItem(currOntURI);            ontList.setSelectedValue(swoopModel.getSelectedOntology().getURI(),                    true);            ontPropBox.setSelectedItem(currOntURI);            ontValBox.setSelectedItem(currOntURI);        } catch (Exception ex) {            ex.printStackTrace();        }    }        /**     * Create the appropriate Ontology Change (class-level) depending on the     * type-code Default parameters of the change are current selected ontology     * and class     *     * @param newDesc -     *            new OWL description component of change     * @throws OWLException     */    private void makeChange(OWLDescription newDesc) throws OWLException {        // create the ontology change object        OWLOntology dispOnt = swoopModel.getSelectedOntology();        OWLEntity dispEntity = swoopModel.getSelectedEntity();        OntologyChange change = null;        switch (typeIntCode) {        	case 0 :                // add equivalent-class                change = new AddEquivalentClass(dispOnt, (OWLClass) dispEntity,                        newDesc, null);                changes.add(change);                break;            case 9 :                // add complement class                addBooleanSet(dispOnt, (OWLClass) dispEntity, newDesc, "COM");                break;            case 1 :                // add super-class                change = new AddSuperClass(dispOnt, (OWLClass) dispEntity, newDesc, null);                changes.add(change);                break;            case 2 :                // add sub-class                OWLSubClassAxiom axiom = dispOnt.getOWLDataFactory().getOWLSubClassAxiom(newDesc, (OWLClass) dispEntity);                change = new AddClassAxiom(dispOnt, axiom, null);                changes.add(change);                break;            case 3 :                // add disjoint-class                OWLDataFactory df = dispOnt.getOWLDataFactory();                Set disSet = new HashSet();                disSet.add(newDesc);                disSet.add(dispEntity);                OWLDisjointClassesAxiom disAxiom = df                        .getOWLDisjointClassesAxiom(disSet);                change = new AddClassAxiom(dispOnt, disAxiom, null);                changes.add(change);                break;            case 4 :                // add element to intersection-set                addBooleanSet(dispOnt, (OWLClass) dispEntity, newDesc, "INT");                break;            case 5 :                // add element to union-set                addBooleanSet(dispOnt, (OWLClass) dispEntity, newDesc, "UNI");                break;            case 6 :                // add domain class                change = new AddDomain(dispOnt, (OWLProperty) dispEntity,                        newDesc, null);                changes.add(change);                break;            case 7 :                // add range class                OWLProperty prop = (OWLProperty) dispEntity;                if (prop instanceof OWLDataProperty) {                    String dTypeURIStr = newClassFld.getText();                    if (isURI(dTypeURIStr)) {                        URI uri = null;                        try {                            uri = new URI(dTypeURIStr);                        } catch (URISyntaxException e) {                            e.printStackTrace();                        }                        OWLDataType dType = swoopModel.getSelectedOntology()                                .getOWLDataFactory()                                .getOWLConcreteDataType(uri);                        change = new AddDataPropertyRange(dispOnt,                                (OWLDataProperty) prop, dType, null);                        changes.add(change);                    }                } else {                    //					************************************                    //added for Econnections                    //*****************************************                    if (!((OWLObjectProperty) prop).isLink()) {                        change = new AddObjectPropertyRange(dispOnt,                                (OWLObjectProperty) prop, newDesc, null);                        changes.add(change);                    } else {                        if (newDesc instanceof OWLClass) {                            change = new AddObjectPropertyRange(dispOnt,                                    (OWLObjectProperty) prop, newDesc, null);                            changes.add(change);                            OntologyChange change2 = new AddForeignEntity(                                    dispOnt, (OWLClass) newDesc,                                    ((OWLObjectProperty) prop).getLinkTarget(),                                    null);                            changes.add(change2);                            OntologyChange change3 = new RemoveEntity(dispOnt,                                    (OWLClass) newDesc, null);                            changes.add(change3);                        }                    }                }                break;            case 8 :                // add instance type                OWLIndividual ind = (OWLIndividual) dispEntity;                change = new AddIndividualClass(dispOnt, ind, newDesc, null);                changes.add(change);                break;        }    }    /**     * Create and return an ADD boolean element change i.e. ADD intersection or     * union element on a particular class     *     * @param dispOnt -     *            displayed ontology     * @param dispClass -     *            displayed class     * @param newDesc -     *            OWL description of boolean element     * @param type -     *            INT or UNI or COM     * @throws OWLException     */    private void addBooleanSet(OWLOntology dispOnt, OWLClass dispClass,            OWLDescription newDesc, String type) throws OWLException {        /**         * need to change when more than one boolean set present currently adds         * 'newDesc' to first boolean set         */        Class typeC = null;        if (type.equals("INT"))            typeC = OWLAnd.class;        else if (type.equals("UNI"))            typeC = OWLOr.class;        else            typeC = OWLNot.class;        BooleanElementChange change = new BooleanElementChange(typeC, "Add",                dispOnt, dispClass, newDesc, null);        changes.add(change);    }        /**     * Method called when the 'Add' class button is pressed in the Class Expression Pane.     * It gets the OWL CE created by the user and passes it to makeChange(..) to create the     * appropriate class change (e.g. AddSuperClass etc)     *     */    private void addCEChange() {    	currClassExpr = (OWLDescription) ceList.getSelectedValue();    	if (currClassExpr!=null) {	    	try {				this.makeChange(currClassExpr);			} catch (OWLException e) {				e.printStackTrace();			}	    	swoopModel.addUncommittedChanges(changes);	        changes = new ArrayList(); // reset it after changes have been added    	}    	else ceStatusLbl.setText("No Class Expression selected!");    }        /**     * Method called when the 'Add' class button is pressed It gets the OWL     * class selected by the user and passes it to makeChange(..) to create the     * appropriate class change (e.g. AddSuperClass etc)     *     */    private void addClassChange() {        try {            // get selected OWLClass element            OWLClass selCla = null;            if ((newClassFld.getText() != null)                    && (!newClassFld.getText().trim().equals(""))) {                // user-specified class name/uri                String claStr = newClassFld.getText();                claStr = claStr.replaceAll(" ","_");                if (!isURI(claStr))                    claStr = swoopModel.getSelectedOntology().getLogicalURI()                            + "#" + claStr;                URI claURI = new URI(claStr);                selCla = swoopModel.getSelectedOntology().getOWLDataFactory()                        .getOWLClass(claURI);                makeChange(selCla);            } else {                // existing class in swoopModel                // enable multiple selection in class list                Object[] selClas = (Object[]) classList.getSelectedValues();                for (int i = 0; i < selClas.length; i++) {                    if (selClas[i] instanceof OWLClass)                        makeChange((OWLClass) selClas[i]);                }            }            swoopModel.addUncommittedChanges(changes);            changes = new ArrayList(); // reset it after changes have been                                       // added            // dispose();        } catch (Exception ex) {            ex.printStackTrace();        }    }    private boolean isURI(String str) {        try {            new URI(str);            return true;        } catch (Exception ex) {        }        return false;    }    /**     * Method called when the user clicks on the Add Restriction button Creates     * the OWL Restriction based on user selections and values and passes it to     * the makeChange(..) method to create the corresponding class change     */    private void addRestrictionChange() {        try {            // get appropriate OWL restriction            // get property            OWLProperty prop = null;            URI userPropURI = null;            //**********************************************            //Added for Econnections            //***********************************************            Set foreignEnt = new HashSet();            //***********************************************            String propType = "";            if (restrPropOntologyCombo.getSelectedIndex() != 0) {                prop = (OWLProperty) resPropBox.getSelectedItem();                if (prop instanceof OWLDataProperty)                    propType = "Data";                else {                    //********************************************                    //Changed for Econnections                    //*******************************************                    if (!(((OWLObjectProperty) prop).isLink()))                        propType = "Object";                    else                        propType = "Link";                }            } else {                // user-specified property name/uri                String propStr = resPropBox.getSelectedItem().toString();                propStr = propStr.replaceAll(" ","_");                if (!isURI(propStr))                    propStr = swoopModel.getSelectedOntology().getLogicalURI()                            + "#" + propStr;                userPropURI = new URI(propStr);            }                        //---------------------------------------------------            // get restriction type / name and object accordingly            OWLClass cla = null; // some/all values object rest            OWLDataRange dRan = null; // some/all values data rest            OWLIndividual ind = null; // has value object rest            OWLDataValue dVal = null; // has value data rest            int cardinality = -1;            OWLDataFactory ontDF = swoopModel.getSelectedOntology().getOWLDataFactory();                        if (resNameCombo.getSelectedIndex() >= 4) {                // get class                if (propType.equals("Data")) {                    // get data range                    // some/all values for datatype property                    String dRanStr = resDTypeBox.getSelectedItem().toString();                    if ((!isURI(dRanStr))                            || (dRanStr.indexOf("XMLSchema#") == -1)) {                        popupError("Invalid DataType Range - need XML Schema URI");                        restrClassOntologyCombo.setSelectedIndex(0);                        resClassBox.addItem("http://www.w3.org/2001/XMLSchema#");                        resClassBox.setSelectedItem("http://www.w3.org/2001/XMLSchema#");                        return;                    }                    URI dataURI = new URI(dRanStr);                    dRan = ontDF.getOWLConcreteDataType(dataURI);                } else {                    // get class                    if (restrClassOntologyCombo.getSelectedIndex() != 0) {

⌨️ 快捷键说明

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