Project

General

Profile

« Previous | Next » 

Revision 75902572

Added by Katja Luther over 4 years ago

fix potential multiple representation exceptions in distribution editor, session dispose did not work

View differences:

eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistEditor.java
23 23
import org.eclipse.core.runtime.Status;
24 24
import org.eclipse.core.runtime.jobs.Job;
25 25
import org.eclipse.jface.viewers.ISelection;
26
import org.eclipse.jface.viewers.ISelectionChangedListener;
27
import org.eclipse.jface.viewers.IStructuredSelection;
28
import org.eclipse.jface.viewers.SelectionChangedEvent;
29 26
import org.eclipse.jface.viewers.StructuredViewer;
30 27
import org.eclipse.jface.viewers.TableViewer;
31 28
import org.eclipse.jface.viewers.TableViewerColumn;
......
33 30
import org.eclipse.swt.events.ModifyListener;
34 31
import org.eclipse.swt.events.SelectionAdapter;
35 32
import org.eclipse.swt.events.SelectionEvent;
36
import org.eclipse.swt.events.SelectionListener;
37 33
import org.eclipse.swt.layout.GridData;
38 34
import org.eclipse.swt.layout.GridLayout;
39 35
import org.eclipse.swt.widgets.Composite;
......
80 76
import eu.etaxonomy.taxeditor.model.MessagingUtils;
81 77
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
82 78
import eu.etaxonomy.taxeditor.preference.Resources;
83
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
84 79
import eu.etaxonomy.taxeditor.store.CdmStore;
85 80

  
86 81
/**
......
190 185

  
191 186
    private Label statusLabel;
192 187

  
193
    private ICdmEntitySession cdmEntitySession;
188
//    private ICdmEntitySession cdmEntitySession;
194 189

  
195 190
    private ChecklistLabelProvider labelProvider;
196 191

  
......
226 221
    /** {@inheritDoc} */
227 222
    @Override
228 223
    public void createPartControl(Composite parent) {
229
        service = (IWorkbenchSiteProgressService) getSite().getAdapter(IWorkbenchSiteProgressService.class);
224
        service = getSite().getAdapter(IWorkbenchSiteProgressService.class);
230 225
        taxonNodeService = CdmStore.getService(ITaxonNodeService.class);
231 226
        selectionService = getSite().getWorkbenchWindow().getSelectionService();
232 227
        selectionService.addSelectionListener(this);
233 228
        viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION);
234
      
229

  
235 230
//        viewer.addSelectionChangedListener(new ISelectionChangedListener() {
236 231
//        	  @Override
237 232
//        	  public void selectionChanged(SelectionChangedEvent event) {
......
240 235
//        	    // do something with it
241 236
//        	  }
242 237
//
243
//			
244
//        	}); 
238
//
239
//        	});
245 240
        labelProvider = new ChecklistLabelProvider(this.viewer);
246 241

  
247 242
        terms = labelProvider.getNamedAreas();
