You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by jo...@apache.org on 2011/04/12 14:44:38 UTC
svn commit: r1091386 - in
/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor:
core/model/DotCorpusElement.java editor/AnnotationEditor.java
editor/DefaultCasDocumentProvider.java
ui/property/TypeSystemLocationPropertyPage.java
Author: joern
Date: Tue Apr 12 12:44:37 2011
New Revision: 1091386
URL: http://svn.apache.org/viewvc?rev=1091386&view=rev
Log:
UIMA-2122 Added support to configure the default type system location
Added:
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/TypeSystemLocationPropertyPage.java (with props)
Modified:
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/core/model/DotCorpusElement.java
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DefaultCasDocumentProvider.java
Modified: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/core/model/DotCorpusElement.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/core/model/DotCorpusElement.java?rev=1091386&r1=1091385&r2=1091386&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/core/model/DotCorpusElement.java (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/core/model/DotCorpusElement.java Tue Apr 12 12:44:37 2011
@@ -32,17 +32,20 @@ import org.apache.uima.caseditor.core.mo
import org.apache.uima.caseditor.core.model.dotcorpus.DotCorpusSerializer;
import org.apache.uima.caseditor.core.util.MarkerUtil;
import org.apache.uima.caseditor.editor.AnnotationStyle;
+import org.apache.uima.caseditor.ui.property.TypeSystemLocationPropertyPage;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.QualifiedName;
/**
* The <code>DotCorpus</code> is responsible to load/store the project dependent configuration. It
* has several methods to set and retrieve configuration parameters.
*/
public class DotCorpusElement extends AbstractNlpElement {
+
private DotCorpus mDotCorpus;
private IFile mResource;
@@ -70,14 +73,23 @@ public class DotCorpusElement extends Ab
* @return - type system file name or null if no set
*/
public IFile getTypeSystemFile() {
- IFile result;
-
- if (mDotCorpus.getTypeSystemFileName() != null) {
- result = getFile(mDotCorpus.getTypeSystemFileName());
- } else {
- result = null;
+
+ // Get from project property
+ IFile result = TypeSystemLocationPropertyPage.getTypeSystemLocation(mNlpProject.getProject());
+
+ // Migration:
+ // If not there it might be the first run or type system is not set
+ // Try to get it from the dot corpus file, if not set that will also return null
+ if (result == null) {
+ if (mDotCorpus.getTypeSystemFileName() != null) {
+ result = getFile(mDotCorpus.getTypeSystemFileName());
+ }
+
+ // Set it as a project property
+ if (result != null)
+ TypeSystemLocationPropertyPage.setTypeSystemLocation(mNlpProject.getProject(), result.getFullPath().toString());
}
-
+
return result;
}
@@ -98,7 +110,22 @@ public class DotCorpusElement extends Ab
* type system file name
*/
public void setTypeSystemFilename(String filename) {
- mDotCorpus.setTypeSystemFilename(filename);
+
+ if (filename != null) {
+ // Make path absolute
+ IFile tsFile = mNlpProject.getProject().getFile(filename);
+
+ // Write into project property!
+ TypeSystemLocationPropertyPage.setTypeSystemLocation(mNlpProject.getProject(), tsFile.getFullPath().toString());
+
+ // Write type system location into dot corpus for backward compatibility
+ // Might not be needed but is safer!
+ mDotCorpus.setTypeSystemFilename(tsFile.getFullPath().toString());
+ }
+ else {
+ TypeSystemLocationPropertyPage.setTypeSystemLocation(mNlpProject.getProject(), "");
+ mDotCorpus.setTypeSystemFilename(null);
+ }
}
/**
Modified: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java?rev=1091386&r1=1091385&r2=1091386&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/AnnotationEditor.java Tue Apr 12 12:44:37 2011
@@ -1514,7 +1514,7 @@ public final class AnnotationEditor exte
FileEditorInput editorInput = (FileEditorInput) getEditorInput();
provider.setTypeSystem(editorInput.getFile().getFullPath().toPortableString(),
- resource.getFullPath().toPortableString());
+ resource.getFullPath().toString());
// Now set the input again to open the editor with the
// specified type system
Modified: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DefaultCasDocumentProvider.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DefaultCasDocumentProvider.java?rev=1091386&r1=1091385&r2=1091386&view=diff
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DefaultCasDocumentProvider.java (original)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/editor/DefaultCasDocumentProvider.java Tue Apr 12 12:44:37 2011
@@ -36,6 +36,7 @@ import org.apache.uima.caseditor.core.mo
import org.apache.uima.caseditor.core.model.INlpElement;
import org.apache.uima.caseditor.core.model.dotcorpus.DotCorpus;
import org.apache.uima.caseditor.core.model.dotcorpus.DotCorpusSerializer;
+import org.apache.uima.caseditor.ui.property.TypeSystemLocationPropertyPage;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
@@ -123,28 +124,21 @@ public class DefaultCasDocumentProvider
else {
// Try to find a type system for the CAS file
+ // TODO: Change to only use full path
+ IFile typeSystemFile = null;
// First check if a type system is already known or was
// set by the editor for this specific CAS
String typeSystemFileString = documentToTypeSystemMap.get(casFile.getFullPath().toPortableString());
- // If non was found, use the default name!
- if (typeSystemFileString == null)
- typeSystemFileString = "TypeSystem.xml";
-
- // TODO: Change to only use full path
- IFile typeSystemFile = null;
-
- IResource typeSystemResource = ResourcesPlugin.getWorkspace().getRoot().
- findMember(new Path(typeSystemFileString));
-
- if (typeSystemResource instanceof IFile)
- typeSystemFile = (IFile) typeSystemResource;
+ if (typeSystemFileString != null)
+ typeSystemFile = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(typeSystemFileString));
+ // If non was found get it from project
if (typeSystemFile == null)
- typeSystemFile = casFile.getProject().getFile(typeSystemFileString);
+ typeSystemFile = TypeSystemLocationPropertyPage.getTypeSystemLocation(casFile.getProject());
- if (typeSystemFile.exists()) {
+ if (typeSystemFile != null && typeSystemFile.exists()) {
// Try to load a style file for the type system
// Should be named: ts file name, prefixed with .style-
@@ -244,9 +238,17 @@ public class DefaultCasDocumentProvider
return document;
}
else {
- IStatus status = new Status(IStatus.ERROR, "org.apache.uima.dev", 12,
- "Cannot find type system!\nPlease place a valid type system in this path:\n" +
- typeSystemFile.getLocation().toOSString(), null);
+
+ String message = null;
+
+ if (typeSystemFile != null) {
+ message = "Cannot find type system!\nPlease place a valid type system in this path:\n" +
+ typeSystemFile.getFullPath().toString();
+ }
+ else
+ message = "Type system is not set, please choose a type system to open the CAS.";
+
+ IStatus status = new Status(IStatus.ERROR, "org.apache.uima.dev", 12, message, null);
elementErrorStatus.put(element, status);
}
Added: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/TypeSystemLocationPropertyPage.java
URL: http://svn.apache.org/viewvc/uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/TypeSystemLocationPropertyPage.java?rev=1091386&view=auto
==============================================================================
--- uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/TypeSystemLocationPropertyPage.java (added)
+++ uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/TypeSystemLocationPropertyPage.java Tue Apr 12 12:44:37 2011
@@ -0,0 +1,212 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.uima.caseditor.ui.property;
+
+import org.apache.uima.caseditor.CasEditorPlugin;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.dialogs.ElementTreeSelectionDialog;
+import org.eclipse.ui.dialogs.PropertyPage;
+import org.eclipse.ui.model.WorkbenchContentProvider;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+
+/**
+ * Type System Property Page to set the default type system location
+ * of a project.
+ */
+public class TypeSystemLocationPropertyPage extends PropertyPage {
+
+ public final static String TYPE_SYSTEM_PROPERTY = "UimaCasEditorTypeSytemPathXSSSSSSS";
+
+ private static final String DEFAULT_TYPE_SYSTEM_PATH = "TypeSystem.xml";
+
+ private Text typeSystemText;
+
+
+ IProject getProject() {
+ return (IProject) getElement().getAdapter(IProject.class);
+ }
+
+ String getDefaultTypeSystemLocation() {
+
+ IProject project = getProject();
+
+ if (project != null)
+ return project.getFile(DEFAULT_TYPE_SYSTEM_PATH).getFullPath().toString();
+ else
+ return "";
+ }
+
+ protected Control createContents(Composite parent) {
+ Composite composite = new Composite(parent, SWT.NONE);
+ GridLayout layout = new GridLayout();
+ layout.numColumns = 2;
+ composite.setLayout(layout);
+
+ GridData data = new GridData();
+ data.verticalAlignment = GridData.FILL;
+ data.horizontalAlignment = GridData.FILL;
+ composite.setLayoutData(data);
+
+ Label instructions = new Label(composite, SWT.WRAP);
+ instructions.setText("Select the default type system which is used to open CASes:");
+ GridData gd = new GridData(GridData.FILL_HORIZONTAL);
+ gd.horizontalSpan = 2;
+ gd.grabExcessHorizontalSpace = true;
+ instructions.setLayoutData(gd);
+
+ typeSystemText = new Text(composite,SWT.BORDER);
+ gd = new GridData(GridData.FILL_HORIZONTAL);
+ typeSystemText.setLayoutData(gd);
+
+ try {
+ String typeSystemPath = ((IResource) getElement()).getPersistentProperty(new QualifiedName("",
+ TYPE_SYSTEM_PROPERTY));
+ typeSystemText.setText((typeSystemPath != null) ? typeSystemPath : getDefaultTypeSystemLocation());
+ } catch (CoreException e) {
+ typeSystemText.setText(DEFAULT_TYPE_SYSTEM_PATH);
+ }
+
+ Button browseButton = new Button(composite, SWT.PUSH);
+ browseButton.setText("Browse ...");
+ browseButton.addSelectionListener(new SelectionAdapter() {
+ public void widgetSelected(SelectionEvent e) {
+ ElementTreeSelectionDialog dialog = new ElementTreeSelectionDialog(getShell(),
+ new WorkbenchLabelProvider(), new WorkbenchContentProvider());
+ dialog.setTitle("Select descriptor");
+ dialog.setMessage("Select descriptor");
+ dialog.setInput(ResourcesPlugin.getWorkspace().getRoot());
+ dialog.setInitialSelection(ResourcesPlugin.getWorkspace().getRoot().
+ findMember(typeSystemText.getText()));
+ if (dialog.open() == IDialogConstants.OK_ID) {
+ IResource resource = (IResource) dialog.getFirstResult();
+ if (resource != null) {
+ String fileLoc = resource.getFullPath().toString();
+ typeSystemText.setText(fileLoc);
+ }
+ }
+ }
+ });
+
+ return composite;
+ }
+
+ protected void performDefaults() {
+ typeSystemText.setText(getDefaultTypeSystemLocation());
+ }
+
+ @Override
+ public boolean isValid() {
+
+ IProject project = getProject();
+
+ if (project != null) {
+ try {
+ if (typeSystemText.getText().length() > 0) {
+ project.getFile(typeSystemText.getText());
+ }
+ return true;
+ }
+ catch (IllegalArgumentException e) {
+ return false;
+ }
+ }
+
+ return false;
+ }
+
+ public boolean performOk() {
+
+ // have check, so performOk is only done when ts file is a valid file string
+
+ // store the value in the owner text field
+ try {
+ ((IResource) getElement()).setPersistentProperty(
+ new QualifiedName("", TYPE_SYSTEM_PROPERTY), typeSystemText.getText());
+ } catch (CoreException e) {
+ return false;
+ }
+ return true;
+ }
+
+ /**
+ * Retrieves the type system or null if its not set!
+ *
+ * @param project
+ * @return
+ */
+ public static IFile getTypeSystemLocation(IProject project) {
+
+ IFile defaultTypeSystemFile = project.getFile(DEFAULT_TYPE_SYSTEM_PATH);
+
+ String typeSystemLocation;
+ try {
+ typeSystemLocation = project.getPersistentProperty(new QualifiedName("", TYPE_SYSTEM_PROPERTY));
+ } catch (CoreException e) {
+ typeSystemLocation = null;
+ }
+
+ IFile typeSystemFile = null;
+
+ // Type system location is null when it was never set it anyway,
+ if (typeSystemLocation != null) {
+
+ if (typeSystemLocation.length() > 0) {
+ IResource potentialTypeSystemResource = ResourcesPlugin.getWorkspace().getRoot().findMember(typeSystemLocation);
+ if (potentialTypeSystemResource instanceof IFile)
+ typeSystemFile = (IFile) potentialTypeSystemResource;
+ }
+ // Empty string means user does not want a type system to be set
+ else {
+ return null;
+ }
+ }
+
+ if (typeSystemFile == null) {
+ typeSystemFile = defaultTypeSystemFile;
+ }
+
+ return typeSystemFile;
+ }
+
+ public static void setTypeSystemLocation(IProject project, String typeSystemLocation) {
+
+ try {
+ project.setPersistentProperty(new QualifiedName("", TYPE_SYSTEM_PROPERTY), typeSystemLocation);
+ } catch (CoreException e) {
+ CasEditorPlugin.log(e);
+ }
+ }
+}
Propchange: uima/uimaj/trunk/uimaj-ep-cas-editor/src/main/java/org/apache/uima/caseditor/ui/property/TypeSystemLocationPropertyPage.java
------------------------------------------------------------------------------
svn:mime-type = text/plain