-// $Id$
/**
-* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
-* http://www.e-taxonomy.eu
-*
-* The contents of this file are subject to the Mozilla Public License Version 1.1
-* See LICENSE.TXT at the top of this package for the full license terms.
-*/
+ * Copyright (C) 2007 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * The contents of this file are subject to the Mozilla Public License Version 1.1
+ * See LICENSE.TXT at the top of this package for the full license terms.
+ */
package eu.etaxonomy.taxeditor.view;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.swt.widgets.Label;
import org.eclipse.ui.ISelectionListener;
import org.eclipse.ui.ISelectionService;
-import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.part.PageBook;
import org.eclipse.ui.part.ViewPart;
import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
import eu.etaxonomy.cdm.model.common.CdmBase;
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
-import eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider;
+import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
-import eu.etaxonomy.taxeditor.store.StoreUtil;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
+import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
/**
* <p>Abstract AbstractCdmViewPart class.</p>
* @created Jun 15, 2010
* @version 1.0
*/
-public abstract class AbstractCdmViewPart extends ViewPart implements ISelectionListener, IPostOperationEnabled, IConversationEnabled, IDirtyMarkableSelectionProvider{
+public abstract class AbstractCdmViewPart extends ViewPart implements ISelectionListener, IPostOperationEnabled, IConversationEnabled, ICdmEntitySessionEnabled, IDirtyMarkable{
- protected ISelectionService selectionService;
+ protected ISelectionService selectionService;
- public static IStructuredSelection EMPTY_SELECTION = new StructuredSelection();
+ public static IStructuredSelection EMPTY_SELECTION = new StructuredSelection();
- protected IWorkbenchPart part;
+ protected Object part;
private PageBook pageBook;
- private Label emptySelectionLabel;
+ private Label emptySelectionLabel;
- private Composite viewerComposite;
+ private Composite viewerComposite;
- /** {@inheritDoc} */
- @Override
- public void createPartControl(Composite parent) {
- selectionService = getSite().getWorkbenchWindow().getSelectionService();
- selectionService.addSelectionListener(this);
+ /** {@inheritDoc} */
+ @Override
+ public void createPartControl(Composite parent) {
+ selectionService = getSite().getWorkbenchWindow().getSelectionService();
+ selectionService.addSelectionListener(this);
- pageBook = new PageBook(parent, SWT.NULL);
- createViewerComposite(pageBook);
- createViewer(viewerComposite);
+ pageBook = new PageBook(parent, SWT.NULL);
+ //create viewerComposite
+ viewerComposite = new SashForm(pageBook, SWT.HORIZONTAL);
+ createViewer(viewerComposite);
- // Page 2: Nothing selected
+ // Page 2: Nothing selected
emptySelectionLabel = new Label(pageBook, SWT.TOP + SWT.LEFT + SWT.WRAP);
setInitialSelection();
- }
-
- /**
- *
- */
- private void setInitialSelection() {
- selectionChanged(StoreUtil.getActivePart(), getInitialSelection());
- }
+ }
- /**
- * <p>getInitialSelection</p>
- *
- * @return a {@link org.eclipse.jface.viewers.ISelection} object.
- */
- protected ISelection getInitialSelection() {
- return selectionService.getSelection();
- }
+ private void setInitialSelection() {
+// selectionChanged(AbstractUtility.getActiveWorkbenchPart(), getInitialSelection());
+ }
- private void createViewerComposite(Composite parent) {
- viewerComposite = new SashForm(parent, SWT.HORIZONTAL);
- }
+ /**
+ * <p>getInitialSelection</p>
+ *
+ * @return a {@link org.eclipse.jface.viewers.ISelection} object.
+ */
+ protected ISelection getInitialSelection() {
+ return selectionService.getSelection();
+ }
- /**
- * <p>showEmptyPage</p>
- */
- public void showEmptyPage(){
- pageBook.showPage(emptySelectionLabel);
- }
+ /**
+ * <p>showEmptyPage</p>
+ */
+ public void showEmptyPage(){
+ setPartName(createPartTitle(null));
+ pageBook.showPage(emptySelectionLabel);
+ }
/**
* <p>showViewer</p>
* @param part a {@link org.eclipse.ui.IWorkbenchPart} object.
* @param selection a {@link org.eclipse.jface.viewers.ISelection} object.
*/
- public void showViewer(IWorkbenchPart part, IStructuredSelection selection){
- this.part = part;
+ public void showViewer(Object part, IStructuredSelection selection){
+ this.part = part;
- Object element = selection.getFirstElement();
-
- getViewer().setInput(element);
+ Object element = selection.getFirstElement();
+ //avoid widget is disposed exceptions
+ if (getViewer().getControl()==null || getViewer().getControl().isDisposed()){
+ return;
+ }
- showViewer();
+ setPartName(createPartTitle(element));
+ getViewer().setInput(element);
+ showViewer();
}
/**
*/
public abstract Viewer getViewer();
- /**
- * <p>showViewer</p>
- */
- public void showViewer(){
- pageBook.showPage(viewerComposite);
+ /**
+ * <p>showViewer</p>
+ */
+ public void showViewer(){
+ pageBook.showPage(viewerComposite);
}
- public void setEnabled(boolean enabled){
- pageBook.setEnabled(enabled);
- }
+ public void setEnabled(boolean enabled){
+ pageBook.setEnabled(enabled);
+ }
- /** {@inheritDoc} */
- @Override
- public void setFocus() {
- if(getConversationHolder() != null){
- getConversationHolder().bind();
- }
- getViewer().getControl().setFocus();
- }
+ /** {@inheritDoc} */
+ @Override
+ public void setFocus() {
+ if(getConversationHolder() != null){
+ getConversationHolder().bind();
+ }
+ if(getCdmEntitySession() != null){
+ getCdmEntitySession().bind();
+ }
+ getViewer().getControl().setFocus();
+ }
- /**
- * <p>createViewer</p>
- *
- * @param parent a {@link org.eclipse.swt.widgets.Composite} object.
- */
- public abstract void createViewer(Composite parent);
+ /**
+ * <p>createViewer</p>
+ *
+ * @param parent a {@link org.eclipse.swt.widgets.Composite} object.
+ */
+ public abstract void createViewer(Composite parent);
- /** {@inheritDoc} */
- @Override
+ /** {@inheritDoc} */
+ @Override
public boolean postOperation(CdmBase objectAffectedByOperation) {
- changed(objectAffectedByOperation);
- return true;
- }
+ changed(objectAffectedByOperation);
+ return true;
+ }
- /** {@inheritDoc} */
- @Override
+ /** {@inheritDoc} */
+ @Override
public abstract void changed(Object object);
- /**
- * <p>getConversationHolder</p>
- *
- * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
- */
- @Override
+ /**
+ * <p>getConversationHolder</p>
+ *
+ * @return a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
+ */
+ @Override
public ConversationHolder getConversationHolder() {
- if(part != null) {
+ if(part != null && part instanceof IConversationEnabled) {
return ((IConversationEnabled) part).getConversationHolder();
}
- return null;
- }
+ return null;
+ }
+
+ @Override
+ public ICdmEntitySession getCdmEntitySession() {
+ if(part != null && part instanceof ICdmEntitySessionEnabled) {
+ return ((ICdmEntitySessionEnabled) part).getCdmEntitySession();
+ }
+ return null;
+ }
- /** {@inheritDoc} */
- @Override
+ @Override
+ public List<? extends CdmBase> getRootEntities() {
+ return Arrays.asList((CdmBase)getViewer().getInput());
+ }
+
+ /** {@inheritDoc} */
+ @Override
public void update(CdmDataChangeMap changeEvents) {
- }
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void dispose() {
+ selectionService.removeSelectionListener(this);
+ super.dispose();
+ }
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.model.IDirtyMarkableSelectionProvider#forceDirty()
+ */
+ @Override
+ public void forceDirty() {
+ changed(null);
+ }
- /** {@inheritDoc} */
- @Override
- public void dispose() {
- selectionService.removeSelectionListener(this);
- super.dispose();
+
+ /* (non-Javadoc)
+ * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
+ */
+ @Override
+ public Map<Object, List<String>> getPropertyPathsMap() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ protected String createPartTitle(Object selectedObject){
+ if(selectedObject!=null){
+ return getViewName()+": "+selectedObject; //$NON-NLS-1$
+ }
+ return getViewName();
}
+
+ protected abstract String getViewName();
}