......
786 781
    public void changed(Object element) {
787 782
        if (element != null) {
788 783
            viewer.update(element, null);
784
            if (element instanceof Taxon){
785
                checklistEditorInput.addTaxonToSave((Taxon)element);
786
            }
789 787
            setDirty(true);
790 788
            firePropertyChange(PROP_DIRTY);
791 789
        }
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/ChecklistEditorInput.java
46 46

  
47 47
    private final ConversationHolder conversation;
48 48

  
49
    private List<TaxonBase> taxaToSave = new ArrayList();
50

  
49 51

  
50 52
    /**
51 53
     * Creates an editor input for the {@link ChecklistView} with the currently selected TaxonNode
......
130 132

  
131 133

  
132 134

  
133
    /* (non-Javadoc)
134
     * @see java.lang.Object#hashCode()
135
     */
136
    @Override
137
    public int hashCode() {
138
        final int prime = 31;
139
        int result = 1;
140
        result = prime * result + ((classification == null) ? 0 : classification.hashCode());
141
        result = prime * result + ((taxonNode == null) ? 0 : taxonNode.hashCode());
142
        return result;
143
    }
135
//    /* (non-Javadoc)
136
//     * @see java.lang.Object#hashCode()
137
//     */
138
//    @Override
139
//    public int hashCode() {
140
//        final int prime = 31;
141
//        int result = 1;
142
//        result = prime * result + ((classification == null) ? 0 : classification.hashCode());
143
//        result = prime * result + ((taxonNode == null) ? 0 : taxonNode.hashCode());
144
//        return result;
145
//    }
144 146

  
145 147
    /* (non-Javadoc)
146 148
     * @see java.lang.Object#equals(java.lang.Object)
......
184 186

  
185 187
    @Override
186 188
    public void merge() {
187
        CdmStore.getService(ITaxonService.class).merge(taxa, true);
189
        if (!getCdmEntitySession().isActive()){
190
            getCdmEntitySession().bind();
191
        }
192
        CdmStore.getService(ITaxonService.class).merge(taxaToSave, true);
188 193
    }
189 194

  
190 195
    /* (non-Javadoc)
......
254 259

  
255 260
	}
256 261

  
262

  
263
    /**
264
     * @param element
265
     */
266
    public void addTaxonToSave(Taxon element) {
267
        this.taxaToSave.add(element);
268

  
269
    }
270

  
257 271
//    @Override
258 272
//    public void dispose(){
259 273
//    	conversation.unbind();
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/checklist/e4/ChecklistEditorE4.java
51 51
import org.eclipse.swt.widgets.Text;
52 52
import org.eclipse.swt.widgets.ToolBar;
53 53
import org.eclipse.swt.widgets.ToolItem;
54
import org.eclipse.ui.IMemento;
55 54
import org.eclipse.ui.progress.IWorkbenchSiteProgressService;
56 55

  
57 56
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
......
59 58
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
60 59
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
61 60
import eu.etaxonomy.cdm.model.taxon.Classification;
61
import eu.etaxonomy.cdm.model.taxon.Taxon;
62 62
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
63 63
import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
64 64
import eu.etaxonomy.taxeditor.editor.EditorUtil;
......
72 72
import eu.etaxonomy.taxeditor.editor.view.checklist.filter.ChecklistEditorFilter;
73 73
import eu.etaxonomy.taxeditor.editor.view.checklist.listener.ChecklistFocusListener;
74 74
import eu.etaxonomy.taxeditor.editor.view.checklist.listener.ChecklistModifyListener;
75
import eu.etaxonomy.taxeditor.model.IContextListener;
76 75
import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
77 76
import eu.etaxonomy.taxeditor.model.IPartContentHasDetails;
78 77
import eu.etaxonomy.taxeditor.model.IPartContentHasFactualData;
......
88 87
 *
89 88
 */
90 89
public class ChecklistEditorE4 implements IPartContentHasFactualData, IConversationEnabled,
91
        IContextListener, IDirtyMarkable, IPartContentHasDetails, IE4SavablePart, IDistributionEditor{
90
       IDirtyMarkable, IPartContentHasDetails, IE4SavablePart, IDistributionEditor{
92 91

  
93 92
    private static final String DISTRIBUTION_EDITOR = "Distribution Editor";
94 93
	private static final String LOADING_TAXA = Messages.ChecklistEditor_LOAD_TAXA;
......
98 97

  
99 98
    private static final Logger logger = Logger.getLogger(ChecklistEditorE4.class);
100 99

  
101

  
102
//    private class ChecklistJob extends Job {
103
//
104
//        private List<TaxonNode> taxonNodes;
105
//
106
//        /**
107
//         * @param name
108
//         */
109
//        public ChecklistJob(String title, List<TaxonNode> listTaxonNodes) {
110
//            super(title);
111
//            this.taxonNodes = listTaxonNodes;
112
//
113
//
114
//        }
115
//
116
//        /*
117
//         * (non-Javadoc)
118
//         *
119
//         * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.
120
//         * IProgressMonitor)
121
//         */
122
//        @Override
123
//        public IStatus run(final IProgressMonitor monitor) {
124
//            try {
125
//                logger.debug("Begin of eclipse core runtime Job to Retrieve datasources"); //$NON-NLS-1$
126
//                monitor.beginTask(Messages.ChecklistEditor_RETRIEVE_NODES, taxonNodes.size() + 1);
127
//
128
//                final List<Taxon> taxonList = new ArrayList<Taxon>();
129
//
130
//                for (TaxonNode taxonNode : taxonNodes) {
131
//                    HibernateProxyHelper hh = new HibernateProxyHelper();
132
//                    Taxon taxon = hh.deproxy(taxonNode.getTaxon(), Taxon.class);
133
//                    taxonList.add(taxon);
134
//                }
135
//                // set View input
136
//                Display.getDefault().asyncExec(new Runnable() {
137
//
138
//                    @Override
139
//                    public void run() {
140
//                    	viewer.setInput(taxonList);
141
//                    }
142
//                });
143
//                monitor.worked(1);
144
//
145
//            } finally {
146
//                monitor.done();
147
//                taxonNodes = null;
148
//            }
149
//            return Status.OK_STATUS;
150
//        }
151
//    }
152

  
153 100
    /**
154 101
     * Constant
155 102
     * <code>ID="eu.etaxonomy.taxeditor.store.datasource"{trunked}</code>
......
158 105

  
159 106
    private TableViewer viewer;
160 107

  
161
    private String partNameCache;
162

  
163
    //FIXME E4 migrate/delete ater full migration
164

  
165
    private IWorkbenchSiteProgressService service;
166

  
167 108
    private ITaxonNodeService taxonNodeService;
168 109

  
169 110
    private ChecklistEditorComparator comparator;
......
189 130

  
190 131
    private ChecklistEditorFilter filter;
191 132

  
192
    private Menu headerMenu;
193

  
194 133
    private Label statusLabel;
195 134

  
196
   // private final ICdmEntitySession cdmEntitySession;
197

  
198 135
    private ChecklistLabelProvider labelProvider;
199 136

  
200 137
    private SortedSet<DefinedTermBase> terms = null;
......
510 447
        }
511 448
    }
512 449

  
513
    /** {@inheritDoc} */
450

  
514 451
    @PreDestroy
515 452
    public void dispose() {
516
//    	if(checklistEditorInput!=null){
517
//    		this.checklistEditorInput.getConversation().unregisterForDataStoreChanges(this.checklistEditorInput);
518
//    	}
519

  
520 453
    	if(conversation!=null){
521 454
    		conversation.unregisterForDataStoreChanges(this);
522
    		conversation.unbind();
523 455
    		conversation.close();
524 456
    	}
525 457
    	conversation = null;
526 458
    	if(checklistEditorInput!=null){
527 459
    	    checklistEditorInput.dispose();
528 460
    	}
461

  
529 462
    }
530 463

  
531 464
    /** {@inheritDoc} */
......
671 604
            if (!conversation.isBound()) {
672 605
                conversation.bind();
673 606
            }
674
           this.checklistEditorInput.merge();
675
            //this.checklistEditorInput.merge();
607

  
608
            this.checklistEditorInput.merge();
609

  
676 610
            conversation.commit(true);
677 611
            setDirty(false);
678 612
            monitor.worked(1);
......
697 631

  
698 632
        loadDataInput();
699 633
    }
700

  
701

  
702
    /*
703
     * (non-Javadoc)
704
     *
705
     * @see
706
     * eu.etaxonomy.taxeditor.model.IContextListener#contextAboutToStop(org.
707
     * eclipse.ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
708
     */
709

  
710
    @Override
711
    public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
712

  
713
    }
714

  
715
    /*
716
     * (non-Javadoc)
717
     *
718
     * @see
719
     * eu.etaxonomy.taxeditor.model.IContextListener#contextStop(org.eclipse
720
     * .ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
721
     */
722
    @Override
723
    public void contextStop(IMemento memento, IProgressMonitor monitor) {
724
//        IStructuredSelection sel = (IStructuredSelection) this.viewer.getSelection();
725
//        if (sel.isEmpty()) {
726
//            return;
727
//        }
728
//        memento = memento.createChild("tree-selections");
729
//        Iterator iter = sel.iterator();
730
//        while (iter.hasNext()) {
731
//            String nodeName = (String) iter.next();
732
//            memento.createChild("selected-nodes", nodeName);
733
//        }
734
    }
735

  
736
    /*
737
     * (non-Javadoc)
738
     *
739
     * @see
740
     * eu.etaxonomy.taxeditor.model.IContextListener#contextStart(org.eclipse
741
     * .ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
742
     */
743
    @Override
744
    public void contextStart(IMemento memento, IProgressMonitor monitor) {
745

  
746
    }
747

  
748
    /*
749
     * (non-Javadoc)
750
     *
751
     * @see
752
     * eu.etaxonomy.taxeditor.model.IContextListener#contextRefresh(org.eclipse
753
     * .core.runtime.IProgressMonitor)
754
     */
755
    @Override
756
    public void contextRefresh(IProgressMonitor monitor) {
757
    }
758

  
759
    /*
760
     * (non-Javadoc)
761
     *
762
     * @see
763
     * eu.etaxonomy.taxeditor.model.IContextListener#workbenchShutdown(org.eclipse
764
     * .ui.IMemento, org.eclipse.core.runtime.IProgressMonitor)
765
     */
766
    @Override
767
    public void workbenchShutdown(IMemento memento, IProgressMonitor monitor) {
768
    }
769

  
770 634
    private static final List<String> NODE_INIT_STRATEGY = Arrays.asList(new String[] { "descriptions", //$NON-NLS-1$
771 635
            "descriptions.*", "description.state", "feature", "feature.*", "childNodes", "childNodes.taxon", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
772 636
            "childNodes.taxon.name", "taxonNodes", "taxonNodes.*", "taxonNodes.taxon.*", "taxon.*", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
......
784 648
    public void changed(Object element) {
785 649
        if (element != null) {
786 650
            viewer.update(element, null);
651
            if (element instanceof Taxon){
652
                checklistEditorInput.addTaxonToSave((Taxon)element);
653
            }
787 654
            setDirty(true);
788 655
        }
789 656
    }
......
809 676
        return dirty.isDirty();
810 677
    }
811 678

  
812
    /* (non-Javadoc)
813
     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getCdmEntitySession()
814
     */
815

  
816

  
817
//    /* (non-Javadoc)
818
//     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getRootEntities()
819
//     */
820
//    @Override
821
//    public <T extends CdmBase> Collection<T> getRootEntities() {
822
//        // TODO Auto-generated method stub
823
//        return null;
824
//    }
825
//
826
//    /* (non-Javadoc)
827
//     * @see eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled#getPropertyPathsMap()
828
//     */
829
//    @Override
830
//    public Map<Object, List<String>> getPropertyPathsMap() {
831
//        // TODO Auto-generated method stub
832
//        return null;
833
//    }
834 679

  
835 680
    /**
836 681
     * @return the labelProvider
......
853 698
     */
854 699
    @Override
855 700
    public ConversationHolder getConversationHolder() {
856

  
857 701
        return conversation;
858 702
    }
859 703

  
......
864 708
    @Persist
865 709
    public void save(IProgressMonitor monitor) {
866 710
        doSave(monitor);
867

  
868 711
    }
869 712

  
870 713

  

Also available in: Unified diff