You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by sc...@apache.org on 2007/11/28 20:10:21 UTC
svn commit: r599098 [2/3] - in
/incubator/uima/uimaj/trunk/uimaj-ep-configurator: ./ META-INF/ schema/
src/main/java/org/apache/uima/taeconfigurator/
src/main/java/org/apache/uima/taeconfigurator/editors/
src/main/java/org/apache/uima/taeconfigurator/e...
Modified: incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/MultiPageEditor.java
URL: http://svn.apache.org/viewvc/incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/MultiPageEditor.java?rev=599098&r1=599097&r2=599098&view=diff
==============================================================================
--- incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/MultiPageEditor.java (original)
+++ incubator/uima/uimaj/trunk/uimaj-ep-configurator/src/main/java/org/apache/uima/taeconfigurator/editors/MultiPageEditor.java Wed Nov 28 11:10:20 2007
@@ -1,2737 +1,2938 @@
-/*
- * 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.taeconfigurator.editors;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.PrintStream;
-import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.net.URLClassLoader;
-import java.text.MessageFormat;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Properties;
-import java.util.Set;
-import java.util.TreeMap;
-import java.util.TreeSet;
-import java.util.Vector;
-
-import org.apache.uima.UIMAFramework;
-import org.apache.uima.analysis_engine.AnalysisEngineDescription;
-import org.apache.uima.analysis_engine.TypeOrFeature;
-import org.apache.uima.analysis_engine.impl.AnalysisEngineDescription_impl;
-import org.apache.uima.analysis_engine.metadata.AnalysisEngineMetaData;
-import org.apache.uima.analysis_engine.metadata.FlowControllerDeclaration;
-import org.apache.uima.cas.CAS;
-import org.apache.uima.cas.impl.CASImpl;
-import org.apache.uima.collection.CasConsumerDescription;
-import org.apache.uima.collection.CasInitializerDescription;
-import org.apache.uima.collection.CollectionReaderDescription;
-import org.apache.uima.flow.FlowControllerDescription;
-import org.apache.uima.jcas.jcasgenp.MergerImpl;
-import org.apache.uima.resource.ResourceCreationSpecifier;
-import org.apache.uima.resource.ResourceInitializationException;
-import org.apache.uima.resource.ResourceManager;
-import org.apache.uima.resource.ResourceServiceSpecifier;
-import org.apache.uima.resource.ResourceSpecifier;
-import org.apache.uima.resource.metadata.Capability;
-import org.apache.uima.resource.metadata.FsIndexCollection;
-import org.apache.uima.resource.metadata.Import;
-import org.apache.uima.resource.metadata.MetaDataObject;
-import org.apache.uima.resource.metadata.ProcessingResourceMetaData;
-import org.apache.uima.resource.metadata.ResourceManagerConfiguration;
-import org.apache.uima.resource.metadata.ResourceMetaData;
-import org.apache.uima.resource.metadata.TypeDescription;
-import org.apache.uima.resource.metadata.TypePriorities;
-import org.apache.uima.resource.metadata.TypePriorityList;
-import org.apache.uima.resource.metadata.TypeSystemDescription;
-import org.apache.uima.taeconfigurator.CDEpropertyPage;
-import org.apache.uima.taeconfigurator.InternalErrorCDE;
-import org.apache.uima.taeconfigurator.Messages;
-import org.apache.uima.taeconfigurator.TAEConfiguratorPlugin;
-import org.apache.uima.taeconfigurator.editors.ui.AbstractSection;
-import org.apache.uima.taeconfigurator.editors.ui.AggregatePage;
-import org.apache.uima.taeconfigurator.editors.ui.CapabilityPage;
-import org.apache.uima.taeconfigurator.editors.ui.HeaderPage;
-import org.apache.uima.taeconfigurator.editors.ui.IndexesPage;
-import org.apache.uima.taeconfigurator.editors.ui.OverviewPage;
-import org.apache.uima.taeconfigurator.editors.ui.ParameterPage;
-import org.apache.uima.taeconfigurator.editors.ui.ResourcesPage;
-import org.apache.uima.taeconfigurator.editors.ui.SettingsPage;
-import org.apache.uima.taeconfigurator.editors.ui.TypePage;
-import org.apache.uima.taeconfigurator.editors.ui.Utility;
-import org.apache.uima.taeconfigurator.editors.xml.XMLEditor;
-import org.apache.uima.taeconfigurator.files.ContextForPartDialog;
-import org.apache.uima.taeconfigurator.model.AllTypes;
-import org.apache.uima.taeconfigurator.model.DefinedTypesWithSupers;
-import org.apache.uima.taeconfigurator.model.DescriptorTCAS;
-import org.apache.uima.tools.jcasgen.IError;
-import org.apache.uima.tools.jcasgen.Jg;
-import org.apache.uima.util.CasCreationUtils;
-import org.apache.uima.util.InvalidXMLException;
-import org.apache.uima.util.Level;
-import org.apache.uima.util.Logger;
-import org.apache.uima.util.XMLInputSource;
-import org.apache.uima.util.XMLSerializer;
-import org.apache.uima.util.XMLizable;
-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.resources.IWorkspace;
-import org.eclipse.core.resources.IWorkspaceRunnable;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.core.runtime.QualifiedName;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.search.IJavaSearchScope;
-import org.eclipse.jdt.core.search.SearchEngine;
-import org.eclipse.jdt.launching.JavaRuntime;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.window.Window;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Color;
-import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Shell;
-import org.eclipse.ui.IEditorInput;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.IEditorSite;
-import org.eclipse.ui.IFileEditorInput;
-import org.eclipse.ui.ISaveablePart;
-import org.eclipse.ui.IWorkbenchPage;
-import org.eclipse.ui.PartInitException;
-import org.eclipse.ui.PlatformUI;
-import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.forms.widgets.FormToolkit;
-import org.eclipse.ui.part.FileEditorInput;
-import org.eclipse.ui.texteditor.ITextEditor;
-import org.xml.sax.ContentHandler;
-import org.xml.sax.SAXException;
-
-/**
- * Main class implementing the multi page editor. In Eclipse 3, we extend FormEditor, which extends
- * in turn MultiPageEditorPart.
- *
- * Life cycle: Create: An instance of this class is created each time the editor is started on a new
- * resource. Base multipage editor createPartControl calls createPages; FormEditor's impl of
- * createPages calls createToolkit, then calls addPages. FormEditor has field holding the toolkit
- * This class overrides createToolkit to re-use the colors in the plugin. * Dispose: dispose is
- * called. FormEditor impl of dispose disposes of the toolkit.
- *
- * Superclass (FormEditor) holds vector of pages toolkit (disposed of in FormEditor dispose method)
- * SuperSuperclass (MultiPageEditorPart) holds array of editors (we only have 1 "editor" - the xml
- * source editor - the rest are views into that model / data).
- *
- * Stale = model (on disk, saved) is ahead of widgets Dirty = widgets are ahead of model <<< NOT
- * USED HERE
- *
- * Each page of the multipage editor has its own class. ownclass -> HeaderPage -> FormPage (impl
- * IFormPage) has instance of PageForm -> ManagedForm ManagedForm (impl IManagedForm): has instance
- * of ScrolledForm has subparts (IFormPart - which live on the scrolled form) A part can be a
- * section. A part can implement IPartSelectionListener to get selectionChanged(IFormPart,
- * ISelection) calls. initialize() call propagated to all parts. dispose() call propagated to all
- * parts. refresh() propagated to all parts (if part.isStale()) (Not Used) commit() propagated to
- * all parts (if part.isDirty()) setInput() propagated to all parts setFocus() propagated to 1st
- * part (not used) isDirty() propagated to all parts, is true if any are true isStale() propagated
- * to all parts, is true if any are true reflow() delegated to the contained ScrolledForm (not used)
- * fireSelectionChanged(IFormPart, ISelection) - can be used to notify other parts that implement
- * IPartSelectionListener about selection changes
- *
- * Each page has one or more sections. sectionSpecific -> (AbstractTableSection) -> AbstractSection ->
- * SectionPart -> AbstractFormPart (impl IFormPart, see above)
- *
- * AbstractFormPart holds back ref to managed form, a dirty and stale bit. Stale = model is ahead of
- * widgets (Not used) Dirty = widgets are ahead of model Stale brought into sync by 'refresh'
- * method. Part notifies containing ManagedForm when Stale/Dirty changes in the part; Part
- * responsible for removing listeners from event providers. IFormPart can receive form input
- * SectionPart adds listeners for expansionStateChang(ed)(ing) expansionStateChanged calls reflow on
- * wrapped form Note: the forms framework Dirty mechanism and the "commit" methods are not used. In
- * its place, the handlers directly update the model, rather than marking Dirty and letting someone
- * call commit.
- */
-public class MultiPageEditor extends FormEditor {
-
- // ******************************
- // * Tuning Parameters
- public final int INITIAL_SIZE_TYPE_COLLECTIONS = 20;
-
- public final int INITIAL_SIZE_FEATURE_COLLECTIONS = 40;
-
- // ******************************
-
- // ***********************************************************
- // M O D E L
- // the following are only populated based on what type
- // of descriptor is being edited
- protected AnalysisEngineDescription aeDescription = null;
-
- private TypeSystemDescription typeSystemDescription = null;
-
- private TypeSystemDescription mergedTypeSystemDescription = null;
-
- private Map mergedTypesAddingFeatures = new TreeMap();
-
- private TypeSystemDescription importedTypeSystemDescription = null;
-
- /**
- * Key = unique ID of included AE in aggregate Value = AnalysisEngineSpecification or URISpecifier
- * if remote This value is obtained from aeDescription.getDelegateAnalysisEngineSpecifiers() for
- * aggregates, and is cached so we don't need to repeatedly resolve it, with checks for invalid
- * xml exceptions.
- */
- private Map resolvedDelegates = new HashMap();
-
- // fully resolved (imports) and merged index collection
- // resolve with mergeDelegateAnalysisEngineFsIndexCollections
- // (This works also for primitives)
- private FsIndexCollection mergedFsIndexCollection;
-
- private FsIndexCollection importedFsIndexCollection;
-
- // fully resolved (imports) and merged type priorities
- // resolve with mergeDelegateAnalysisEngineTypePriorities
- // (This works also for primitives)
- // This collects all the type priority lists into one list, after
- // resolving imports.
- private TypePriorities mergedTypePriorities;
-
- private TypePriorities importedTypePriorities;
-
- // fully resolved (imports) ResourceManagerConfiguration
- // This collects all the External Resources and bindings into 2 list,
- // resolving imports. The resulting list may have
- // overridden bindings
- // unused external resources (not bound)
- private ResourceManagerConfiguration resolvedExternalResourcesAndBindings;
-
- // private ResourceManagerConfiguration importedExternalResourcesAndBindings;
-
- private FlowControllerDeclaration resolvedFlowControllerDeclaration;
-
- private CollectionReaderDescription collectionReaderDescription;
-
- private CasInitializerDescription casInitializerDescription;
-
- private CasConsumerDescription casConsumerDescription;
-
- private FlowControllerDescription flowControllerDescription;
-
- // values computed when first needed
- // all use common markStale()
- public DescriptorTCAS descriptorCAS;
-
- public AllTypes allTypes;
-
- public DefinedTypesWithSupers definedTypesWithSupers;
-
- // ****************************************
- // * Model parts not part of the descriptor
- // ****************************************
- private IFile file; // file being edited
-
- private IFile fileNeedingContext;
-
- // ***********************************************************
- // End of M O D E L
- // ***********************************************************
-
- /*
- * Each page is an instance of a particular class. These instances are created each time a new
- * instance of the editor opens.
- */
-
- protected int sourceIndex = -1;
-
- protected int overviewIndex = -1;
-
- private int aggregateIndex = -1;
-
- private int parameterIndex = -1;
-
- private int settingsIndex = -1;
-
- protected int typeIndex = -1;
-
- protected int capabilityIndex = -1;
-
- protected int indexesIndex = -1;
-
- protected int resourcesIndex = -1;
-
- protected OverviewPage overviewPage = null;
-
- private AggregatePage aggregatePage = null;
-
- private ParameterPage parameterPage = null;
-
- private SettingsPage settingsPage = null;
-
- protected TypePage typePage = null;
-
- protected CapabilityPage capabilityPage = null;
-
- protected IndexesPage indexesPage = null;
-
- protected ResourcesPage resourcesPage = null;
-
- protected XMLEditor sourceTextEditor;
-
+/*
+ * 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.taeconfigurator.editors;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintStream;
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.TreeMap;
+import java.util.TreeSet;
+import java.util.Vector;
+
+import org.apache.uima.UIMAFramework;
+import org.apache.uima.analysis_engine.AnalysisEngineDescription;
+import org.apache.uima.analysis_engine.TypeOrFeature;
+import org.apache.uima.analysis_engine.impl.AnalysisEngineDescription_impl;
+import org.apache.uima.analysis_engine.metadata.AnalysisEngineMetaData;
+import org.apache.uima.analysis_engine.metadata.FlowControllerDeclaration;
+import org.apache.uima.cas.CAS;
+import org.apache.uima.cas.impl.CASImpl;
+import org.apache.uima.collection.CasConsumerDescription;
+import org.apache.uima.collection.CasInitializerDescription;
+import org.apache.uima.collection.CollectionReaderDescription;
+import org.apache.uima.flow.FlowControllerDescription;
+import org.apache.uima.jcas.jcasgenp.MergerImpl;
+import org.apache.uima.resource.ResourceCreationSpecifier;
+import org.apache.uima.resource.ResourceInitializationException;
+import org.apache.uima.resource.ResourceManager;
+import org.apache.uima.resource.ResourceServiceSpecifier;
+import org.apache.uima.resource.ResourceSpecifier;
+import org.apache.uima.resource.metadata.Capability;
+import org.apache.uima.resource.metadata.FsIndexCollection;
+import org.apache.uima.resource.metadata.Import;
+import org.apache.uima.resource.metadata.MetaDataObject;
+import org.apache.uima.resource.metadata.ProcessingResourceMetaData;
+import org.apache.uima.resource.metadata.ResourceManagerConfiguration;
+import org.apache.uima.resource.metadata.ResourceMetaData;
+import org.apache.uima.resource.metadata.TypeDescription;
+import org.apache.uima.resource.metadata.TypePriorities;
+import org.apache.uima.resource.metadata.TypePriorityList;
+import org.apache.uima.resource.metadata.TypeSystemDescription;
+import org.apache.uima.taeconfigurator.CDEpropertyPage;
+import org.apache.uima.taeconfigurator.InternalErrorCDE;
+import org.apache.uima.taeconfigurator.Messages;
+import org.apache.uima.taeconfigurator.TAEConfiguratorPlugin;
+import org.apache.uima.taeconfigurator.editors.point.IUimaEditorExtension;
+import org.apache.uima.taeconfigurator.editors.point.IUimaMultiPageEditor;
+import org.apache.uima.taeconfigurator.editors.ui.AbstractSection;
+import org.apache.uima.taeconfigurator.editors.ui.AggregatePage;
+import org.apache.uima.taeconfigurator.editors.ui.CapabilityPage;
+import org.apache.uima.taeconfigurator.editors.ui.HeaderPage;
+import org.apache.uima.taeconfigurator.editors.ui.IndexesPage;
+import org.apache.uima.taeconfigurator.editors.ui.OverviewPage;
+import org.apache.uima.taeconfigurator.editors.ui.ParameterPage;
+import org.apache.uima.taeconfigurator.editors.ui.ResourcesPage;
+import org.apache.uima.taeconfigurator.editors.ui.SettingsPage;
+import org.apache.uima.taeconfigurator.editors.ui.TypePage;
+import org.apache.uima.taeconfigurator.editors.ui.Utility;
+import org.apache.uima.taeconfigurator.editors.xml.XMLEditor;
+import org.apache.uima.taeconfigurator.files.ContextForPartDialog;
+import org.apache.uima.taeconfigurator.model.AllTypes;
+import org.apache.uima.taeconfigurator.model.DefinedTypesWithSupers;
+import org.apache.uima.taeconfigurator.model.DescriptorTCAS;
+import org.apache.uima.tools.jcasgen.IError;
+import org.apache.uima.tools.jcasgen.Jg;
+import org.apache.uima.util.CasCreationUtils;
+import org.apache.uima.util.InvalidXMLException;
+import org.apache.uima.util.Level;
+import org.apache.uima.util.Logger;
+import org.apache.uima.util.XMLInputSource;
+import org.apache.uima.util.XMLSerializer;
+import org.apache.uima.util.XMLizable;
+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.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.core.runtime.IExtension;
+import org.eclipse.core.runtime.IExtensionPoint;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.QualifiedName;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.search.IJavaSearchScope;
+import org.eclipse.jdt.core.search.SearchEngine;
+import org.eclipse.jdt.launching.JavaRuntime;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IEditorInput;
+import org.eclipse.ui.IEditorPart;
+import org.eclipse.ui.IEditorSite;
+import org.eclipse.ui.IFileEditorInput;
+import org.eclipse.ui.ISaveablePart;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.part.FileEditorInput;
+import org.eclipse.ui.texteditor.ITextEditor;
+import org.osgi.framework.Bundle;
+import org.xml.sax.ContentHandler;
+import org.xml.sax.SAXException;
+
+/**
+ * Main class implementing the multi page editor. In Eclipse 3, we extend FormEditor, which extends
+ * in turn MultiPageEditorPart.
+ *
+ * Life cycle: Create: An instance of this class is created each time the editor is started on a new
+ * resource. Base multipage editor createPartControl calls createPages; FormEditor's impl of
+ * createPages calls createToolkit, then calls addPages. FormEditor has field holding the toolkit
+ * This class overrides createToolkit to re-use the colors in the plugin. * Dispose: dispose is
+ * called. FormEditor impl of dispose disposes of the toolkit.
+ *
+ * Superclass (FormEditor) holds vector of pages toolkit (disposed of in FormEditor dispose method)
+ * SuperSuperclass (MultiPageEditorPart) holds array of editors (we only have 1 "editor" - the xml
+ * source editor - the rest are views into that model / data).
+ *
+ * Stale = model (on disk, saved) is ahead of widgets Dirty = widgets are ahead of model <<< NOT
+ * USED HERE
+ *
+ * Each page of the multipage editor has its own class. ownclass -> HeaderPage -> FormPage (impl
+ * IFormPage) has instance of PageForm -> ManagedForm ManagedForm (impl IManagedForm): has instance
+ * of ScrolledForm has subparts (IFormPart - which live on the scrolled form) A part can be a
+ * section. A part can implement IPartSelectionListener to get selectionChanged(IFormPart,
+ * ISelection) calls. initialize() call propagated to all parts. dispose() call propagated to all
+ * parts. refresh() propagated to all parts (if part.isStale()) (Not Used) commit() propagated to
+ * all parts (if part.isDirty()) setInput() propagated to all parts setFocus() propagated to 1st
+ * part (not used) isDirty() propagated to all parts, is true if any are true isStale() propagated
+ * to all parts, is true if any are true reflow() delegated to the contained ScrolledForm (not used)
+ * fireSelectionChanged(IFormPart, ISelection) - can be used to notify other parts that implement
+ * IPartSelectionListener about selection changes
+ *
+ * Each page has one or more sections. sectionSpecific -> (AbstractTableSection) -> AbstractSection ->
+ * SectionPart -> AbstractFormPart (impl IFormPart, see above)
+ *
+ * AbstractFormPart holds back ref to managed form, a dirty and stale bit. Stale = model is ahead of
+ * widgets (Not used) Dirty = widgets are ahead of model Stale brought into sync by 'refresh'
+ * method. Part notifies containing ManagedForm when Stale/Dirty changes in the part; Part
+ * responsible for removing listeners from event providers. IFormPart can receive form input
+ * SectionPart adds listeners for expansionStateChang(ed)(ing) expansionStateChanged calls reflow on
+ * wrapped form Note: the forms framework Dirty mechanism and the "commit" methods are not used. In
+ * its place, the handlers directly update the model, rather than marking Dirty and letting someone
+ * call commit.
+ */
+public class MultiPageEditor extends FormEditor implements IUimaMultiPageEditor {
+
+ // ******************************
+ // * Tuning Parameters
+ public final int INITIAL_SIZE_TYPE_COLLECTIONS = 20;
+
+ public final int INITIAL_SIZE_FEATURE_COLLECTIONS = 40;
+
+ // ******************************
+
+ // ***********************************************************
+ // M O D E L
+ // the following are only populated based on what type
+ // of descriptor is being edited
+ private AnalysisEngineDescription aeDescription = null;
+
+ private TypeSystemDescription typeSystemDescription = null;
+
+ private TypeSystemDescription mergedTypeSystemDescription = null;
+
+ private Map mergedTypesAddingFeatures = new TreeMap();
+
+ private TypeSystemDescription importedTypeSystemDescription = null;
+
+ /**
+ * Key = unique ID of included AE in aggregate Value = AnalysisEngineSpecification or URISpecifier
+ * if remote This value is obtained from aeDescription.getDelegateAnalysisEngineSpecifiers() for
+ * aggregates, and is cached so we don't need to repeatedly resolve it, with checks for invalid
+ * xml exceptions.
+ */
+ private Map resolvedDelegates = new HashMap();
+
+ // fully resolved (imports) and merged index collection
+ // resolve with mergeDelegateAnalysisEngineFsIndexCollections
+ // (This works also for primitives)
+ private FsIndexCollection mergedFsIndexCollection;
+
+ private FsIndexCollection importedFsIndexCollection;
+
+ // fully resolved (imports) and merged type priorities
+ // resolve with mergeDelegateAnalysisEngineTypePriorities
+ // (This works also for primitives)
+ // This collects all the type priority lists into one list, after
+ // resolving imports.
+ private TypePriorities mergedTypePriorities;
+
+ private TypePriorities importedTypePriorities;
+
+ // fully resolved (imports) ResourceManagerConfiguration
+ // This collects all the External Resources and bindings into 2 list,
+ // resolving imports. The resulting list may have
+ // overridden bindings
+ // unused external resources (not bound)
+ private ResourceManagerConfiguration resolvedExternalResourcesAndBindings;
+
+ // private ResourceManagerConfiguration importedExternalResourcesAndBindings;
+
+ private FlowControllerDeclaration resolvedFlowControllerDeclaration;
+
+ private CollectionReaderDescription collectionReaderDescription;
+
+ private CasInitializerDescription casInitializerDescription;
+
+ private CasConsumerDescription casConsumerDescription;
+
+ private FlowControllerDescription flowControllerDescription;
+
+ // values computed when first needed
+ // all use common markStale()
+ public DescriptorTCAS descriptorCAS;
+
+ public AllTypes allTypes;
+
+ public DefinedTypesWithSupers definedTypesWithSupers;
+
+ // ****************************************
+ // * Model parts not part of the descriptor
+ // ****************************************
+ private IFile file; // file being edited
+
+ private IFile fileNeedingContext;
+
+ // ***********************************************************
+ // End of M O D E L
+ // ***********************************************************
+
+ /*
+ * Each page is an instance of a particular class. These instances are created each time a new
+ * instance of the editor opens.
+ */
+
+ protected int sourceIndex = -1;
+
+ protected int overviewIndex = -1;
+
+ private int aggregateIndex = -1;
+
+ private int parameterIndex = -1;
+
+ private int settingsIndex = -1;
+
+ protected int typeIndex = -1;
+
+ protected int capabilityIndex = -1;
+
+ protected int indexesIndex = -1;
+
+ protected int resourcesIndex = -1;
+
+ protected OverviewPage overviewPage = null;
+
+ private AggregatePage aggregatePage = null;
+
+ private ParameterPage parameterPage = null;
+
+ private SettingsPage settingsPage = null;
+
+ protected TypePage typePage = null;
+
+ protected CapabilityPage capabilityPage = null;
+
+ protected IndexesPage indexesPage = null;
+
+ protected ResourcesPage resourcesPage = null;
+
+ protected XMLEditor sourceTextEditor;
+
private boolean m_bIsInited = false;
-
- protected boolean isBadXML = true;
-
- public boolean sourceChanged = true;
-
+
+ protected boolean isBadXML = true;
+
+ public boolean sourceChanged = true;
+
private boolean fileDirty; // can only be set dirty once inited
-
- private HashSet dirtyTypeNameHash; // for generating .java
-
- // type files upon saving (this has a problem if user edited xml
- // directly...)
-
- private int m_nSaveAsStatus = SAVE_AS_NOT_IN_PROGRESS;
-
- public static final int SAVE_AS_NOT_IN_PROGRESS = -1;
-
- public static final int SAVE_AS_STARTED = -2;
-
- public static final int SAVE_AS_CANCELLED = -3;
-
- public static final int SAVE_AS_CONFIRMED = -4;
-
- private boolean openingContext = false;
-
- private boolean isContextLoaded = false;
-
- public boolean getIsContextLoaded() {
- return isContextLoaded;
- }
-
- /**
- * Descriptor Types
- */
-
- private int descriptorType = 0;
-
- public int getDescriptorType() {
- return descriptorType;
- }
-
- public static final int DESCRIPTOR_AE = 1;
-
- public static final int DESCRIPTOR_TYPESYSTEM = 1 << 1;
-
- public static final int DESCRIPTOR_INDEX = 1 << 2;
-
- public static final int DESCRIPTOR_TYPEPRIORITY = 1 << 3;
-
- public static final int DESCRIPTOR_EXTRESANDBINDINGS = 1 << 4;
-
- public static final int DESCRIPTOR_COLLECTIONREADER = 1 << 5;
-
- public static final int DESCRIPTOR_CASINITIALIZER = 1 << 6;
-
- public static final int DESCRIPTOR_CASCONSUMER = 1 << 7;
-
- public static final int DESCRIPTOR_FLOWCONTROLLER = 1 << 8;
-
- public String descriptorTypeString(int pDescriptorType) {
- String r;
- switch (pDescriptorType) {
- case DESCRIPTOR_AE:
- r = Messages.getString("MultiPageEditor.0");break; //$NON-NLS-1$
- case DESCRIPTOR_TYPESYSTEM:
- r = Messages.getString("MultiPageEditor.1");break; //$NON-NLS-1$
- case DESCRIPTOR_INDEX:
- r = Messages.getString("MultiPageEditor.2");break; //$NON-NLS-1$
- case DESCRIPTOR_TYPEPRIORITY:
- r = Messages.getString("MultiPageEditor.3");break; //$NON-NLS-1$
- case DESCRIPTOR_EXTRESANDBINDINGS:
- r = Messages.getString("MultiPageEditor.4");break; //$NON-NLS-1$
- case DESCRIPTOR_COLLECTIONREADER:
- r = Messages.getString("MultiPageEditor.5");break; //$NON-NLS-1$
- case DESCRIPTOR_CASINITIALIZER:
- r = Messages.getString("MultiPageEditor.6");break; //$NON-NLS-1$
- case DESCRIPTOR_CASCONSUMER:
- r = Messages.getString("MultiPageEditor.7");break; //$NON-NLS-1$
- case DESCRIPTOR_FLOWCONTROLLER:
- r = "Flow Controller";
- break;
- default:
- throw new InternalErrorCDE(Messages.getString("MultiPageEditor.8")); //$NON-NLS-1$
- }
- return r + Messages.getString("MultiPageEditor.9"); //$NON-NLS-1$
- }
-
- public String descriptorTypeString() {
- return descriptorTypeString(descriptorType);
- }
-
- public boolean isAeDescriptor() {
- return 0 != (descriptorType & DESCRIPTOR_AE);
- }
-
- public boolean isTypeSystemDescriptor() {
- return 0 != (descriptorType & DESCRIPTOR_TYPESYSTEM);
- }
-
- public boolean isFsIndexCollection() {
- return 0 != (descriptorType & DESCRIPTOR_INDEX);
- }
-
- public boolean isTypePriorityDescriptor() {
- return 0 != (descriptorType & DESCRIPTOR_TYPEPRIORITY);
- }
-
- public boolean isExtResAndBindingsDescriptor() {
- return 0 != (descriptorType & DESCRIPTOR_EXTRESANDBINDINGS);
- }
-
- public boolean isCollectionReaderDescriptor() {
- return 0 != (descriptorType & DESCRIPTOR_COLLECTIONREADER);
- }
-
- public boolean isCasInitializerDescriptor() {
- return 0 != (descriptorType & DESCRIPTOR_CASINITIALIZER);
- }
-
- public boolean isCasConsumerDescriptor() {
- return 0 != (descriptorType & DESCRIPTOR_CASCONSUMER);
- }
-
- public boolean isFlowControllerDescriptor() {
- return 0 != (descriptorType & DESCRIPTOR_FLOWCONTROLLER);
- }
-
- public boolean isLocalProcessingDescriptor() {
- return 0 != (descriptorType & (DESCRIPTOR_AE | DESCRIPTOR_COLLECTIONREADER
- | DESCRIPTOR_CASINITIALIZER | DESCRIPTOR_CASCONSUMER | DESCRIPTOR_FLOWCONTROLLER));
- }
-
- public boolean isPrimitive() {
- return isLocalProcessingDescriptor() && aeDescription.isPrimitive();
- }
-
- public boolean isAggregate() {
- return isAeDescriptor() && (!aeDescription.isPrimitive());
- }
-
- private TypePriorities m_typePrioritiesBackup;
-
- private Color fadeColor;
-
- private boolean isRevertingIndex;
-
- protected boolean isPageChangeRecursion = false;
-
- public static final TypeDescription[] typeDescriptionArray0 = new TypeDescription[0];
-
- private List typeSystemsToMerge;
-
- private List typePrioritiesToMerge;
-
- private List fsIndexesToMerge;
-
- private Map failedRemotes = new TreeMap();
- private Set failedRemotesAlreadyKnown = new TreeSet();
-
- public MultiPageEditor() {
- super();
-
- // Model initialization
- fileDirty = false;
- dirtyTypeNameHash = new HashSet();
- descriptorCAS = new DescriptorTCAS(this);
- allTypes = new AllTypes(this);
- definedTypesWithSupers = new DefinedTypesWithSupers(this);
-
- // reasonable initial values
- aeDescription = UIMAFramework.getResourceSpecifierFactory().createAnalysisEngineDescription();
- typeSystemDescription = null;
- importedTypeSystemDescription = null;
- mergedTypeSystemDescription = null;
- mergedFsIndexCollection = aeDescription.getAnalysisEngineMetaData().getFsIndexCollection();
- resolvedExternalResourcesAndBindings = aeDescription.getResourceManagerConfiguration();
- resolvedFlowControllerDeclaration = aeDescription.getFlowControllerDeclaration();
- mergedTypePriorities = aeDescription.getAnalysisEngineMetaData().getTypePriorities();
- }
-
- /**
- * override the createToolkit method in FormEditor - to use a shared colors resource.
- *
- * This method is called by the FormEditor's createPages() method which will in turn call the
- * addPages method below. The toolkit ref is stored in the FormEditor object, and can be retrieved
- * by getToolkit().
- *
- */
-
- protected FormToolkit createToolkit(Display display) {
- return new FormToolkit(TAEConfiguratorPlugin.getDefault().getFormColors(display));
- }
-
- /*
- * Two forms of addPage - one for non-source-editors, and one for source-editor
- */
- protected int addPageAndSetTabTitle(HeaderPage page, String keyTabTitle) throws PartInitException {
- int pageIndex = addPage(page);
- // set the text on the tab used to select the page in the multipage editor
- setPageText(pageIndex, keyTabTitle);
- return pageIndex;
- }
-
- protected int addPageAndSetTabTitle(IEditorPart page, IEditorInput input, String keyTabTitle)
- throws PartInitException {
- int pageIndex = addPage(page, input);
- // set the text on the tab used to select the page in the multipage editor
- setPageText(pageIndex, keyTabTitle);
- return pageIndex;
- }
-
- /*
- * In general, 3 kinds of pages can be added. 1) an editor (IEditorPart, IEditorInput) 2) (lazy)
- * an IFormPage (extends IEditorPart) - has a managedForm, can wrap an editor 3) (lazy) a SWT
- * Control (Not Used)
- *
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
- */
- protected void addPages() {
- boolean allPages = isLocalProcessingDescriptor();
- try {
- overviewIndex = addPageAndSetTabTitle(overviewPage = new OverviewPage(this), Messages
- .getString("MultiPageEditor.overviewTab")); //$NON-NLS-1$
-
- if (allPages) {
- if (isAeDescriptor())
- aggregateIndex = addPageAndSetTabTitle(aggregatePage = new AggregatePage(this), Messages
- .getString("MultiPageEditor.aggregateTab")); //$NON-NLS-1$
- parameterIndex = addPageAndSetTabTitle(parameterPage = new ParameterPage(this), Messages
- .getString("MultiPageEditor.parameterTab")); //$NON-NLS-1$
- settingsIndex = addPageAndSetTabTitle(settingsPage = new SettingsPage(this), Messages
- .getString("MultiPageEditor.settingsTab")); //$NON-NLS-1$
- }
-
- if (allPages || isTypeSystemDescriptor()) {
- typeIndex = addPageAndSetTabTitle(typePage = new TypePage(this), Messages
- .getString("MultiPageEditor.typeTab")); //$NON-NLS-1$
- }
-
- if (allPages) {
- capabilityIndex = addPageAndSetTabTitle(capabilityPage = new CapabilityPage(this), Messages
- .getString("MultiPageEditor.capabilityTab")); //$NON-NLS-1$
- }
-
- if (allPages || isTypePriorityDescriptor() || isFsIndexCollection()) {
- indexesIndex = addPageAndSetTabTitle(indexesPage = new IndexesPage(this), Messages
- .getString("MultiPageEditor.indexesTab")); //$NON-NLS-1$
- }
-
- if (allPages || isExtResAndBindingsDescriptor()) {
- resourcesIndex = addPageAndSetTabTitle(resourcesPage = new ResourcesPage(this), Messages
- .getString("MultiPageEditor.resourcesTab")); //$NON-NLS-1$
- }
-
- sourceIndex = addPageAndSetTabTitle(sourceTextEditor = new XMLEditor(this), getEditorInput(),
- Messages.getString("MultiPageEditor.sourceTab")); //$NON-NLS-1$
-
- } catch (PartInitException e) {
- e.printStackTrace(); // TODO fix this
- }
- if (isBadXML) {
- pageChange(sourceIndex);
- }
- }
-
- /**
- * @param monitor
- */
- public void jcasGen(IProgressMonitor monitor) {
- if (MultiPageEditorContributor.getAutoJCasGen()) {
- doJCasGenChkSrc(monitor);
- }
- }
-
- public void doJCasGenChkSrc(IProgressMonitor monitor) {
- if (isSourceFolderValid())
- doJCasGen(monitor);
- }
-
- public boolean isSourceFolderValid() {
- IResource folder = getPrimarySourceFolder();
- if (folder == null) {
- String msg = Messages.getString("MultiPageEditor.noSrcNoJCas"); //$NON-NLS-1$
- Utility.popMessage(Messages.getString("MultiPageEditor.noSrcDir"), msg, MessageDialog.ERROR); //$NON-NLS-1$
- return false;
- }
- return true;
- }
-
- private boolean syncSourceBeforeSavingToFile() {
- boolean modelOK = true;
- if (getCurrentPage() != sourceIndex) {
- validateIndexes();
- updateSourceFromModel();
- } else { // have to check if there are dirty types
- modelOK = validateSource();
- }
- if (modelOK && isLocalProcessingDescriptor()) {
- return isValidAE(aeDescription);
- }
- return modelOK;
- }
-
- public boolean isValidAE(AnalysisEngineDescription aAe) {
- AbstractSection.setVnsHostAndPort(aAe);
- // copy Ae into real descriptors if needed
- getTrueDescriptor();
- // use clones because validation modifies (imports get imported)
- if (isCollectionReaderDescriptor()) {
- CollectionReaderDescription collRdr = (CollectionReaderDescription) collectionReaderDescription
- .clone();
- try {
- collRdr.doFullValidation(createResourceManager());
- } catch (Throwable e) { // all these are Throwable to catch errors like
- // UnsupportedClassVersionError, which happens if the annotator
- // class is compiled for Java 5.0, but the CDE is running Java 1.4.2
- Utility
- .popMessage(
- Messages.getString("MultiPageEditor.failedCollRdrValidation"), //$NON-NLS-1$
- Messages.getString("MultiPageEditor.failedCollRdrValidationMsg") + "\n" + getMessagesToRootCause(e), //$NON-NLS-1$ //$NON-NLS-2$
- MessageDialog.ERROR);
- return false;
- }
- } else if (isCasInitializerDescriptor()) {
- CasInitializerDescription casInit = (CasInitializerDescription) casInitializerDescription
- .clone();
- try {
- casInit.doFullValidation(createResourceManager());
- } catch (Throwable e) {
- Utility
- .popMessage(
- Messages.getString("MultiPageEditor.failedCasInitValidation"), //$NON-NLS-1$
- Messages.getString("MultiPageEditor.failedCasInitValidationMsg") + "\n" + getMessagesToRootCause(e), //$NON-NLS-1$ //$NON-NLS-2$
- MessageDialog.ERROR);
- return false;
- }
- } else if (isCasConsumerDescriptor()) {
- CasConsumerDescription casCons = (CasConsumerDescription) casConsumerDescription.clone();
- try {
- casCons.doFullValidation(createResourceManager());
- } catch (Throwable e) {
- Utility
- .popMessage(
- Messages.getString("MultiPageEditor.failedCasConsValidation"), //$NON-NLS-1$
- Messages.getString("MultiPageEditor.failedCasConsValidationMsg") + "\n" + getMessagesToRootCause(e), //$NON-NLS-1$ //$NON-NLS-2$
- MessageDialog.ERROR);
- return false;
- }
-
- } else if (isFlowControllerDescriptor()) {
- FlowControllerDescription fc = (FlowControllerDescription) flowControllerDescription.clone();
- try {
- fc.doFullValidation(createResourceManager());
- } catch (Throwable e) {
- Utility.popMessage("Error in Flow Controller Descriptor",
- "The Descriptor is invalid for the following reason:" + "\n"
- + getMessagesToRootCause(e), MessageDialog.ERROR);
- return false;
- }
- } else {
- AnalysisEngineDescription ae = (AnalysisEngineDescription) aAe.clone();
-
- // speedup = replace typeSystem with resolved imports version
- if (ae.isPrimitive()) {
- TypeSystemDescription tsd = getMergedTypeSystemDescription();
- if (null != tsd) {
- tsd = (TypeSystemDescription) tsd.clone();
- }
- ae.getAnalysisEngineMetaData().setTypeSystem(tsd);
- }
- ae.getAnalysisEngineMetaData().setFsIndexCollection(getMergedFsIndexCollection());
- ae.getAnalysisEngineMetaData().setTypePriorities(getMergedTypePriorities());
- try {
- ae.doFullValidation(createResourceManager());
- } catch (Throwable e) {
- Utility
- .popMessage(
- Messages.getString("MultiPageEditor.failedAeValidation"), //$NON-NLS-1$
- Messages.getString("MultiPageEditor.failedAeValidationMsg") + "\n" + getMessagesToRootCause(e), //$NON-NLS-1$ //$NON-NLS-2$
- MessageDialog.ERROR);
- return false;
- }
- }
- return true;
- }
-
- /**
- * Saves the multi-page editor's document.
- */
- public void doSave(IProgressMonitor monitor) {
- boolean modelOK = syncSourceBeforeSavingToFile();
- sourceTextEditor.doSave(monitor);
- finishSave(monitor, modelOK);
- }
-
- private void finishSave(IProgressMonitor monitor, boolean modelOK) {
- if (modelOK) {
- if (dirtyTypeNameHash.size() > 0)
- jcasGen(monitor);
- dirtyTypeNameHash.clear();
- }
- fileDirty = false;
- firePropertyChange(ISaveablePart.PROP_DIRTY);
-
- }
-
- /**
- * Saves the multi-page editor's document as another file. Updates this multi-page editor's input
- * to correspond to the nested editor's.
- *
- * This is not implemented correctly: filename isn't switched to new filename, etc.
- */
- public void doSaveAs() {
- boolean modelOK = syncSourceBeforeSavingToFile();
- setSaveAsStatus(SAVE_AS_STARTED);
- sourceTextEditor.doSaveAs();
-
- if (m_nSaveAsStatus == SAVE_AS_CANCELLED) {
- m_nSaveAsStatus = SAVE_AS_NOT_IN_PROGRESS;
- return;
- }
- // should only do if editorInput is new
- FileEditorInput newEditorInput = (FileEditorInput) sourceTextEditor.getEditorInput();
-
- // if(old)
- setInput(newEditorInput);
- firePropertyChange(PROP_INPUT);
- // setTitle(newEditorInput.getFile().getName());
- setPartName(newEditorInput.getFile().getName());
- // this next does NOT seem to change the overall page title
-
- firePropertyChange(PROP_TITLE);
- finishSave(null, modelOK);
- }
-
- public boolean isDirty() {
- return fileDirty;
- }
-
- public boolean isSaveOnCloseNeeded() {
- return fileDirty;
- }
-
- public void setFileDirty() {
- if (m_bIsInited) {
- fileDirty = true;
- // next is key
- this.firePropertyChange(ISaveablePart.PROP_DIRTY);
- }
- }
-
- /*
- * (non-Javadoc)
- *
- * @see org.eclipse.ui.IEditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
- */
- public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException {
- XMLInputSource input;
-
- if (!(editorInput instanceof IFileEditorInput))
- throw new PartInitException(Messages.getString("MultiPageEditor.invalidInputClass")); //$NON-NLS-1$
- fileNeedingContext = file = ((IFileEditorInput) editorInput).getFile();
- String filePathName = file.getLocation().toOSString();
-
- try {
- input = new XMLInputSource(filePathName);
- } catch (IOException e) {
- String m = Messages.getFormattedString("MultiPageEditor.IOError", //$NON-NLS-1$
- new String[] { AbstractSection.maybeShortenFileName(filePathName) })
- + Messages.getString("MultiPageEditor.10") + getMessagesToRootCause(e); //$NON-NLS-1$
- // skip showing a message because the partInitException
- // shows it
- throw new PartInitException(m);
- }
-
- // leaves isBadXML set, if it can't parse but isn't throwing
- isContextLoaded = false;
- try {
- parseSource(input, filePathName);
- } catch (MultilevelCancel e) {
- throw new PartInitException("Operation Cancelled");
- }
-
- isContextLoaded = true;
-
- super.init(site, editorInput);
- setPartName(editorInput.getName());
- setContentDescription(editorInput.getName());
- // setContentDescription(1 line summary); TODO
-
- m_bIsInited = true;
- }
-
- private void parseSource(XMLInputSource input, String filePathName) throws PartInitException {
- try {
- XMLizable inputDescription = AbstractSection.parseDescriptor(input);
- if (inputDescription instanceof AnalysisEngineDescription) {
- validateDescriptorType(DESCRIPTOR_AE);
- setAeDescription((AnalysisEngineDescription) inputDescription);
- } else if (inputDescription instanceof TypeSystemDescription) {
- validateDescriptorType(DESCRIPTOR_TYPESYSTEM);
- setTypeSystemDescription((TypeSystemDescription) inputDescription);
- } else if (inputDescription instanceof TypePriorities) {
- validateDescriptorType(DESCRIPTOR_TYPEPRIORITY);
- setTypePriorities((TypePriorities) inputDescription);
- } else if (inputDescription instanceof FsIndexCollection) {
- validateDescriptorType(DESCRIPTOR_INDEX);
- setFsIndexCollection((FsIndexCollection) inputDescription);
- } else if (inputDescription instanceof ResourceManagerConfiguration) {
- validateDescriptorType(DESCRIPTOR_EXTRESANDBINDINGS);
- setExtResAndBindings((ResourceManagerConfiguration) inputDescription);
- } else if (inputDescription instanceof CollectionReaderDescription) {
- validateDescriptorType(DESCRIPTOR_COLLECTIONREADER);
- setCollectionReaderDescription((CollectionReaderDescription) inputDescription);
- } else if (inputDescription instanceof CasInitializerDescription) {
- validateDescriptorType(DESCRIPTOR_CASINITIALIZER);
- setCasInitializerDescription((CasInitializerDescription) inputDescription);
- } else if (inputDescription instanceof CasConsumerDescription) {
- validateDescriptorType(DESCRIPTOR_CASCONSUMER);
- setCasConsumerDescription((CasConsumerDescription) inputDescription);
- } else if (inputDescription instanceof FlowControllerDescription) {
- validateDescriptorType(DESCRIPTOR_FLOWCONTROLLER);
- setFlowControllerDescription((FlowControllerDescription) inputDescription);
- } else {
- throw new PartInitException(Messages.getFormattedString(
- "MultiPageEditor.unrecognizedDescType", //$NON-NLS-1$
- new String[] { AbstractSection.maybeShortenFileName(filePathName) })
- + Messages.getString("MultiPageEditor.11")); //$NON-NLS-1$
- }
- isBadXML = false;
- } catch (InvalidXMLException e) {
- e.printStackTrace();
- Utility
- .popMessage(
- Messages.getString("MultiPageEditor.XMLerrorInDescriptorTitle"), //$NON-NLS-1$
- Messages.getString("MultiPageEditor.XMLerrorInDescriptor") + "\n" + getMessagesToRootCause(e), //$NON-NLS-1$ //$NON-NLS-2$
- MessageDialog.ERROR);
-
- } catch (ResourceInitializationException e) {
- // occurs if bad xml
- // leave isBadXML flag set to true
- Utility.popMessage(Messages.getString("MultiPageEditor.errorInDescTitle"), //$NON-NLS-1$
- Messages.getString("MultiPageEditor.errorInDesc") + "\n" + getMessagesToRootCause(e), //$NON-NLS-1$ //$NON-NLS-2$
- MessageDialog.ERROR);
- }
- }
-
- private void validateDescriptorType(int newDescriptorType) throws ResourceInitializationException {
- if (0 != descriptorType && !openingContext && ((descriptorType & newDescriptorType) == 0))
- throw new ResourceInitializationException(Messages.getString("MultiPageEditor.12"), //$NON-NLS-1$
- Messages.getString("MultiPageEditor.13"), //$NON-NLS-1$
- new String[] { descriptorTypeString(), descriptorTypeString(newDescriptorType) });
- if (!openingContext)
- descriptorType = newDescriptorType;
- }
-
- /**
- * Create a resource manager that has a class loader that will search the compiled output of the
- * current project, in addition to the plug-in's classpath.
- *
- * We create a new resource manager every time it's needed to pick up any changes the user may
- * have made to any classes that could have been loaded.
- *
- * @return
- */
- public ResourceManager createResourceManager() {
- // long time = System.currentTimeMillis();
- ResourceManager rm = createResourceManager(null);
- // System.out.println("CreateResourceManager: " + (System.currentTimeMillis() - time));
- return rm;
- }
-
- public ResourceManager createResourceManager(String classPath) {
- // workspacePath = TAEConfiguratorPlugin.getWorkspace().getRoot().getLocation().toString();
- ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager();
-
- try {
- if (null == classPath)
- classPath = getProjectClassPath();
- resourceManager.setExtensionClassPath(this.getClass().getClassLoader(), classPath, true);
- resourceManager.setDataPath(CDEpropertyPage.getDataPath(getProject()));
- } catch (MalformedURLException e1) {
- throw new InternalErrorCDE(Messages.getString("MultiPageEditor.14"), e1); //$NON-NLS-1$
- } catch (CoreException e1) {
- throw new InternalErrorCDE(Messages.getString("MultiPageEditor.15"), e1); //$NON-NLS-1$
- }
- return resourceManager;
- }
-
- /*
- * (non-Javadoc) Method declared on IEditorPart.
- */
- public boolean isSaveAsAllowed() {
- return true;
- }
-
- protected void pageChange(int newPageIndex) {
- if (isPageChangeRecursion)
- return;
- isRevertingIndex = false;
- int oldPageIndex = getCurrentPage();
-
- if (oldPageIndex != -1) {
- if (oldPageIndex == sourceIndex) {
- if (!validateSource()) {
- setActivePageWhileBlockingRecursion(sourceIndex);
- return;
- }
- } else if (oldPageIndex == indexesIndex &&
- // could be the same page if users chose to
- // edit current descriptor when validateIndexes detected a
- // bad type priorities set
- newPageIndex != indexesIndex) // could be the same
- if (!validateIndexes())
- return;
- else if (newPageIndex != indexesIndex) {
- saveGoodVersionOfTypePriorities();
- }
- }
-
- super.pageChange(newPageIndex);
-
- Object newPage = pages.get(newPageIndex);
- if (newPage instanceof HeaderPage) {
- // ((HeaderPage)newPage).getManagedForm().refresh(); //super.pageChange does this
- if (newPage instanceof IndexesPage && oldPageIndex != indexesIndex) {
- saveGoodVersionOfTypePriorities();
- }
- } else if (newPageIndex == sourceIndex) {
- if (!isBadXML)
- updateSourceFromModel();
- else
- setActivePageWhileBlockingRecursion(sourceIndex);
- // set sourceChanged if badXML to redo error notification if nothing changed
- // in case XML was bad
- sourceChanged = (isBadXML || isRevertingIndex) ? true : false;
- }
- }
-
- protected void setActivePageWhileBlockingRecursion(int sourceIndex) {
- try {
- isPageChangeRecursion = true;
- // next call needed to be done but wasn't prior to
- // Eclipse 3.2
- // In Eclipse 3.2 they fixed this, but call this now
- // calls pageChange, and makes a recursive loop
- // We break that loop here.
- setActivePage(sourceIndex); // isn't being done otherwise?
- } finally {
- isPageChangeRecursion = false;
- }
- }
-
- private void saveGoodVersionOfTypePriorities() {
- TypePriorities tp = getAeDescription().getAnalysisEngineMetaData().getTypePriorities();
- m_typePrioritiesBackup = (null == tp) ? null : (TypePriorities) tp.clone();
- }
-
- private boolean revertToLastValid(String msg, String msgDetails) {
- String[] buttonLabels = new String[2];
- buttonLabels[0] = Messages.getString("MultiPageEditor.revertToLastValid"); //$NON-NLS-1$
- buttonLabels[1] = Messages.getString("MultiPageEditor.EditExisting"); //$NON-NLS-1$
- MessageDialog dialog = new MessageDialog(getEditorSite().getShell(), msg, null, msgDetails,
- MessageDialog.WARNING, buttonLabels, 0);
- dialog.open();
- // next line depends on return code for button 1 (which is 1)
- // and CANCEL code both being == 1
- return dialog.getReturnCode() == 0;
- }
-
- /**
- * Called when switching off of the indexes page Goal is to validate indexes by making a CAS - as
- * a side effect it does index validation.
- *
- * We do this without changing the typeSystemDescription
- *
- * @return
- */
- private boolean validateIndexes() {
- CAS localCAS = descriptorCAS.get();
- TypePriorities savedMergedTypePriorities = getMergedTypePriorities();
- FsIndexCollection savedFsIndexCollection = getMergedFsIndexCollection();
- try {
- setMergedFsIndexCollection();
- setMergedTypePriorities();
- descriptorCAS.validate();
- } catch (Exception ex) {
- descriptorCAS.set(localCAS);
- if (!revertToLastValid(Messages.getString("MultiPageEditor.indexDefProblemTitle"), //$NON-NLS-1$
- Messages.getString("MultiPageEditor.indexDefProblem") + //$NON-NLS-1$
- getMessagesToRootCause(ex))) {
- // currentIndex = -1; //irrelevent, but not sourceIndex
- super.setActivePage(indexesIndex);
- // currentIndex = indexesIndex;
- return false;
- } else {
- getAeDescription().getAnalysisEngineMetaData().setTypePriorities(m_typePrioritiesBackup);
- setMergedTypePriorities(savedMergedTypePriorities);
- setMergedFsIndexCollection(savedFsIndexCollection);
- isRevertingIndex = true;
- return true;
- }
- }
- return true;
- }
-
- private String getCharSet(String text) {
- final String key = Messages.getString("MultiPageEditor.16"); //$NON-NLS-1$
- int i = text.indexOf(key);
- if (i == -1)
- return Messages.getString("MultiPageEditor.17"); //$NON-NLS-1$
- i += key.length();
- int end = text.indexOf(Messages.getString("MultiPageEditor.18"), i); //$NON-NLS-1$
- return text.substring(i, end);
- }
-
+
+ private HashSet dirtyTypeNameHash; // for generating .java
+
+ // type files upon saving (this has a problem if user edited xml
+ // directly...)
+
+ public int m_nSaveAsStatus = SAVE_AS_NOT_IN_PROGRESS;
+
+ public static final int SAVE_AS_NOT_IN_PROGRESS = -1;
+
+ public static final int SAVE_AS_STARTED = -2;
+
+ public static final int SAVE_AS_CANCELLED = -3;
+
+ public static final int SAVE_AS_CONFIRMED = -4;
+
+ private boolean openingContext = false;
+
+ private boolean isContextLoaded = false;
+
+ public boolean getIsContextLoaded() {
+ return isContextLoaded;
+ }
+
+ /**
+ * Descriptor Types
+ */
+
+ private int descriptorType = 0;
+
+ public int getDescriptorType() {
+ return descriptorType;
+ }
+
+ public static final int DESCRIPTOR_AE = 1;
+
+ public static final int DESCRIPTOR_TYPESYSTEM = 1 << 1;
+
+ public static final int DESCRIPTOR_INDEX = 1 << 2;
+
+ public static final int DESCRIPTOR_TYPEPRIORITY = 1 << 3;
+
+ public static final int DESCRIPTOR_EXTRESANDBINDINGS = 1 << 4;
+
+ public static final int DESCRIPTOR_COLLECTIONREADER = 1 << 5;
+
+ public static final int DESCRIPTOR_CASINITIALIZER = 1 << 6;
+
+ public static final int DESCRIPTOR_CASCONSUMER = 1 << 7;
+
+ public static final int DESCRIPTOR_FLOWCONTROLLER = 1 << 8;
+
+ public String descriptorTypeString(int pDescriptorType) {
+ String r;
+ switch (pDescriptorType) {
+ case DESCRIPTOR_AE:
+ r = Messages.getString("MultiPageEditor.0");break; //$NON-NLS-1$
+ case DESCRIPTOR_TYPESYSTEM:
+ r = Messages.getString("MultiPageEditor.1");break; //$NON-NLS-1$
+ case DESCRIPTOR_INDEX:
+ r = Messages.getString("MultiPageEditor.2");break; //$NON-NLS-1$
+ case DESCRIPTOR_TYPEPRIORITY:
+ r = Messages.getString("MultiPageEditor.3");break; //$NON-NLS-1$
+ case DESCRIPTOR_EXTRESANDBINDINGS:
+ r = Messages.getString("MultiPageEditor.4");break; //$NON-NLS-1$
+ case DESCRIPTOR_COLLECTIONREADER:
+ r = Messages.getString("MultiPageEditor.5");break; //$NON-NLS-1$
+ case DESCRIPTOR_CASINITIALIZER:
+ r = Messages.getString("MultiPageEditor.6");break; //$NON-NLS-1$
+ case DESCRIPTOR_CASCONSUMER:
+ r = Messages.getString("MultiPageEditor.7");break; //$NON-NLS-1$
+ case DESCRIPTOR_FLOWCONTROLLER:
+ r = "Flow Controller";
+ break;
+ default:
+ throw new InternalErrorCDE(Messages.getString("MultiPageEditor.8")); //$NON-NLS-1$
+ }
+ return r + Messages.getString("MultiPageEditor.9"); //$NON-NLS-1$
+ }
+
+ public String descriptorTypeString() {
+ return descriptorTypeString(descriptorType);
+ }
+
+ public boolean isAeDescriptor() {
+ return 0 != (descriptorType & DESCRIPTOR_AE);
+ }
+
+ public boolean isTypeSystemDescriptor() {
+ return 0 != (descriptorType & DESCRIPTOR_TYPESYSTEM);
+ }
+
+ public boolean isFsIndexCollection() {
+ return 0 != (descriptorType & DESCRIPTOR_INDEX);
+ }
+
+ public boolean isTypePriorityDescriptor() {
+ return 0 != (descriptorType & DESCRIPTOR_TYPEPRIORITY);
+ }
+
+ public boolean isExtResAndBindingsDescriptor() {
+ return 0 != (descriptorType & DESCRIPTOR_EXTRESANDBINDINGS);
+ }
+
+ public boolean isCollectionReaderDescriptor() {
+ return 0 != (descriptorType & DESCRIPTOR_COLLECTIONREADER);
+ }
+
+ public boolean isCasInitializerDescriptor() {
+ return 0 != (descriptorType & DESCRIPTOR_CASINITIALIZER);
+ }
+
+ public boolean isCasConsumerDescriptor() {
+ return 0 != (descriptorType & DESCRIPTOR_CASCONSUMER);
+ }
+
+ public boolean isFlowControllerDescriptor() {
+ return 0 != (descriptorType & DESCRIPTOR_FLOWCONTROLLER);
+ }
+
+ public boolean isLocalProcessingDescriptor() {
+ return 0 != (descriptorType & (DESCRIPTOR_AE | DESCRIPTOR_COLLECTIONREADER
+ | DESCRIPTOR_CASINITIALIZER | DESCRIPTOR_CASCONSUMER | DESCRIPTOR_FLOWCONTROLLER));
+ }
+
+ public boolean isPrimitive() {
+ return isLocalProcessingDescriptor() && aeDescription.isPrimitive();
+ }
+
+ public boolean isAggregate() {
+ return isAeDescriptor() && (!aeDescription.isPrimitive());
+ }
+
+ private TypePriorities m_typePrioritiesBackup;
+
+ private Color fadeColor;
+
+ private boolean isRevertingIndex;
+
+ protected boolean isPageChangeRecursion = false;
+
+ public static final TypeDescription[] typeDescriptionArray0 = new TypeDescription[0];
+
+ private List typeSystemsToMerge;
+
+ private List typePrioritiesToMerge;
+
+ private List fsIndexesToMerge;
+
+ private Map failedRemotes = new TreeMap();
+ private Set failedRemotesAlreadyKnown = new TreeSet();
+
+ private static List<IConfigurationElement> externalEditorConfigurations = null;
+
+ private IUimaMultiPageEditor currentEditor; // can be CDE or another editor
+
+ public MultiPageEditor() {
+ super();
+ currentEditor = this; // default
+ initCDE (); // specific for CDE
+ }
+
+ /**
+ *
+ * Note: Try to move these codes out of constructor MultiPageEditor().
+ * Too much of impacts. Put it back into constructor MultiPageEditor()
+ */
+ private void initCDE () {
+ // Model initialization
+ fileDirty = false;
+ dirtyTypeNameHash = new HashSet();
+ descriptorCAS = new DescriptorTCAS(this);
+ allTypes = new AllTypes(this);
+ definedTypesWithSupers = new DefinedTypesWithSupers(this);
+
+ // reasonable initial values
+ aeDescription = UIMAFramework.getResourceSpecifierFactory().createAnalysisEngineDescription();
+ typeSystemDescription = null;
+ importedTypeSystemDescription = null;
+ mergedTypeSystemDescription = null;
+ mergedFsIndexCollection = aeDescription.getAnalysisEngineMetaData().getFsIndexCollection();
+ resolvedExternalResourcesAndBindings = aeDescription.getResourceManagerConfiguration();
+ resolvedFlowControllerDeclaration = aeDescription.getFlowControllerDeclaration();
+ mergedTypePriorities = aeDescription.getAnalysisEngineMetaData().getTypePriorities();
+ }
+
+ private static final String EXTENSION_TAG_CLASS_ATTRIB = "class";
+
+
+ private IUimaEditorExtension getRequiredEditor(XMLizable parsedResult) {
+ return getRequiredEditor(null, parsedResult.getClass().getName());
+ }
+
+ private IUimaEditorExtension getRequiredEditor(String topElementName) {
+ return getRequiredEditor(topElementName, null);
+ }
+
+ // returns null if no matching editor found
+ // otherwise instantiates a new editor
+ private IUimaEditorExtension getRequiredEditor(String topElementName, String parsedResultClassName) {
+ IUimaEditorExtension editor;
+ // load external editor configurations if not already loaded
+ if (null == externalEditorConfigurations) {
+ getExternalEditorConfigurations();
+ }
+
+ for (IConfigurationElement xeditor : externalEditorConfigurations) {
+ for (IConfigurationElement canEdit : xeditor.getChildren()) {
+ String elementName = canEdit.getAttribute("elementName");
+ String parseResultName = canEdit.getAttribute("internalParseClass");
+ if ( ( (null != topElementName) && topElementName.equals(elementName)) |
+ ( (null != parsedResultClassName) && parsedResultClassName.equals(parseResultName)) ) {
+ try {
+ editor = (IUimaEditorExtension) xeditor.createExecutableExtension(EXTENSION_TAG_CLASS_ATTRIB);
+ } catch (CoreException e) {
+ Utility.popMessage("Unexpected Exception", "While trying to load an editor extension"
+ + getMessagesToRootCause(e), Utility.ERROR);
+ return null;
+ }
+ editor.init();
+ return editor;
+ }
+ }
+ }
+ return null;
+ }
+
+ private static final String EXTENSION_POINT_ID = "externalEditor";
+
+ // load all of the external editor xml data
+ // (but don't load the actual editors, yet)
+ private void getExternalEditorConfigurations () {
+ // Get extension point from Registry
+ IExtensionPoint point = Platform.getExtensionRegistry()
+ .getExtensionPoint(TAEConfiguratorPlugin.pluginId, EXTENSION_POINT_ID);
+
+ externalEditorConfigurations = new ArrayList<IConfigurationElement>();
+
+ // check: Any <extension> tags for our extension-point?
+ if (point != null) {
+ for (IExtension extension : point.getExtensions()) {
+ Bundle b = Platform.getBundle(extension.getContributor().getName());
+ if (b == null) {
+ Utility.popMessage(
+ "Problem with Editor Extension",
+ "Editor '" + extension.getContributor().getName() + "' is present, but can't be loaded, probably because of unsatisfied dependencies\n",
+ Utility.ERROR);
+ continue;
+ }
+ for (IConfigurationElement ces : extension.getConfigurationElements()) {
+ externalEditorConfigurations.add(ces);
+ }
+ }
+ } else {
+ // Error - no such extension point
+ Utility.popMessage(
+ "Internal Error",
+ "CDE's extension point is missing",
+ Utility.ERROR);
+ }
+ }
+
+ /***************************************************************************/
+ /* Expose "protected" methods and methods from Super */
+ /***************************************************************************/
+
+ public void initSuper(IEditorSite site, IEditorInput editorInput) throws PartInitException {
+ super.init(site, editorInput);
+ }
+
+ public int getCurrentPageSuper () {
+ return getCurrentPage();
+ }
+
+ public void setPartNameSuper(String partName) {
+ super.setPartName(partName);
+ }
+
+ public void setPageTextSuper(int pageIndex, String text) {
+ super.setPageText(pageIndex, text);
+ }
+
+ public void pageChangeSuper(int newPageIndex) {
+ super.pageChange(newPageIndex);
+ }
+
+ public void setActivePageSuper (int pageIndex) {
+ super.setActivePage(pageIndex);
+ }
+
+ public void firePropertyChangeSuper(final int propertyId) {
+ super.firePropertyChange(propertyId);
+ }
+
+ public void setInputSuper(IEditorInput input) {
+ super.setInput(input);
+ }
+
+ // XML source editor is opened by CDE when the source is "initially" invalid.
+ // Called by DDE when the source becomes valid and it is DD.
+ public XMLEditor getSourceEditor () {
+ return sourceTextEditor;
+ }
+
+ /***************************************************************************/
+
+ /**
+ * override the createToolkit method in FormEditor - to use a shared colors resource.
+ *
+ * This method is called by the FormEditor's createPages() method which will in turn call the
+ * addPages method below. The toolkit ref is stored in the FormEditor object, and can be retrieved
+ * by getToolkit().
+ *
+ */
+
+ protected FormToolkit createToolkit(Display display) {
+ return new FormToolkit(TAEConfiguratorPlugin.getDefault().getFormColors(display));
+ }
+
+ /*
+ * Two forms of addPage - one for non-source-editors, and one for source-editor
+ */
+ protected int addPageAndSetTabTitle(HeaderPage page, String keyTabTitle) throws PartInitException {
+ int pageIndex = addPage(page);
+ // set the text on the tab used to select the page in the multipage editor
+ setPageText(pageIndex, keyTabTitle);
+ return pageIndex;
+ }
+
+ protected int addPageAndSetTabTitle(IEditorPart page, IEditorInput input, String keyTabTitle)
+ throws PartInitException {
+ int pageIndex = addPage(page, input);
+ // set the text on the tab used to select the page in the multipage editor
+ setPageText(pageIndex, keyTabTitle);
+ return pageIndex;
+ }
+
+ /*
+ * In general, 3 kinds of pages can be added. 1) an editor (IEditorPart, IEditorInput) 2) (lazy)
+ * an IFormPage (extends IEditorPart) - has a managedForm, can wrap an editor 3) (lazy) a SWT
+ * Control (Not Used)
+ *
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.forms.editor.FormEditor#addPages()
+ */
+ protected void addPages() {
+ currentEditor.addPagesForCurrentEditor();
+ }
+
+ public void addPagesForCurrentEditor() {
+ boolean allPages = isLocalProcessingDescriptor();
+ try {
+ overviewIndex = addPageAndSetTabTitle(overviewPage = new OverviewPage(this), Messages
+ .getString("MultiPageEditor.overviewTab")); //$NON-NLS-1$
+
+ if (allPages) {
+ if (isAeDescriptor())
+ aggregateIndex = addPageAndSetTabTitle(aggregatePage = new AggregatePage(this), Messages
+ .getString("MultiPageEditor.aggregateTab")); //$NON-NLS-1$
+ parameterIndex = addPageAndSetTabTitle(parameterPage = new ParameterPage(this), Messages
+ .getString("MultiPageEditor.parameterTab")); //$NON-NLS-1$
+ settingsIndex = addPageAndSetTabTitle(settingsPage = new SettingsPage(this), Messages
+ .getString("MultiPageEditor.settingsTab")); //$NON-NLS-1$
+ }
+
+ if (allPages || isTypeSystemDescriptor()) {
+ typeIndex = addPageAndSetTabTitle(typePage = new TypePage(this), Messages
+ .getString("MultiPageEditor.typeTab")); //$NON-NLS-1$
+ }
+
+ if (allPages) {
+ capabilityIndex = addPageAndSetTabTitle(capabilityPage = new CapabilityPage(this), Messages
+ .getString("MultiPageEditor.capabilityTab")); //$NON-NLS-1$
+ }
+
+ if (allPages || isTypePriorityDescriptor() || isFsIndexCollection()) {
+ indexesIndex = addPageAndSetTabTitle(indexesPage = new IndexesPage(this), Messages
+ .getString("MultiPageEditor.indexesTab")); //$NON-NLS-1$
+ }
+
+ if (allPages || isExtResAndBindingsDescriptor()) {
+ resourcesIndex = addPageAndSetTabTitle(resourcesPage = new ResourcesPage(this), Messages
+ .getString("MultiPageEditor.resourcesTab")); //$NON-NLS-1$
+ }
+
+ sourceIndex = addPageAndSetTabTitle(sourceTextEditor = new XMLEditor(this), getEditorInput(),
+ Messages.getString("MultiPageEditor.sourceTab")); //$NON-NLS-1$
+
+ } catch (PartInitException e) {
+ e.printStackTrace(); // TODO fix this
+ }
+ if (isBadXML) {
+ pageChange(sourceIndex);
+ }
+ }
+
+ /**
+ * @param monitor
+ */
+ public void jcasGen(IProgressMonitor monitor) {
+ if (MultiPageEditorContributor.getAutoJCasGen()) {
+ doJCasGenChkSrc(monitor);
+ }
+ }
+
+ public void doJCasGenChkSrc(IProgressMonitor monitor) {
+ if (isSourceFolderValid())
+ doJCasGen(monitor);
+ }
+
+ public boolean isSourceFolderValid() {
+ IResource folder = getPrimarySourceFolder();
+ if (folder == null) {
+ String msg = Messages.getString("MultiPageEditor.noSrcNoJCas"); //$NON-NLS-1$
+ Utility.popMessage(Messages.getString("MultiPageEditor.noSrcDir"), msg, MessageDialog.ERROR); //$NON-NLS-1$
+ return false;
+ }
+ return true;
+ }
+
+ private boolean syncSourceBeforeSavingToFile() {
+ boolean modelOK = true;
+ if (getCurrentPage() != sourceIndex) {
+ validateIndexes();
+ updateSourceFromModel();
+ } else { // have to check if there are dirty types
+ modelOK = validateSource();
+ }
+ if (modelOK && isLocalProcessingDescriptor()) {
+ return isValidAE(aeDescription);
+ }
+ return modelOK;
+ }
+
+ public boolean isValidAE(AnalysisEngineDescription aAe) {
+ AbstractSection.setVnsHostAndPort(aAe);
+ // copy Ae into real descriptors if needed
+ getTrueDescriptor();
+ // use clones because validation modifies (imports get imported)
+ if (isCollectionReaderDescriptor()) {
+ CollectionReaderDescription collRdr = (CollectionReaderDescription) collectionReaderDescription
+ .clone();
+ try {
+ collRdr.doFullValidation(createResourceManager());
+ } catch (Throwable e) { // all these are Throwable to catch errors like
+ // UnsupportedClassVersionError, which happens if the annotator
+ // class is compiled for Java 5.0, but the CDE is running Java 1.4.2
+ Utility
+ .popMessage(
+ Messages.getString("MultiPageEditor.failedCollRdrValidation"), //$NON-NLS-1$
+ Messages.getString("MultiPageEditor.failedCollRdrValidationMsg") + "\n" + getMessagesToRootCause(e), //$NON-NLS-1$ //$NON-NLS-2$
+ MessageDialog.ERROR);
+ return false;
+ }
+ } else if (isCasInitializerDescriptor()) {
+ CasInitializerDescription casInit = (CasInitializerDescription) casInitializerDescription
+ .clone();
+ try {
+ casInit.doFullValidation(createResourceManager());
+ } catch (Throwable e) {
+ Utility
+ .popMessage(
+ Messages.getString("MultiPageEditor.failedCasInitValidation"), //$NON-NLS-1$
+ Messages.getString("MultiPageEditor.failedCasInitValidationMsg") + "\n" + getMessagesToRootCause(e), //$NON-NLS-1$ //$NON-NLS-2$
+ MessageDialog.ERROR);
+ return false;
+ }
+ } else if (isCasConsumerDescriptor()) {
+ CasConsumerDescription casCons = (CasConsumerDescription) casConsumerDescription.clone();
+ try {
+ casCons.doFullValidation(createResourceManager());
+ } catch (Throwable e) {
+ Utility
+ .popMessage(
+ Messages.getString("MultiPageEditor.failedCasConsValidation"), //$NON-NLS-1$
+ Messages.getString("MultiPageEditor.failedCasConsValidationMsg") + "\n" + getMessagesToRootCause(e), //$NON-NLS-1$ //$NON-NLS-2$
+ MessageDialog.ERROR);
+ return false;
+ }
+
+ } else if (isFlowControllerDescriptor()) {
+ FlowControllerDescription fc = (FlowControllerDescription) flowControllerDescription.clone();
+ try {
+ fc.doFullValidation(createResourceManager());
+ } catch (Throwable e) {
+ Utility.popMessage("Error in Flow Controller Descriptor",
+ "The Descriptor is invalid for the following reason:" + "\n"
+ + getMessagesToRootCause(e), MessageDialog.ERROR);
+ return false;
+ }
+ } else {
+ AnalysisEngineDescription ae = (AnalysisEngineDescription) aAe.clone();
+
+ // speedup = replace typeSystem with resolved imports version
+ if (ae.isPrimitive()) {
+ TypeSystemDescription tsd = getMergedTypeSystemDescription();
+ if (null != tsd) {
+ tsd = (TypeSystemDescription) tsd.clone();
+ }
+ ae.getAnalysisEngineMetaData().setTypeSystem(tsd);
+ }
+ ae.getAnalysisEngineMetaData().setFsIndexCollection(getMergedFsIndexCollection());
+ ae.getAnalysisEngineMetaData().setTypePriorities(getMergedTypePriorities());
+ try {
+ ae.doFullValidation(createResourceManager());
+ } catch (Throwable e) {
+ Utility
+ .popMessage(
+ Messages.getString("MultiPageEditor.failedAeValidation"), //$NON-NLS-1$
+ Messages.getString("MultiPageEditor.failedAeValidationMsg") + "\n" + getMessagesToRootCause(e), //$NON-NLS-1$ //$NON-NLS-2$
+ MessageDialog.ERROR);
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * Saves the multi-page editor's document.
+ */
+ public void doSave(IProgressMonitor monitor) {
+ currentEditor.doSaveForCurrentEditor(monitor);
+ }
+
+ public void doSaveForCurrentEditor(IProgressMonitor monitor) {
+ boolean modelOK = syncSourceBeforeSavingToFile();
+ sourceTextEditor.doSave(monitor);
+ finishSave(monitor, modelOK);
+ }
+
+ private void finishSave(IProgressMonitor monitor, boolean modelOK) {
+ if (modelOK) {
+ if (dirtyTypeNameHash.size() > 0)
+ jcasGen(monitor);
+ dirtyTypeNameHash.clear();
+ }
+ fileDirty = false;
+ firePropertyChange(ISaveablePart.PROP_DIRTY);
+
+ }
+
+ /**
+ * Saves the multi-page editor's document as another file. Updates this multi-page editor's input
+ * to correspond to the nested editor's.
+ *
+ * This is not implemented correctly: filename isn't switched to new filename, etc.
+ */
+ public void doSaveAs() {
+ currentEditor.doSaveAsForCurrentEditor();
+ }
+
+ public void doSaveAsForCurrentEditor() {
+ boolean modelOK = syncSourceBeforeSavingToFile();
+ setSaveAsStatus(SAVE_AS_STARTED);
+ sourceTextEditor.doSaveAs();
+
+ if (m_nSaveAsStatus == SAVE_AS_CANCELLED) {
+ m_nSaveAsStatus = SAVE_AS_NOT_IN_PROGRESS;
+ return;
+ }
+ // should only do if editorInput is new
+ FileEditorInput newEditorInput = (FileEditorInput) sourceTextEditor.getEditorInput();
+
+ // if(old)
+ setInput(newEditorInput);
+ firePropertyChange(PROP_INPUT);
+ // setTitle(newEditorInput.getFile().getName());
+ setPartName(newEditorInput.getFile().getName());
+ // this next does NOT seem to change the overall page title
+
+ firePropertyChange(PROP_TITLE);
+ finishSave(null, modelOK);
+ }
+
+ public boolean isDirty() {
+ return fileDirty;
+ }
+
+ public boolean isSaveOnCloseNeeded() {
+ return fileDirty;
+ }
+
+ public void setFileDirty() {
+ if (m_bIsInited) {
+ fileDirty = true;
+ // next is key
+ this.firePropertyChange(ISaveablePart.PROP_DIRTY);
+ }
+ }
+
+ // Called by External Editor extensions when doSave or doSaveAs is called
+ public void setFileDirtyFlag(boolean value) {
+ fileDirty = value;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.eclipse.ui.IEditorPart#init(org.eclipse.ui.IEditorSite, org.eclipse.ui.IEditorInput)
+ */
+ public void init(IEditorSite site, IEditorInput editorInput) throws PartInitException {
+ XMLInputSource input;
+
+ if (!(editorInput instanceof IFileEditorInput))
+ throw new PartInitException(Messages.getString("MultiPageEditor.invalidInputClass")); //$NON-NLS-1$
+ fileNeedingContext = file = ((IFileEditorInput) editorInput).getFile();
+ String filePathName = file.getLocation().toOSString();
+
+ try {
+ input = new XMLInputSource(filePathName);
+ } catch (IOException e) {
+ String m = Messages.getFormattedString("MultiPageEditor.IOError", //$NON-NLS-1$
+ new String[] { AbstractSection.maybeShortenFileName(filePathName) })
+ + Messages.getString("MultiPageEditor.10") + getMessagesToRootCause(e); //$NON-NLS-1$
+ // skip showing a message because the partInitException
+ // shows it
+ throw new PartInitException(m);
+ }
+
+ super.init(site, editorInput); // to allow other editors to get site and editorInput
+
+ // leaves isBadXML set, if it can't parse but isn't throwing
+ isContextLoaded = false;
+ try {
+ parseSource(input, filePathName);
+ } catch (MultilevelCancel e) {
+ throw new PartInitException("Operation Cancelled");
+ }
+
+ isContextLoaded = true;
+
+ // super.init(site, editorInput);
+ setPartName(editorInput.getName());
+ setContentDescription(editorInput.getName());
+ // setContentDescription(1 line summary); TODO
+
+ m_bIsInited = true;
+ }
+
+ private IUimaEditorExtension extensionEditor;
+
+ private void parseSource(XMLInputSource input, String filePathName) throws PartInitException {
+ extensionEditor = null;
+ parseSourceInner(input, filePathName);
+ }
+
+ private void parseSourceInner(XMLInputSource input, String filePathName) throws PartInitException {
+ XMLizable inputDescription = null;
+ try {
+ inputDescription = AbstractSection.parseDescriptor(input);
+ if (inputDescription instanceof AnalysisEngineDescription) {
+ validateDescriptorType(DESCRIPTOR_AE);
+ setAeDescription((AnalysisEngineDescription) inputDescription);
+ } else if (inputDescription instanceof TypeSystemDescription) {
+ validateDescriptorType(DESCRIPTOR_TYPESYSTEM);
+ setTypeSystemDescription((TypeSystemDescription) inputDescription);
+ } else if (inputDescription instanceof TypePriorities) {
+ validateDescriptorType(DESCRIPTOR_TYPEPRIORITY);
+ setTypePriorities((TypePriorities) inputDescription);
+ } else if (inputDescription instanceof FsIndexCollection) {
+ validateDescriptorType(DESCRIPTOR_INDEX);
+ setFsIndexCollection((FsIndexCollection) inputDescription);
+ } else if (inputDescription instanceof ResourceManagerConfiguration) {
+ validateDescriptorType(DESCRIPTOR_EXTRESANDBINDINGS);
+ setExtResAndBindings((ResourceManagerConfiguration) inputDescription);
+ } else if (inputDescription instanceof CollectionReaderDescription) {
+ validateDescriptorType(DESCRIPTOR_COLLECTIONREADER);
+ setCollectionReaderDescription((CollectionReaderDescription) inputDescription);
+ } else if (inputDescription instanceof CasInitializerDescription) {
+ validateDescriptorType(DESCRIPTOR_CASINITIALIZER);
+ setCasInitializerDescription((CasInitializerDescription) inputDescription);
+ } else if (inputDescription instanceof CasConsumerDescription) {
+ validateDescriptorType(DESCRIPTOR_CASCONSUMER);
+ setCasConsumerDescription((CasConsumerDescription) inputDescription);
+ } else if (inputDescription instanceof FlowControllerDescription) {
+ validateDescriptorType(DESCRIPTOR_FLOWCONTROLLER);
+ setFlowControllerDescription((FlowControllerDescription) inputDescription);
+ } else {
+ if (null == extensionEditor) {
+ extensionEditor = getRequiredEditor(inputDescription);
+ }
+ if (null == extensionEditor) {
+ throw new PartInitException(Messages.getFormattedString(
+ "MultiPageEditor.unrecognizedDescType", //$NON-NLS-1$
+ new String[] { AbstractSection.maybeShortenFileName(filePathName) })
+ + Messages.getString("MultiPageEditor.11")); //$NON-NLS-1$
+ } else {
+ extensionEditor.activateEditor(getEditorSite(), getEditorInput(), this, inputDescription);
+ currentEditor = (IUimaMultiPageEditor)extensionEditor;
+ }
+ }
+ isBadXML = false;
+ } catch (InvalidXMLException e) {
+ if (InvalidXMLException.INVALID_DESCRIPTOR_FILE.equals(e.getMessageKey())) {
+ Throwable cause = e.getCause();
+ if ((cause instanceof InvalidXMLException) &&
+ InvalidXMLException.UNKNOWN_ELEMENT.equals(((InvalidXMLException)cause).getMessageKey()) &&
+ (null == extensionEditor)) {
+ // try loading extension editors and reparsing
+ extensionEditor = getRequiredEditor((String)((InvalidXMLException)cause).getArguments()[0]);
+ if (null != extensionEditor) {
+ // the act of finding the right editor calls that editors init() method
+ // which could install another parse target result, which would make this
+ // exception go away - so try reparsing.
+
+ try {
+ parseSourceInner(new XMLInputSource(input.getURL()), filePathName);
+ } catch (IOException e1) {
+ Utility.popMessage(
+ "Internal Error",
+ "While parsing input for extension editor: " + getMessagesToRootCause(e1),
+ Utility.ERROR);
+ throw new InternalErrorCDE(e1);
+ }
+ return;
+ }
+ }
+ }
+ e.printStackTrace();
+ Utility.popMessage(Messages.getString("MultiPageEditor.XMLerrorInDescriptorTitle"), //$NON-NLS-1$
+ Messages.getString("MultiPageEditor.XMLerrorInDescriptor") + "\n" + getMessagesToRootCause(e), //$NON-NLS-1$ //$NON-NLS-2$
+ MessageDialog.ERROR);
+
+ } catch (ResourceInitializationException e) {
+ // occurs if bad xml
+ // leave isBadXML flag set to true
+ Utility.popMessage(Messages.getString("MultiPageEditor.errorInDescTitle"), //$NON-NLS-1$
+ Messages.getString("MultiPageEditor.errorInDesc") + "\n" + getMessagesToRootCause(e), //$NON-NLS-1$ //$NON-NLS-2$
+ MessageDialog.ERROR);
+ }
+ }
+
+ private void validateDescriptorType(int newDescriptorType) throws ResourceInitializationException {
+ if (0 != descriptorType && !openingContext && ((descriptorType & newDescriptorType) == 0))
+ throw new ResourceInitializationException(Messages.getString("MultiPageEditor.12"), //$NON-NLS-1$
+ Messages.getString("MultiPageEditor.13"), //$NON-NLS-1$
+ new String[] { descriptorTypeString(), descriptorTypeString(newDescriptorType) });
+ if (!openingContext)
+ descriptorType = newDescriptorType;
+ }
+
+ /**
+ * Create a resource manager that has a class loader that will search the compiled output of the
+ * current project, in addition to the plug-in's classpath.
+ *
+ * We create a new resource manager every time it's needed to pick up any changes the user may
+ * have made to any classes that could have been loaded.
+ *
+ * @return
+ */
+ public ResourceManager createResourceManager() {
+ // long time = System.currentTimeMillis();
+ ResourceManager rm = createResourceManager(null);
+ // System.out.println("CreateResourceManager: " + (System.currentTimeMillis() - time));
+ return rm;
+ }
+
+ public ResourceManager createResourceManager(String classPath) {
+ // workspacePath = TAEConfiguratorPlugin.getWorkspace().getRoot().getLocation().toString();
+ ResourceManager resourceManager = UIMAFramework.newDefaultResourceManager();
+
+ try {
+ if (null == classPath)
+ classPath = getProjectClassPath();
+ resourceManager.setExtensionClassPath(this.getClass().getClassLoader(), classPath, true);
+ resourceManager.setDataPath(CDEpropertyPage.getDataPath(getProject()));
+ } catch (MalformedURLException e1) {
+ throw new InternalErrorCDE(Messages.getString("MultiPageEditor.14"), e1); //$NON-NLS-1$
+ } catch (CoreException e1) {
+ throw new InternalErrorCDE(Messages.getString("MultiPageEditor.15"), e1); //$NON-NLS-1$
+ }
+ return resourceManager;
+ }
+
+ /*
+ * (non-Javadoc) Method declared on IEditorPart.
+ */
+ public boolean isSaveAsAllowed() {
+ return true;
+ }
+
+ protected void pageChange(int newPageIndex) {
+ currentEditor.pageChangeForCurrentEditor(newPageIndex);
+ }
+
+ public void pageChangeForCurrentEditor(int newPageIndex) {
+ if (isPageChangeRecursion)
+ return;
+ isRevertingIndex = false;
+ int oldPageIndex = getCurrentPage();
+
+ if (oldPageIndex != -1) {
+ if (oldPageIndex == sourceIndex) {
+ if (!validateSource()) {
+ setActivePageWhileBlockingRecursion(sourceIndex);
+ return;
+ }
+ } else if (oldPageIndex == indexesIndex &&
+ // could be the same page if users chose to
+ // edit current descriptor when validateIndexes detected a
+ // bad type priorities set
+ newPageIndex != indexesIndex) // could be the same
+ if (!validateIndexes())
+ return;
+ else if (newPageIndex != indexesIndex) {
+ saveGoodVersionOfTypePriorities();
+ }
+ }
+
+ super.pageChange(newPageIndex);
+
+ Object newPage = pages.get(newPageIndex);
+ if (newPage instanceof HeaderPage) {
+ // ((HeaderPage)newPage).getManagedForm().refresh(); //super.pageChange does this
+ if (newPage instanceof IndexesPage && oldPageIndex != indexesIndex) {
+ saveGoodVersionOfTypePriorities();
+ }
+ } else if (newPageIndex == sourceIndex) {
+ if (!isBadXML)
+ updateSourceFromModel();
+ else
+ setActivePageWhileBlockingRecursion(sourceIndex);
+ // set sourceChanged if badXML to redo error notification if nothing changed
+ // in case XML was bad
[... 3483 lines stripped ...]