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 2009/03/31 11:54:48 UTC
svn commit: r760383 [4/6] - in
/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin: ./ META-INF/ icons/
icons/application/ icons/svgicons/ icons/window/
src/main/java/org/apache/uima/caseditor/
src/main/java/org/apache/uima/caseditor/core/ src/main/ja...
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusExplorerActionGroup.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusExplorerActionGroup.java?rev=760383&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusExplorerActionGroup.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusExplorerActionGroup.java Tue Mar 31 09:54:43 2009
@@ -0,0 +1,240 @@
+/*
+ * 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.corpusview;
+
+import org.apache.uima.caseditor.core.model.INlpElement;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.action.Separator;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+import org.eclipse.jface.window.SameShellProvider;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchActionConstants;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.actions.ActionContext;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.actions.ActionGroup;
+import org.eclipse.ui.actions.ImportResourcesAction;
+import org.eclipse.ui.dialogs.PropertyDialogAction;
+
+/**
+ * Main corpus explorer action group.
+ */
+final class CorpusExplorerActionGroup extends ActionGroup implements ICorpusExplorerActionGroup {
+ private OpenActionGroup openActionGroup;
+
+ private RefactorGroup refactorGroup;
+
+ protected ImportResourcesAction importAction;
+
+ // protected ExportResourcesAction mExportAction;
+
+ private WorkspaceActionGroup workspaceGroup;
+
+ private AnnotatorActionGroup annotatorActionGroup;
+
+ private ConsumerCorpusActionGroup consumerCorpusActionGroup;
+
+ private UimaRefactorActionGroup uimaRefactorActionGroup;
+
+ private PropertyDialogAction propertyAction;
+
+ private IWorkbenchWindow mWindow;
+
+ private IAction mRetargetPropertiesAction;
+
+ /**
+ * Creates a <code>CorpusExplorerActionGroup</code> object.
+ *
+ * @param view -
+ * the corresponding <code>CorpusExplorerView</code>
+ */
+ CorpusExplorerActionGroup(CorpusExplorerView view) {
+ mWindow = view.getSite().getPage().getWorkbenchWindow();
+
+ Shell shell = view.getSite().getShell();
+
+ openActionGroup = new OpenActionGroup(view.getSite().getPage());
+
+ refactorGroup = new RefactorGroup(shell, mWindow);
+
+ importAction = new ImportResourcesAction(mWindow);
+
+ // mExportAction = new ExportResourcesAction(mWindow);
+
+ workspaceGroup = new WorkspaceActionGroup(shell, mWindow);
+
+ annotatorActionGroup = new AnnotatorActionGroup(shell);
+
+ consumerCorpusActionGroup = new ConsumerCorpusActionGroup(shell);
+
+ uimaRefactorActionGroup = new UimaRefactorActionGroup(shell);
+
+ propertyAction = new PropertyDialogAction(new SameShellProvider(shell), view.getTreeViewer());
+
+ mRetargetPropertiesAction = ActionFactory.PROPERTIES.create(mWindow);
+ }
+
+ /**
+ * Fills the context menu with all the actions.
+ */
+ @Override
+ public void fillContextMenu(IMenuManager menu) {
+ IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
+
+ // For action order see "Eclipse User Interface Guidelines"
+
+ // 1. New actions
+ IAction newAction = ActionFactory.NEW.create(mWindow);
+ newAction.setText("New");
+ menu.add(newAction);
+ menu.add(new Separator());
+
+ // 2. Open actions
+ openActionGroup.fillContextMenu(menu);
+ menu.add(new Separator());
+
+ // 3. Navigate + Show In
+
+ // 4.1 Cut, Copy, Paste, Delete, Rename and other refactoring commands
+ refactorGroup.fillContextMenu(menu);
+ menu.add(new Separator());
+
+ // 4.2
+ menu.add(ActionFactory.IMPORT.create(mWindow));
+
+ // menu.add(ActionFactory.EXPORT.create(mWindow));
+
+ menu.add(new Separator());
+
+ // 5. Other Plugin Additions
+ workspaceGroup.fillContextMenu(menu);
+ menu.add(new Separator());
+
+ // 5.2 annotator additions
+ MenuManager taggerMenu = new MenuManager("Annotator");
+ menu.add(taggerMenu);
+
+ annotatorActionGroup.fillContextMenu(taggerMenu);
+
+ // 5.3 consumer additions
+ MenuManager trainerMenu = new MenuManager("Consumer");
+ menu.add(trainerMenu);
+
+ consumerCorpusActionGroup.fillContextMenu(trainerMenu);
+
+ MenuManager uimaRefactorMenu = new MenuManager("Refactor");
+ menu.add(uimaRefactorMenu);
+
+ uimaRefactorActionGroup.fillContextMenu(uimaRefactorMenu);
+
+ // 5.4 Annotator plugin additions
+ menu.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
+
+ // 6. Properties action
+ boolean isOnlyOneResourceSelected = selection.size() == 1;
+ if (isOnlyOneResourceSelected) {
+ menu.add(mRetargetPropertiesAction);
+ }
+ }
+
+ /**
+ * Fills the action bars
+ */
+ @Override
+ public void fillActionBars(IActionBars actionBars) {
+ actionBars.setGlobalActionHandler(ActionFactory.PROPERTIES.getId(), propertyAction);
+
+ actionBars.updateActionBars();
+
+ openActionGroup.fillActionBars(actionBars);
+ refactorGroup.fillActionBars(actionBars);
+ workspaceGroup.fillActionBars(actionBars);
+ }
+
+ /**
+ * Updates the actions.
+ */
+ @Override
+ public void updateActionBars() {
+ IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
+
+ propertyAction.setEnabled(selection.size() == 1);
+
+ openActionGroup.updateActionBars();
+ refactorGroup.updateActionBars();
+ workspaceGroup.updateActionBars();
+ }
+
+ /**
+ * Sets the context to the action groups.
+ */
+ @Override
+ public void setContext(ActionContext context) {
+ super.setContext(context);
+
+ openActionGroup.setContext(context);
+ refactorGroup.setContext(context);
+ workspaceGroup.setContext(context);
+ annotatorActionGroup.setContext(context);
+ consumerCorpusActionGroup.setContext(context);
+ uimaRefactorActionGroup.setContext(context);
+ }
+
+ /**
+ * Executes the default action, in this case the open action.
+ */
+ public void executeDefaultAction(IStructuredSelection selection) {
+ if (selection.getFirstElement() instanceof INlpElement) {
+ INlpElement nlpElement = (INlpElement) selection.getFirstElement();
+
+ openActionGroup.executeDefaultAction(new StructuredSelection(nlpElement.getResource()));
+ } else {
+ openActionGroup.executeDefaultAction(selection);
+ }
+ }
+
+ /**
+ * Dispose all resources created by the current object.
+ */
+ @Override
+ public void dispose() {
+ super.dispose();
+
+ openActionGroup.dispose();
+ refactorGroup.dispose();
+ importAction.dispose();
+ // mExportAction.dispose();
+ workspaceGroup.dispose();
+ annotatorActionGroup.dispose();
+ consumerCorpusActionGroup.dispose();
+ uimaRefactorActionGroup.dispose();
+ propertyAction.dispose();
+ }
+
+ void handleKeyPressed(KeyEvent e) {
+ refactorGroup.handleKeyPressed(e);
+ workspaceGroup.handleKeyPressed(e);
+ }
+}
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusExplorerUtil.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusExplorerUtil.java?rev=760383&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusExplorerUtil.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusExplorerUtil.java Tue Mar 31 09:54:43 2009
@@ -0,0 +1,97 @@
+/*
+ * 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.corpusview;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import org.apache.uima.caseditor.core.model.INlpElement;
+import org.apache.uima.caseditor.core.model.NlpProject;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.StructuredSelection;
+
+final class CorpusExplorerUtil
+{
+ /**
+ * Avoids instanciation of this utility class
+ */
+ private CorpusExplorerUtil()
+ {
+ // overridden to change access to private
+ }
+
+ static IStructuredSelection convertNLPElementsToResources(
+ IStructuredSelection selection)
+ {
+
+ LinkedList<Object> newSelectionList = new LinkedList<Object>();
+
+ for (Iterator elements = selection.iterator(); elements.hasNext();)
+ {
+ Object element = elements.next();
+
+ if (element instanceof INlpElement)
+ {
+ INlpElement nlpElement = (INlpElement) element;
+ newSelectionList.add(nlpElement.getResource());
+ }
+ else
+ {
+ newSelectionList.add(element);
+ }
+ }
+
+ return new StructuredSelection(newSelectionList);
+ }
+
+ /**
+ * TODO: Replace this method, the name is very ugly.
+ *
+ * @param selection
+ * @return true if NLPProject or NonNLPResource is included
+ *
+ * @deprecated
+ */
+ @Deprecated
+ static boolean isContaingNLPProjectOrNonNLPResources(
+ IStructuredSelection selection)
+ {
+ boolean isNLPProjectOrNonNLPResource = false;
+
+ for (Iterator resources = selection.iterator() ;
+ resources.hasNext() && !isNLPProjectOrNonNLPResource;)
+ {
+ Object resource = resources.next();
+
+ if (! (resource instanceof INlpElement))
+ {
+ isNLPProjectOrNonNLPResource = true;
+ }
+
+ // if nlp project return also
+ if ((resource instanceof NlpProject))
+ {
+ isNLPProjectOrNonNLPResource = true;
+ }
+ }
+
+ return isNLPProjectOrNonNLPResource;
+ }
+}
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusExplorerView.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusExplorerView.java?rev=760383&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusExplorerView.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusExplorerView.java Tue Mar 31 09:54:43 2009
@@ -0,0 +1,237 @@
+/*
+ * 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.corpusview;
+
+import org.apache.uima.caseditor.CasEditorPlugin;
+import org.eclipse.jface.action.IMenuListener;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.DecoratingLabelProvider;
+import org.eclipse.jface.viewers.DoubleClickEvent;
+import org.eclipse.jface.viewers.IDoubleClickListener;
+import org.eclipse.jface.viewers.IOpenListener;
+import org.eclipse.jface.viewers.ISelectionChangedListener;
+import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.jface.viewers.OpenEvent;
+import org.eclipse.jface.viewers.SelectionChangedEvent;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.dnd.DND;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.KeyListener;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.actions.ActionContext;
+import org.eclipse.ui.model.BaseWorkbenchContentProvider;
+import org.eclipse.ui.model.WorkbenchLabelProvider;
+import org.eclipse.ui.part.ViewPart;
+
+/**
+ * The corpus explorer is a view which knows how to display and handle the nlp
+ * model elements.
+ */
+public final class CorpusExplorerView extends ViewPart
+{
+
+ /**
+ * The ID of the <code>CorpusExplorerView</code>.
+ */
+ public final static String ID = "org.apache.uima.caseditor.corpusview";
+
+ private TreeViewer mTreeViewer;
+
+ private CorpusExplorerActionGroup mActions;
+
+ private ModelChangeListener mModelChangeListener;
+
+ /**
+ * Creates the main control of the current view.
+ */
+ @Override
+ public void createPartControl(Composite parent)
+ {
+ parent.setLayout(new FillLayout());
+
+ mTreeViewer = new TreeViewer(parent);
+ mTreeViewer.setContentProvider(new BaseWorkbenchContentProvider());
+
+ mTreeViewer.setLabelProvider(new DecoratingLabelProvider(
+ new WorkbenchLabelProvider(), PlatformUI.getWorkbench()
+ .getDecoratorManager().getLabelDecorator()));
+
+ // performance optimization
+ mTreeViewer.setUseHashlookup(true); // TODO: change back to true
+
+ initContextMenu();
+
+ mTreeViewer.setInput(CasEditorPlugin.getNlpModel());
+
+ mModelChangeListener = new ModelChangeListener(
+ mTreeViewer);
+
+ CasEditorPlugin.getNlpModel().addNlpModelChangeListener(mModelChangeListener);
+
+ mTreeViewer.setSorter(new CorpusSorter());
+
+ mActions = new CorpusExplorerActionGroup(this);
+
+ initListeners();
+
+ getSite().setSelectionProvider(mTreeViewer);
+
+ initDragAndDrop();
+
+ mActions.fillActionBars(getViewSite().getActionBars());
+
+ mActions.setContext(new ActionContext(
+ mTreeViewer.getSelection()));
+
+ mActions.updateActionBars();
+ }
+
+ /**
+ * Initializes the context menu.
+ */
+ private void initContextMenu()
+ {
+ MenuManager menuManager = new MenuManager("#PopupMenu");
+ menuManager.setRemoveAllWhenShown(true);
+ menuManager.addMenuListener(new IMenuListener()
+ {
+ public void menuAboutToShow(IMenuManager manager)
+ {
+ IStructuredSelection selection = (IStructuredSelection) mTreeViewer
+ .getSelection();
+
+ mActions.setContext(new ActionContext(selection));
+ mActions.fillContextMenu(manager);
+ }
+ });
+
+ Menu menu = menuManager.createContextMenu(mTreeViewer.getTree());
+ mTreeViewer.getTree().setMenu(menu);
+ getSite().registerContextMenu(menuManager, mTreeViewer);
+ }
+
+ /**
+ * Initializes the listeners.
+ */
+ private void initListeners()
+ {
+ mTreeViewer.addDoubleClickListener(new IDoubleClickListener()
+ {
+ public void doubleClick(DoubleClickEvent event)
+ {
+ IStructuredSelection selection = (IStructuredSelection) event
+ .getSelection();
+
+ Object selectedElement = selection.getFirstElement();
+
+ if (mTreeViewer.isExpandable(selectedElement))
+ {
+ mTreeViewer.setExpandedState(selectedElement, !mTreeViewer
+ .getExpandedState(selectedElement));
+ }
+ }
+ });
+
+ mTreeViewer.addOpenListener(new IOpenListener()
+ {
+ public void open(OpenEvent event)
+ {
+ mActions.executeDefaultAction((IStructuredSelection) event
+ .getSelection());
+ }
+ });
+
+ mTreeViewer.addSelectionChangedListener(new ISelectionChangedListener()
+ {
+ public void selectionChanged(SelectionChangedEvent event)
+ {
+ mActions.setContext(new ActionContext(event.getSelection()));
+
+ mActions.updateActionBars();
+ }
+ });
+
+ mTreeViewer.getTree().addKeyListener(new KeyListener(){
+
+ public void keyPressed(KeyEvent e) {
+ mActions.handleKeyPressed(e);
+ }
+
+ public void keyReleased(KeyEvent e) {
+ }});
+ }
+
+ /**
+ * Initializes the drag and drop stuff. Note: currently disabled, cause drag
+ * and drop did not work ...
+ */
+ private void initDragAndDrop()
+ {
+ int ops = DND.DROP_COPY | DND.DROP_MOVE;
+
+ //Transfer[] transfers = new Transfer[]
+ //{ LocalSelectionTransfer.getInstance(), ResourceTransfer.getInstance(),
+ // FileTransfer.getInstance(), PluginTransfer.getInstance() };
+
+ //mTreeViewer
+ // .addDragSupport(ops, transfers, new CorpusExplorerDragAdapter(
+ // getSite().getSelectionProvider()));
+
+ // CorpusExplorerDropAdapter adapter = new CorpusExplorerDropAdapter(
+ // mTreeViewer);
+
+ //adapter.setFeedbackEnabled(false);
+
+ // mTreeViewer.addDropSupport(ops | DND.DROP_DEFAULT, transfers, adapter);
+ }
+
+ /**
+ * Retrieves the <code>TreeViewer</code> of the current corupus explorer.
+ *
+ * @return the <code>TreeViewer</code>.
+ */
+ public ISelectionProvider getTreeViewer()
+ {
+ return mTreeViewer;
+ }
+
+ /**
+ * Sets the focus to the <code>TreeViewer</code>.
+ */
+ @Override
+ public void setFocus()
+ {
+ mTreeViewer.getTree().setFocus();
+ }
+
+ @Override
+ public void dispose()
+ {
+ super.dispose();
+
+ // TaePlugin.getNLPModel().removeNLPModelChangeListener(
+ // mModelChangeListener);
+ }
+}
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusSorter.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusSorter.java?rev=760383&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusSorter.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/CorpusSorter.java Tue Mar 31 09:54:43 2009
@@ -0,0 +1,69 @@
+/*
+ * 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.corpusview;
+
+
+import org.apache.uima.caseditor.core.model.CorpusElement;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.jface.viewers.ViewerSorter;
+
+
+/**
+ * This is a sorter for the corpus explorer tree.
+ */
+final class CorpusSorter extends ViewerSorter
+{
+ private static final int CAT_CORPUS = 1;
+ private static final int CAT_FOLDER = 2;
+ private static final int CAT_FILE = 3;
+
+ /**
+ * Maps the element type to a category coded as number:
+ *
+ * 1 for CorpusElement
+ * 2 for IFolder
+ * 3 for IFile
+ */
+ @Override
+ public int category(Object element)
+ {
+ // 1. corpus folder
+ if (element instanceof CorpusElement)
+ {
+ return CorpusSorter.CAT_CORPUS;
+ }
+ // 2. folder
+ else if (element instanceof IFolder)
+ {
+ return CorpusSorter.CAT_FOLDER;
+ }
+ // 3. files
+ else if (element instanceof IFile)
+ {
+ return CorpusSorter.CAT_FILE;
+ }
+ // if unknown, use default
+ else
+ {
+ return super.category(element);
+ }
+ }
+}
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/ICorpusExplorerActionGroup.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/ICorpusExplorerActionGroup.java?rev=760383&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/ICorpusExplorerActionGroup.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/ICorpusExplorerActionGroup.java Tue Mar 31 09:54:43 2009
@@ -0,0 +1,36 @@
+/*
+ * 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.corpusview;
+
+import org.eclipse.jface.viewers.IStructuredSelection;
+
+/**
+ * This interface should be implemented by all action groups used
+ * be the corpus explorer.
+ */
+public interface ICorpusExplorerActionGroup
+{
+ /**
+ * This method is called to start the default action
+ * of the action group.
+ * @param selection
+ */
+ void executeDefaultAction(IStructuredSelection selection);
+}
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/ModelChangeListener.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/ModelChangeListener.java?rev=760383&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/ModelChangeListener.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/ModelChangeListener.java Tue Mar 31 09:54:43 2009
@@ -0,0 +1,172 @@
+/*
+ * 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.corpusview;
+
+import java.util.LinkedList;
+
+import org.apache.uima.caseditor.core.model.INlpElement;
+import org.apache.uima.caseditor.core.model.delta.INlpElementDelta;
+import org.apache.uima.caseditor.core.model.delta.INlpModelChangeListener;
+import org.apache.uima.caseditor.core.model.delta.INlpModelDeltaVisitor;
+import org.apache.uima.caseditor.core.model.delta.Kind;
+import org.eclipse.jface.viewers.ITreeContentProvider;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.swt.widgets.Display;
+
+/**
+ * The ModelChangeListener listens for changes on the nlp
+ * model and updates the workspace tree.
+ */
+class ModelChangeListener implements
+ INlpModelChangeListener
+{
+ private TreeViewer mTreeViewer;
+
+ /**
+ * Initializes a new instance.
+ *
+ * @param treeViewer
+ */
+ public ModelChangeListener(TreeViewer treeViewer)
+ {
+ mTreeViewer = treeViewer;
+ }
+
+ public void resourceChanged(INlpElementDelta delta)
+ {
+ final LinkedList<Object> updated = new LinkedList<Object>();
+
+ final LinkedList<Object> added = new LinkedList<Object>();
+
+ final LinkedList<Object> removed = new LinkedList<Object>();
+
+
+ // INlpElementDelta childs[] = delta.getAffectedChildren();
+
+ INlpModelDeltaVisitor visitor = new INlpModelDeltaVisitor()
+ {
+ public boolean visit(INlpElementDelta delta)
+ {
+ if (delta.getResource().getName().equals(".corpus")) {
+ return true;
+ }
+
+ //if (delta.getKind() == IResourceDelta.OPEN
+ // || delta.getKind() == IResourceDelta.CONTENT)
+
+ if(delta.getKind().equals(Kind.CHANGED))
+ {
+ if (delta.isNlpElement())
+ {
+ updated.add(delta.getNlpElement());
+ }
+ else
+ {
+ updated.add(delta.getResource());
+ }
+ }
+ else if (delta.getKind().equals(Kind.ADDED))
+ {
+ if (delta.isNlpElement())
+ {
+ added.add(delta.getNlpElement());
+ }
+ else
+ {
+ added.add(delta.getResource());
+ }
+ }
+ else if (delta.getKind() == Kind.REMOVED)
+ {
+ if (delta.isNlpElement())
+ {
+ removed.add(delta.getNlpElement());
+ }
+ else
+ {
+ removed.add(delta.getResource());
+ }
+ }
+
+ return true;
+ }
+ };
+
+ delta.accept(visitor);
+
+ Display display = mTreeViewer.getControl().getDisplay();
+
+ if (!display.isDisposed())
+ {
+ display.asyncExec(new Runnable()
+ {
+ public void run()
+ {
+ if (mTreeViewer.getControl().isDisposed())
+ {
+ return;
+ }
+
+ mTreeViewer.remove(removed.toArray());
+
+ // TODO: add multiple elements at a time
+ // TODO: refactor
+ for (Object add : added)
+ {
+ ITreeContentProvider contentProvider =
+ (ITreeContentProvider)
+ mTreeViewer.getContentProvider();
+
+ // seems to make problems
+ mTreeViewer.add(
+ contentProvider.getParent(add),
+ add);
+ }
+
+ if (updated.size() > 0)
+ {
+ // mTreeViewer.update(updated.toArray(), null);
+
+ // mTreeViewer.refresh(true);
+ }
+
+ // mTreeViewer.refresh();
+ }
+ });
+ }
+ }
+
+ /**
+ * Refreshes the viewer.
+ */
+ public void refresh(final INlpElement element)
+ {
+ Display display = mTreeViewer.getControl().getDisplay();
+
+ display.asyncExec(new Runnable()
+ {
+
+ public void run()
+ {
+ mTreeViewer.refresh(element);
+ }
+ });
+ }
+}
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/OpenActionGroup.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/OpenActionGroup.java?rev=760383&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/OpenActionGroup.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/OpenActionGroup.java Tue Mar 31 09:54:43 2009
@@ -0,0 +1,80 @@
+/*
+ * 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.corpusview;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.actions.ActionGroup;
+import org.eclipse.ui.actions.OpenFileAction;
+import org.eclipse.ui.actions.OpenWithMenu;
+
+/**
+ * The OpenActionGroup contains the Open Action.
+ */
+final class OpenActionGroup extends ActionGroup implements ICorpusExplorerActionGroup {
+
+ /**
+ * The editor WorkbenchPage.
+ */
+ private IWorkbenchPage mPage;
+
+ /**
+ * The cached OpenFileAction instance.
+ */
+ private OpenFileAction mOpenFileAction;
+
+ /**
+ * Initializes a the current instance.
+ *
+ * @param page
+ */
+ OpenActionGroup(IWorkbenchPage page) {
+ mPage = page;
+ mOpenFileAction = new OpenFileAction(mPage);
+ }
+
+ @Override
+ public void fillContextMenu(IMenuManager menu) {
+ IStructuredSelection selection = CorpusExplorerUtil
+ .convertNLPElementsToResources((IStructuredSelection) getContext().getSelection());
+
+ mOpenFileAction.selectionChanged(selection);
+ menu.add(mOpenFileAction);
+
+ if (selection.size() == 1 && (selection.getFirstElement() instanceof IFile)) {
+
+ MenuManager submenu = new MenuManager("Open With");
+ submenu.add(new OpenWithMenu(mPage, (IFile) selection.getFirstElement()));
+
+ menu.add(submenu);
+ }
+ }
+
+ /**
+ * Executes the default action.
+ */
+ public void executeDefaultAction(IStructuredSelection selection) {
+ mOpenFileAction.selectionChanged(selection);
+ mOpenFileAction.run();
+ }
+}
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/PasteAction.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/PasteAction.java?rev=760383&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/PasteAction.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/PasteAction.java Tue Mar 31 09:54:43 2009
@@ -0,0 +1,175 @@
+/*
+ * 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.corpusview;
+
+import java.util.List;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.util.Assert;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.dnd.FileTransfer;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.actions.CopyFilesAndFoldersOperation;
+import org.eclipse.ui.actions.CopyProjectOperation;
+import org.eclipse.ui.part.ResourceTransfer;
+
+
+final class PasteAction extends ResourceAction
+{
+
+ private Shell mShell;
+
+ private Clipboard mClipboard;
+
+ /**
+ * Initializes the current instance.
+ *
+ * @param shell
+ * @param clipboard
+ */
+ public PasteAction(Shell shell, Clipboard clipboard) {
+ super("Paste");
+
+ if (shell == null || clipboard == null) {
+ throw new IllegalArgumentException();
+ }
+
+ mShell = shell;
+ mClipboard = clipboard;
+ }
+
+ /**
+ * Locates the new parent resource for the pasted ones.
+ *
+ * If currently selected resource is a file, the parent of the file is returned.
+ *
+ * @return
+ */
+ private IContainer getNewParent() {
+ List selection = getSelectedResources();
+
+ Assert.isTrue(selection.size() > 0);
+
+ IContainer result;
+
+ if (selection.get(0) instanceof IFile) {
+ result = ((IFile) selection.get(0)).getParent();
+ } else {
+ result = (IContainer) selection.get(0);
+ }
+
+ return result;
+ }
+
+ @Override
+ public void run() {
+ IResource[] resourceData = (IResource[]) mClipboard.getContents(ResourceTransfer.getInstance());
+
+ if (resourceData != null && resourceData.length > 0) {
+
+ // resource always contains either projects or files and folders
+ if (resourceData[0].getType() != IResource.PROJECT) {
+ CopyFilesAndFoldersOperation operation = new CopyFilesAndFoldersOperation(mShell);
+ operation.copyResources(resourceData, getNewParent());
+ } else {
+ for (IResource element : resourceData) {
+ new CopyProjectOperation(mShell).copyProject((IProject) element);
+ }
+ }
+
+ return;
+ } else {
+
+ String[] fileData = (String[]) mClipboard.getContents(FileTransfer.getInstance());
+
+ if (fileData != null && fileData.length > 0) {
+ new CopyFilesAndFoldersOperation(mShell).copyFiles(fileData, getNewParent());
+ }
+ }
+ }
+
+
+ @Override
+ protected boolean updateSelection(IStructuredSelection selection) {
+
+ IResource[] resources = (IResource[]) mClipboard
+ .getContents(ResourceTransfer.getInstance());
+
+ String[] files = (String[]) mClipboard.getContents(FileTransfer.getInstance());
+
+ if (resources == null && files == null) {
+ return false;
+ }
+// else if (resources.length == 0 && files.length == 0) {
+// return false;
+// }
+
+ if (resources != null ) {
+ if (resources[0].getType() == IResource.PROJECT) {
+
+ for (IResource resource : resources) {
+ if (resource.getType() == IResource.PROJECT
+ && !((IProject) resource).isOpen()) {
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ if (getSelectedNonResources().size() > 0) {
+ return false;
+ } else if (getSelectedResources().size() != 1) {
+ return false;
+ }
+
+ // linked resources are not supported
+ for (IResource resource : resources) {
+ if (resource.isLinked()) {
+ return false;
+ }
+ }
+
+ // if parent is project make sure its open
+ IResource parent = getNewParent();
+
+ if (parent instanceof IProject) {
+ IProject parentProject = (IProject) parent;
+
+ if (!parentProject.isOpen()) {
+ return false;
+ }
+ }
+
+ // do not copy folder to itself
+ for (IResource resource : resources) {
+ if (resource.equals(parent)) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+ }
+}
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/RefactorGroup.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/RefactorGroup.java?rev=760383&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/RefactorGroup.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/RefactorGroup.java Tue Mar 31 09:54:43 2009
@@ -0,0 +1,213 @@
+/*
+ * 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.corpusview;
+
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.dnd.Clipboard;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.actions.ActionGroup;
+import org.eclipse.ui.actions.DeleteResourceAction;
+import org.eclipse.ui.actions.RenameResourceAction;
+import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
+
+/**
+ * This group contains refactoring actions.
+ */
+final class RefactorGroup extends ActionGroup {
+
+ /**
+ * The Clipboard for the copy/paste actions. Must be disposed!
+ */
+ private Clipboard mClipboard;
+
+ /**
+ * Action that actually copy the resource.
+ */
+ private CopyAction mCopyAction;
+
+ /**
+ * The copy retarget action
+ */
+ private IWorkbenchAction mRetargetCopyAction;
+
+ /**
+ * Action that actually paste the resource.
+ */
+ private PasteAction mPasteAction;
+
+ /**
+ * The paste retarget action.
+ */
+ private IWorkbenchAction mRetargetPasteAction;
+
+ /**
+ * Action that actually delete the resource.
+ */
+ private DeleteResourceAction mDeleteAction;
+
+ /**
+ * The delete retarget action.
+ */
+ private IWorkbenchAction mRetargetDeleteAction;
+
+ /**
+ * Action that actually rename the resource.
+ */
+ private RenameResourceAction mRenameAction;
+
+ /**
+ * The rename retarget action.
+ */
+ private IWorkbenchAction mRetargetRenameAction;
+
+ /**
+ * Initializes a new instance.
+ *
+ * @param shell
+ * @param window
+ */
+ RefactorGroup(Shell shell, IWorkbenchWindow window) {
+ mClipboard = new Clipboard(shell.getDisplay());
+
+ // copy action
+ mCopyAction = new CopyAction(mClipboard);
+
+ mRetargetCopyAction = ActionFactory.COPY.create(window);
+
+ // paste action
+ mPasteAction = new PasteAction(shell, mClipboard);
+
+ mRetargetPasteAction = ActionFactory.PASTE.create(window);
+
+ // delete action
+ mDeleteAction = new DeleteResourceAction(shell);
+
+ mRetargetDeleteAction = ActionFactory.DELETE.create(window);
+
+ // rename action
+ mRenameAction = new RenameResourceAction(shell);
+
+ mRetargetRenameAction = ActionFactory.RENAME.create(window);
+ }
+
+ /**
+ * Fills the context menu with actions.
+ */
+ @Override
+ public void fillContextMenu(IMenuManager menu) {
+ IStructuredSelection selection = CorpusExplorerUtil
+ .convertNLPElementsToResources((IStructuredSelection) getContext().getSelection());
+
+ boolean isAResourceSelected = !selection.isEmpty();
+
+ // Order as in "Eclipse User Interface Guidelines":
+
+ // 1. Cut
+
+ // 2. Copy
+ menu.add(mRetargetCopyAction);
+
+ // 3. Paste
+ menu.add(mRetargetPasteAction);
+
+ // 4. Delete
+ if (isAResourceSelected) {
+ menu.add(mRetargetDeleteAction);
+ }
+
+ // 5. Move
+ // menu.add(ActionFactory.MOVE.create(mWindow));
+
+ // 6. Rename
+ if (selection.size() == 1) {
+ menu.add(mRetargetRenameAction);
+ }
+
+ // 7. other refactoring commands
+ }
+
+ /**
+ * Fill the ActionBars with defined actions.
+ */
+ @Override
+ public void fillActionBars(IActionBars actionBars) {
+ actionBars.setGlobalActionHandler(ActionFactory.DELETE.getId(), mDeleteAction);
+
+ actionBars.setGlobalActionHandler(ActionFactory.COPY.getId(), mCopyAction);
+
+ actionBars.setGlobalActionHandler(ActionFactory.PASTE.getId(), mPasteAction);
+
+ actionBars.setGlobalActionHandler(ActionFactory.RENAME.getId(), mRenameAction);
+
+ actionBars.updateActionBars();
+ }
+
+ /**
+ * Update the selection of the actions.
+ */
+ @Override
+ public void updateActionBars() {
+ super.updateActionBars();
+
+ IStructuredSelection selection = CorpusExplorerUtil
+ .convertNLPElementsToResources((IStructuredSelection) getContext().getSelection());
+
+ mCopyAction.selectionChanged(selection);
+ mPasteAction.selectionChanged(selection);
+ mDeleteAction.selectionChanged(selection);
+ mRenameAction.selectionChanged(selection);
+ }
+
+ void handleKeyPressed(KeyEvent e) {
+ if (e.keyCode == SWT.F2 && e.stateMask == 0) {
+ if (mRenameAction.isEnabled()) {
+ mRenameAction.run();
+ e.doit = false;
+ }
+ }
+ else if (e.keyCode == SWT.DEL && e.stateMask == 0) {
+ if (mDeleteAction.isEnabled()) {
+ mDeleteAction.run();
+ e.doit = false;
+ }
+ }
+ }
+
+ /**
+ * Destroy all swt elements which where created by this instance.
+ */
+ @Override
+ public void dispose() {
+
+ mClipboard.dispose();
+ mRetargetCopyAction.dispose();
+ mRetargetPasteAction.dispose();
+ mRetargetDeleteAction.dispose();
+ mRetargetRenameAction.dispose();
+
+ super.dispose();
+ }
+}
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/ResourceAction.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/ResourceAction.java?rev=760383&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/ResourceAction.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/ResourceAction.java Tue Mar 31 09:54:43 2009
@@ -0,0 +1,113 @@
+/*
+ * 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.corpusview;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.ui.actions.BaseSelectionListenerAction;
+
+/**
+ * Base class for actions which dependent on {@link IResource} selections.
+ */
+public abstract class ResourceAction extends BaseSelectionListenerAction {
+
+ protected ResourceAction(String text) {
+ super(text);
+ }
+
+ /**
+ * Retrieves all selected items which are not {@link IResource}s.
+ *
+ * @return selected item which are not a {@link IResource}s
+ */
+ protected List<Object> getSelectedNonResources() {
+ List<Object> nonResources = new ArrayList<Object>();
+
+ for (Iterator it = getStructuredSelection().iterator(); it.hasNext(); ) {
+
+ Object selection = it.next();
+
+ if (selection instanceof IAdaptable) {
+ IAdaptable adapter = (IAdaptable) selection;
+
+ IResource resource = (IResource) adapter.getAdapter(IResource.class);
+
+ if (resource == null) {
+ nonResources.add(selection);
+ }
+ }
+ else if (!(selection instanceof IResource)) {
+ nonResources.add(selection);
+ }
+ }
+
+ return nonResources;
+ }
+
+ /**
+ * Retrieves all selected {@link IResource} items.
+ *
+ * @return all selected {@link IResource} items
+ */
+ protected List<IResource> getSelectedResources() {
+
+ List<IResource> resources = new ArrayList<IResource>();
+
+ for (Iterator it = getStructuredSelection().iterator(); it.hasNext(); ) {
+ Object selection = it.next();
+
+ if (selection instanceof IResource) {
+ resources.add((IResource) selection);
+ } else if (selection instanceof IAdaptable) {
+ IAdaptable adapter = (IAdaptable) selection;
+
+ IResource resource = (IResource) adapter.getAdapter(IResource.class);
+
+ if (resource != null) {
+ resources.add(resource);
+ }
+ }
+ }
+
+ return resources;
+ }
+
+ protected boolean resourceIsType(IResource resource, int resourceMask) {
+ return (resource.getType() & resourceMask) != 0;
+ }
+
+ protected boolean selectionIsOfType(int resourceMask) {
+ if (getSelectedNonResources().size() > 0) {
+ return false;
+ }
+
+ for (Object element : getSelectedResources()) {
+ IResource next = (IResource) element;
+ if (!resourceIsType(next, resourceMask)) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/UimaRefactorActionGroup.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/UimaRefactorActionGroup.java?rev=760383&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/UimaRefactorActionGroup.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/UimaRefactorActionGroup.java Tue Mar 31 09:54:43 2009
@@ -0,0 +1,81 @@
+/*
+ * 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.corpusview;
+
+import java.util.Iterator;
+import java.util.LinkedList;
+
+import org.apache.uima.caseditor.core.model.CorpusElement;
+import org.apache.uima.caseditor.core.model.DocumentElement;
+import org.apache.uima.caseditor.ui.action.CleanDocumentActionRunnable;
+import org.apache.uima.caseditor.ui.action.RunnableAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.operation.IRunnableWithProgress;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.actions.ActionGroup;
+
+public class UimaRefactorActionGroup extends ActionGroup {
+
+ private Shell shell;
+
+ /**
+ * Initializes the current instance with the given shell.
+ *
+ * @param shell
+ */
+ UimaRefactorActionGroup(Shell shell) {
+ this.shell = shell;
+ }
+
+
+ @Override
+ public void fillContextMenu(IMenuManager menu) {
+ IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
+
+ LinkedList<DocumentElement> documentElements = new LinkedList<DocumentElement>();
+
+ if (!CorpusExplorerUtil.isContaingNLPProjectOrNonNLPResources(selection)) {
+ Iterator resources = selection.iterator();
+ while (resources.hasNext()) {
+ Object resource = resources.next();
+
+ if (resource instanceof CorpusElement) {
+ documentElements.addAll(((CorpusElement) resource).getDocuments());
+ }
+
+ if (resource instanceof DocumentElement) {
+ documentElements.add(((DocumentElement) resource));
+ }
+ }
+ }
+
+ if (!documentElements.isEmpty()) {
+
+ IRunnableWithProgress annotatorRunnableAction = new CleanDocumentActionRunnable(
+ documentElements);
+
+ RunnableAction annotatorAction = new RunnableAction(shell, "Clean documents",
+ annotatorRunnableAction);
+
+ menu.add(annotatorAction);
+ }
+ }
+}
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/WorkspaceActionGroup.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/WorkspaceActionGroup.java?rev=760383&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/WorkspaceActionGroup.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/WorkspaceActionGroup.java Tue Mar 31 09:54:43 2009
@@ -0,0 +1,210 @@
+/*
+ * 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.corpusview;
+
+import java.util.Iterator;
+
+import org.apache.uima.caseditor.CasEditorPlugin;
+import org.apache.uima.caseditor.Images;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.IMenuManager;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IActionBars;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.actions.ActionFactory;
+import org.eclipse.ui.actions.ActionGroup;
+import org.eclipse.ui.actions.CloseResourceAction;
+import org.eclipse.ui.actions.OpenResourceAction;
+import org.eclipse.ui.actions.RefreshAction;
+
+/**
+ * This group contains workspace actions.
+ */
+final class WorkspaceActionGroup extends ActionGroup
+{
+
+ /**
+ * The action to actually open resources.
+ */
+ private OpenResourceAction mOpenProjectAction;
+
+ /**
+ * The action to actually close resources.
+ */
+ private CloseResourceAction mCloseProjectAction;
+
+ /**
+ * Action to actually refresh resources.
+ */
+ private RefreshAction mRefreshAction;
+
+ /**
+ * The retarget action to refresh.
+ */
+ private IAction mRetargetRefreshAction;
+
+ /**
+ * Initializes a new instance.
+ *
+ * @param shell
+ * @param window
+ */
+ WorkspaceActionGroup(Shell shell, IWorkbenchWindow window)
+ {
+ // open
+ // mOpenProjectAction = new OpenResourceAction(shell);
+ mOpenProjectAction = new OpenResourceAction(shell);
+
+ // close
+ mCloseProjectAction = new CloseResourceAction(shell);
+
+ // refresh
+ mRefreshAction = new RefreshAction(shell);
+
+ mRetargetRefreshAction = ActionFactory.REFRESH.create(window);
+
+ mRetargetRefreshAction.setImageDescriptor(
+ CasEditorPlugin.getTaeImageDescriptor(
+ Images.EXPLORER_E_REFRESH));
+
+ mRetargetRefreshAction.setDisabledImageDescriptor(
+ CasEditorPlugin.getTaeImageDescriptor(
+ Images.EXPLORER_D_REFRESH));
+ }
+
+ /**
+ * Fills the context menu with the actions.
+ */
+ @Override
+ public void fillContextMenu(IMenuManager menu)
+ {
+ IStructuredSelection selection = CorpusExplorerUtil
+ .convertNLPElementsToResources((IStructuredSelection) getContext()
+ .getSelection());
+
+ boolean hasOnlyProjectSelections = true;
+
+ boolean hasOpenProjects = false;
+ boolean hasClosedProjects = false;
+
+ boolean isEverythingKnown = false;
+
+ Iterator resources = selection.iterator();
+
+ while (resources.hasNext() && !isEverythingKnown)
+ {
+ isEverythingKnown = !hasOnlyProjectSelections && hasOpenProjects
+ && hasClosedProjects;
+
+ IResource resource = (IResource) resources.next();
+
+ boolean isProjectSelection = resource instanceof IProject;
+
+ if (!isProjectSelection)
+ {
+ hasOnlyProjectSelections = false;
+ continue;
+ }
+
+ IProject project = (IProject) resource;
+
+ if (project.isOpen())
+ {
+ hasOpenProjects = true;
+ }
+ else
+ {
+ hasClosedProjects = true;
+ }
+ }
+
+ // if nothing is closed add the refresh action
+ if (!hasClosedProjects)
+ {
+ menu.add(mRetargetRefreshAction);
+ }
+
+ // do not run project open/close actions if anyting
+ // else than a project is selected
+ if (hasOnlyProjectSelections)
+ {
+
+ if (hasOpenProjects)
+ {
+ // open projects can be closed
+ menu.add(mCloseProjectAction);
+ }
+
+ if (hasClosedProjects)
+ {
+ menu.add(mOpenProjectAction);
+ }
+
+ return;
+ }
+
+ }
+
+ /**
+ * Fills the action bars.
+ */
+ @Override
+ public void fillActionBars(IActionBars actionBars)
+ {
+ // actionBars.setGlobalActionHandler(
+ // IDEActionFactory.OPEN_PROJECT.getId(), mOpenProjectAction);
+
+ // actionBars.setGlobalActionHandler(IDEActionFactory.CLOSE_PROJECT
+ // .getId(), mCloseProjectAction);
+
+ actionBars.setGlobalActionHandler(ActionFactory.REFRESH.getId(),
+ mRefreshAction);
+
+ actionBars.updateActionBars();
+ }
+
+ void handleKeyPressed(KeyEvent e) {
+ if (e.keyCode == SWT.F5 && e.stateMask == 0) {
+ if (mRefreshAction.isEnabled()) {
+ mRefreshAction.run();
+ e.doit = false;
+ }
+ }
+ }
+
+ /**
+ * Updates the action.
+ */
+ @Override
+ public void updateActionBars()
+ {
+ IStructuredSelection selection = (IStructuredSelection) getContext()
+ .getSelection();
+
+ mCloseProjectAction.selectionChanged(selection);
+ mOpenProjectAction.selectionChanged(selection);
+ mRefreshAction.selectionChanged(selection);
+ }
+}
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/package.html
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/package.html?rev=760383&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/package.html (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/corpusview/package.html Tue Mar 31 09:54:43 2009
@@ -0,0 +1,32 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+ <!--
+ ***************************************************************
+ * 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.
+ ***************************************************************
+ -->
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
+ <head>
+ <title>org.apache.uima.caseditor.corpusview</title>
+ </head>
+
+ <body>
+ <p>This package contains the corpus viewer classes.</p>
+ </body>
+</html>
\ No newline at end of file
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/AbstractElementAdapter.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/AbstractElementAdapter.java?rev=760383&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/AbstractElementAdapter.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/AbstractElementAdapter.java Tue Mar 31 09:54:43 2009
@@ -0,0 +1,51 @@
+/*
+ * 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.model;
+
+
+import org.apache.uima.caseditor.core.model.INlpElement;
+import org.eclipse.ui.model.IWorkbenchAdapter;
+
+/**
+ * The abstract base class for all NLPElement based
+ * <code>IWorkbenchAdapter</code>s.
+ */
+abstract class AbstractElementAdapter implements IWorkbenchAdapter
+{
+ /**
+ * Retrieves the name of the element.
+ */
+ public String getLabel(Object o)
+ {
+ INlpElement element = (INlpElement) o;
+
+ return element.getName();
+ }
+
+ /**
+ * Retrieves the parent element;
+ */
+ public Object getParent(Object o)
+ {
+ INlpElement element = (INlpElement) o;
+
+ return element.getParent();
+ }
+}
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/CorpusAdapter.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/CorpusAdapter.java?rev=760383&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/CorpusAdapter.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/CorpusAdapter.java Tue Mar 31 09:54:43 2009
@@ -0,0 +1,56 @@
+/*
+ * 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.model;
+
+
+import org.apache.uima.caseditor.CasEditorPlugin;
+import org.apache.uima.caseditor.Images;
+import org.apache.uima.caseditor.core.model.CorpusElement;
+import org.apache.uima.caseditor.core.model.DocumentElement;
+import org.eclipse.jface.resource.ImageDescriptor;
+
+/**
+ * This is the IWorkbenchAdapter for the CorpusElement.
+ */
+class CorpusAdapter extends
+ AbstractElementAdapter
+{
+ /**
+ * Retrieves all documents (children) of the current
+ * CorpusElement instance.
+ */
+ public Object[] getChildren(Object o)
+ {
+ CorpusElement corpus = (CorpusElement) o;
+
+ DocumentElement[] documentElements = new DocumentElement[corpus
+ .getDocuments().size()];
+
+ return corpus.getDocuments().toArray(documentElements);
+ }
+
+ /**
+ * Retrieves the image {@link ImageDescriptor} for the CorpusElement.
+ */
+ public ImageDescriptor getImageDescriptor(Object object)
+ {
+ return CasEditorPlugin.getTaeImageDescriptor(Images.MODEL_CORPUS);
+ }
+}
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/ElementWorkbenchAdapterFactory.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/ElementWorkbenchAdapterFactory.java?rev=760383&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/ElementWorkbenchAdapterFactory.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/ElementWorkbenchAdapterFactory.java Tue Mar 31 09:54:43 2009
@@ -0,0 +1,78 @@
+/*
+ * 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.model;
+
+import org.apache.uima.caseditor.core.model.CasProcessorFolder;
+import org.apache.uima.caseditor.core.model.CorpusElement;
+import org.apache.uima.caseditor.core.model.NlpModel;
+import org.apache.uima.caseditor.core.model.NlpProject;
+import org.apache.uima.caseditor.core.model.TypesystemElement;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.IAdapterFactory;
+import org.eclipse.ui.model.IWorkbenchAdapter;
+
+public class ElementWorkbenchAdapterFactory implements IAdapterFactory {
+ private IWorkbenchAdapter mModelAdapter = new ModelAdapter();
+
+ private IWorkbenchAdapter mProjectAdapter = new ProjectAdapter();
+
+ private IWorkbenchAdapter mCorpusAdapter = new CorpusAdapter();
+
+ private IWorkbenchAdapter mUimaSourceFolderAdapter = new ProcessorFolderAdapter();
+
+ private IWorkbenchAdapter mSingleElementAdapter = new SingleElementAdapter();
+
+ private IWorkbenchAdapter mTypesystemAdapter = new TypesystemAdapter();
+
+ private IWorkbenchAdapter mFileAdapter = new FileAdapter();
+
+ private IWorkbenchAdapter mFolderAdapter = new FolderAdpater();
+
+ private IWorkbenchAdapter mSimpleProject = new SimpleProjectAdapter();
+
+ public Object getAdapter(Object adaptableObject, Class adapterType) {
+ if (adaptableObject instanceof NlpModel) {
+ return mModelAdapter;
+ } else if (adaptableObject instanceof NlpProject) {
+ return mProjectAdapter;
+ } else if (adaptableObject instanceof CorpusElement) {
+ return mCorpusAdapter;
+ } else if (adaptableObject instanceof CasProcessorFolder) {
+ return mUimaSourceFolderAdapter;
+ } else if (adaptableObject instanceof TypesystemElement) {
+ return mTypesystemAdapter;
+ } else if (adaptableObject instanceof IFile) {
+ return mFileAdapter;
+ } else if (adaptableObject instanceof IFolder) {
+ return mFolderAdapter;
+ } else if (adaptableObject instanceof IProject) {
+ return mSimpleProject;
+ } else {
+ return mSingleElementAdapter;
+ }
+ }
+
+ public Class[] getAdapterList() {
+ return new Class[] { IWorkbenchAdapter.class };
+
+ }
+}
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/FileAdapter.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/FileAdapter.java?rev=760383&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/FileAdapter.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/FileAdapter.java Tue Mar 31 09:54:43 2009
@@ -0,0 +1,71 @@
+/*
+ * 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.model;
+
+import org.apache.uima.caseditor.CasEditorPlugin;
+import org.apache.uima.caseditor.core.model.INlpElement;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.model.IWorkbenchAdapter;
+
+public class FileAdapter implements IWorkbenchAdapter {
+
+ public Object[] getChildren(Object o) {
+ return new Object[] {};
+ }
+
+ public ImageDescriptor getImageDescriptor(Object object) {
+
+ ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
+ return sharedImages.getImageDescriptor(ISharedImages.IMG_OBJ_FILE);
+ }
+
+ public String getLabel(Object o) {
+ IFile file = (IFile) o;
+
+ return file.getName();
+ }
+
+ public Object getParent(Object o) {
+ IFile file = (IFile) o;
+
+ // first check if there is an nlp element parent,
+ // if this is not the case than use the resource parent
+
+ INlpElement parent;
+ try {
+ parent = org.apache.uima.caseditor.CasEditorPlugin.getNlpModel().getParent(file);
+ } catch (CoreException e) {
+ CasEditorPlugin.log(e);
+ parent = null;
+ }
+
+ if (parent != null) {
+ return parent;
+ }
+ else {
+ return file.getParent();
+ }
+ }
+
+}
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/FolderAdpater.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/FolderAdpater.java?rev=760383&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/FolderAdpater.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/FolderAdpater.java Tue Mar 31 09:54:43 2009
@@ -0,0 +1,77 @@
+/*
+ * 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.model;
+
+import org.apache.uima.caseditor.CasEditorPlugin;
+import org.apache.uima.caseditor.core.model.INlpElement;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.ISharedImages;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.model.IWorkbenchAdapter;
+
+public class FolderAdpater implements IWorkbenchAdapter {
+
+ public Object[] getChildren(Object o) {
+ IFolder folder = (IFolder) o;
+
+ try {
+ return folder.members();
+ } catch (CoreException e) {
+ // TODO: log it
+ e.printStackTrace();
+ return null;
+ }
+ }
+
+ public ImageDescriptor getImageDescriptor(Object object) {
+ ISharedImages sharedImages = PlatformUI.getWorkbench().getSharedImages();
+ return sharedImages.getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER);
+ }
+
+ public String getLabel(Object o) {
+ IFolder folder = (IFolder) o;
+
+ return folder.getName();
+ }
+
+ public Object getParent(Object o) {
+ IFolder folder = (IFolder) o;
+
+ // first check if there is an nlp element parent,
+ // if this is not the case than use the resource parent
+
+ INlpElement parent;
+ try {
+ parent = org.apache.uima.caseditor.CasEditorPlugin.getNlpModel().getParent(folder);
+ } catch (CoreException e) {
+ CasEditorPlugin.log(e);
+ parent = null;
+ }
+
+ if (parent != null) {
+ return parent;
+ }
+ else {
+ return folder.getParent();
+ }
+ }
+}
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/ModelAdapter.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/ModelAdapter.java?rev=760383&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/ModelAdapter.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/ModelAdapter.java Tue Mar 31 09:54:43 2009
@@ -0,0 +1,67 @@
+/*
+ * 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.model;
+
+import java.util.Collections;
+import java.util.LinkedList;
+
+import org.apache.uima.caseditor.core.model.NlpModel;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.resource.ImageDescriptor;
+
+/**
+ * The <code>IWorkbenchAdapter</code> for the <code>NLPModel</code>.
+ */
+class ModelAdapter extends
+ AbstractElementAdapter
+{
+ /**
+ * Retrieves the children of the current <code>NLPModel</code> instance.
+ */
+ public Object[] getChildren(Object o)
+ {
+ NlpModel nlpModel = (NlpModel) o;
+
+ LinkedList<Object> elementList = new LinkedList<Object>();
+
+ Collections.addAll(elementList, nlpModel.getNlpProjects());
+
+ try
+ {
+ Collections.addAll(elementList, nlpModel.getNonNlpProjects());
+ }
+ catch (CoreException e)
+ {
+ e.printStackTrace();
+ }
+
+ return elementList.toArray();
+ }
+
+ /**
+ * No image available.
+ *
+ * @return null
+ */
+ public ImageDescriptor getImageDescriptor(Object object)
+ {
+ return null;
+ }
+}
Added: incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/ProcessorFolderAdapter.java
URL: http://svn.apache.org/viewvc/incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/ProcessorFolderAdapter.java?rev=760383&view=auto
==============================================================================
--- incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/ProcessorFolderAdapter.java (added)
+++ incubator/uima/sandbox/trunk/CasEditorEclipsePlugin/src/main/java/org/apache/uima/caseditor/ui/model/ProcessorFolderAdapter.java Tue Mar 31 09:54:43 2009
@@ -0,0 +1,71 @@
+/*
+ * 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.model;
+
+import java.util.Collection;
+import java.util.LinkedList;
+
+import org.apache.uima.caseditor.CasEditorPlugin;
+import org.apache.uima.caseditor.Images;
+import org.apache.uima.caseditor.core.model.CasProcessorFolder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jface.resource.ImageDescriptor;
+
+/**
+ * The <code>IWorkbenchAdapter</code> for the
+ * <code>UIMASourceFolder</code>.
+ */
+class ProcessorFolderAdapter extends
+ AbstractElementAdapter
+{
+ /**
+ * Retrieves the children of the current <code>UIMASourceFolder</code>.
+ */
+ public Object[] getChildren(Object o)
+ {
+ CasProcessorFolder sourceFolder = (CasProcessorFolder) o;
+
+ Collection<Object> childs = new LinkedList<Object>();
+
+ childs.addAll(sourceFolder.getAnnotators());
+
+ childs.addAll(sourceFolder.getConsumers());
+
+ try
+ {
+ childs.addAll(sourceFolder.getNonNlpResources());
+ }
+ catch (CoreException e)
+ {
+ // sorry this fails if the resource was already removed
+ }
+
+ return childs.toArray();
+ }
+
+ /**
+ * Retrieves the <code>ImageDescriptor</code> for uima folder.
+ */
+ public ImageDescriptor getImageDescriptor(Object object)
+ {
+ return CasEditorPlugin.getTaeImageDescriptor(
+ Images.MODEL_PROCESSOR_FOLDER);
+ }
+}