All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.protege.editor.owl.ui.editor.OWLClassExpressionExpressionEditor Maven / Gradle / Ivy

package org.protege.editor.owl.ui.editor;

import org.protege.editor.core.ui.util.InputVerificationStatusChangedListener;
import org.protege.editor.owl.OWLEditorKit;
import org.protege.editor.owl.model.cache.OWLExpressionUserCache;
import org.protege.editor.owl.ui.clsdescriptioneditor.ExpressionEditor;
import org.protege.editor.owl.ui.clsdescriptioneditor.OWLExpressionChecker;
import org.semanticweb.owlapi.model.OWLClassExpression;
import org.semanticweb.owlapi.model.OWLException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.net.URI;
import java.util.Collections;
import java.util.Set;
/*
* Copyright (C) 2007, University of Manchester
*
*
*/

/**
 * Author: drummond
* http://www.cs.man.ac.uk/~drummond/

* The University Of Manchester
* Bio Health Informatics Group
* Date: Feb 26, 2009

*/ public class OWLClassExpressionExpressionEditor extends AbstractOWLClassExpressionEditor{ private static final Logger logger = LoggerFactory.getLogger(OWLClassExpressionExpressionEditor.class); private static final String CLASS_EXPRESSION_SYNTAX_URL = "http://protegeproject.github.io/protege/class-expression-syntax"; private ExpressionEditor editor; private JPanel editorPanel = new JPanel(new BorderLayout(3, 3)); public void initialise() throws Exception { final OWLEditorKit eKit = getOWLEditorKit(); final OWLExpressionChecker checker = eKit.getModelManager().getOWLExpressionCheckerFactory().getOWLClassExpressionChecker(); editor = new ExpressionEditor<>(eKit, checker); JScrollPane sp = new JScrollPane(editor); editorPanel.add(sp); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEFT)); editorPanel.add(buttonPanel, BorderLayout.SOUTH); JButton helpButton = new JButton("Help..."); buttonPanel.add(helpButton); helpButton.addActionListener(e -> showClassExpressionSyntaxHelp()); } private void showClassExpressionSyntaxHelp() { try { Desktop.getDesktop().browse(URI.create(CLASS_EXPRESSION_SYNTAX_URL)); } catch (IOException ex) { logger.warn("An error occurred when attempting to display the Class Expression documentation: {}", ex.getMessage(), ex); } } public JComponent getComponent() { return editorPanel; } public boolean isValidInput() { return editor.isWellFormed(); } public boolean setDescription(OWLClassExpression description) { editor.setExpressionObject(description); return true; } public Set getClassExpressions() { try { if (editor.isWellFormed()) { OWLClassExpression owlDescription = editor.createObject(); OWLExpressionUserCache.getInstance(getOWLEditorKit().getModelManager()).add(owlDescription, editor.getText()); return Collections.singleton(owlDescription); } else { return null; } } catch (OWLException e) { return null; } } public void addStatusChangedListener(InputVerificationStatusChangedListener l) { editor.addStatusChangedListener(l); } public void removeStatusChangedListener(InputVerificationStatusChangedListener l) { editor.removeStatusChangedListener(l); } public void dispose() throws Exception { // surely ExpressionEditor should be disposable? } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy