Project

General

Profile

« Previous | Next » 

Revision f13a970a

Added by Patrick Plitzner almost 7 years ago

ref #6596 Refactored selection handling to support e3 and e4 parts

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/AbstractUtility.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.model;
11 11

  
12
import java.lang.reflect.Field;
12 13
import java.lang.reflect.InvocationTargetException;
13 14
import java.util.ArrayList;
14 15
import java.util.Collection;
......
34 35
import org.eclipse.core.runtime.SubProgressMonitor;
35 36
import org.eclipse.core.runtime.jobs.ISchedulingRule;
36 37
import org.eclipse.core.runtime.jobs.Job;
38
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
37 39
import org.eclipse.jface.action.IStatusLineManager;
38 40
import org.eclipse.jface.operation.IRunnableWithProgress;
39 41
import org.eclipse.jface.resource.ColorRegistry;
......
53 55
import org.eclipse.ui.PlatformUI;
54 56
import org.eclipse.ui.handlers.IHandlerService;
55 57
import org.eclipse.ui.ide.undo.WorkspaceUndoUtil;
58
import org.eclipse.ui.internal.E4PartWrapper;
56 59
import org.eclipse.ui.part.EditorPart;
57 60
import org.eclipse.ui.progress.IProgressConstants;
58 61
import org.eclipse.ui.progress.IProgressService;
......
77 80
import eu.etaxonomy.taxeditor.view.supplementaldata.SupplementalDataViewPart;
78 81

  
79 82
/**
80
 * <p>
81
 * Abstract AbstractUtility class.
82
 * </p>
83 83
 *
84 84
 * @author n.hoffmann
85 85
 * @created 11.05.2009
......
93 93
    protected static IStatusLineManager statusLineManager;
94 94

  
95 95

  
96
    /**
97
     * <p>
98
     * closeAll
99
     * </p>
100
     *
101
     * @return a boolean.
102
     */
103 96
    public static boolean closeAll() {
104 97
        if(getActivePage()!=null){
105 98
            return getActivePage().closeAllEditors(true);
......
118 111
        return getActivePage() != null ? getActivePage().closeEditor(editor, true):false;
119 112
    }
120 113

  
121
    /**
122
     * <p>
123
     * getShell
124
     * </p>
125
     *
126
     * @return a {@link org.eclipse.swt.widgets.Shell} object.
127
     */
128 114
    public static Shell getShell() {
129 115

  
130 116
        return TaxeditorStorePlugin.getDefault().getWorkbench()
131 117
                .getActiveWorkbenchWindow().getShell();
132 118
    }
133 119

  
134
    /**
135
     * <p>
136
     * getActivePage
137
     * </p>
138
     *
139
     * @return a {@link org.eclipse.ui.IWorkbenchPage} object.
140
     */
141 120
    public static IWorkbenchPage getActivePage() {
142 121
        try{
143 122
            return TaxeditorStorePlugin.getDefault().getWorkbench()
......
147 126
        }
148 127
    }
149 128

  
150
    /**
151
     * <p>
152
     * getActivePart
153
     * </p>
154
     *
155
     * @return a {@link org.eclipse.ui.IWorkbenchPart} object.
156
     */
157
    public static IWorkbenchPart getActivePart() {
158
        return getActivePage() != null ? getActivePage().getActivePart() : null;
129
    public static IWorkbenchPart getActiveWorkbenchPart() {
130
        IWorkbenchPage activePage = getActivePage();
131
        if(activePage!=null){
132
            IWorkbenchPart activePart = activePage.getActivePart();
133
            if(activePart!=null){
134
                return activePart;
135
            }
136
        }
137
        return null;
138
    }
139

  
140
    public static Object getActiveE4Part() {
141
        IWorkbenchPage activePage = getActivePage();
142
        if(activePage!=null){
143
            IWorkbenchPart activePart = activePage.getActivePart();
144
            Object e4WrappedPart = getE4WrappedPart(activePart);
145
            return e4WrappedPart!=null?e4WrappedPart:activePart;
146
        }
147
        return null;
148
    }
149

  
150
    public static Object getE4WrappedPart(Object activePart){
151
        if(activePart instanceof E4PartWrapper){
152
            //FIXME can be removed when E4 migration is complete
153
            try {
154
                Field field = activePart.getClass().getDeclaredField("wrappedPart");
155
                field.setAccessible(true);
156
                Object object = field.get(activePart);
157
                if(object instanceof MPart){
158
                    return ((MPart) object).getObject();
159
                }
160
            } catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException e) {
161
                e.printStackTrace();
162
            }
163
        }
164
        return null;
159 165
    }
160 166

  
161 167
    public static IWorkbench getWorkbench() {
162 168
        return TaxeditorStorePlugin.getDefault().getWorkbench();
163 169
    }
164 170

  
165
    /**
166
     * <p>
167
     * getWorkbenchWindow
168
     * </p>
169
     *
170
     * @return a {@link org.eclipse.jface.window.ApplicationWindow} object.
171
     */
172 171
    public static IWorkbenchWindow getWorkbenchWindow() {
173 172
        if (getWorkbench().getWorkbenchWindowCount() > 1) {
174 173
            throw new IllegalStateException("More than one workbench window");
......
176 175
        return getWorkbench().getWorkbenchWindows()[0];
177 176
    }
178 177

  
179
    /**
180
     * <p>
181
     * showView
182
     * </p>
183
     *
184
     * @param id
185
     *            a {@link java.lang.String} object.
186
     * @return a {@link org.eclipse.ui.IViewPart} object.
187
     */
188 178
    public static IViewPart showView(String id) {
189 179
        try {
190 180
            return PlatformUI.getWorkbench().getActiveWorkbenchWindow()
......
196 186
        }
197 187
    }
198 188

  
199
    /**
200
     * <p>
201
     * hideView
202
     * </p>
203
     *
204
     * @param view
205
     *            a {@link org.eclipse.ui.IViewPart} object.
206
     */
207 189
    public static void hideView(IViewPart view) {
208 190
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
209 191
        .hideView(view);
210 192
    }
211 193

  
212
    /**
213
     * <p>
214
     * getView
215
     * </p>
216
     *
217
     * @param id
218
     *            a {@link java.lang.String} object.
219
     * @param restore
220
     *            a boolean.
221
     * @return a {@link org.eclipse.ui.IViewPart} object.
222
     */
223 194
    public static IViewPart getView(String id, boolean restore) {
224 195
    	IWorkbench workbench = PlatformUI.getWorkbench();
225 196
        IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
......
240 211
        return null;
241 212
    }
242 213

  
243
    /**
244
     * <p>
245
     * getService
246
     * </p>
247
     *
248
     * @param api
249
     *            a {@link java.lang.Class} object.
250
     * @return a {@link java.lang.Object} object.
251
     */
252 214
    public static Object getService(Class api) {
253 215
        return TaxeditorStorePlugin.getDefault().getWorkbench().getService(api);
254 216
    }
255 217

  
256
    /**
257
     * <p>
258
     * getCurrentTheme
259
     * </p>
260
     *
261
     * @return a {@link org.eclipse.ui.themes.ITheme} object.
262
     */
263 218
    public static ITheme getCurrentTheme() {
264 219
        IThemeManager themeManager = TaxeditorStorePlugin.getDefault()
265 220
                .getWorkbench().getThemeManager();
......
277 232
        return getCurrentTheme().getFontRegistry();
278 233
    }
279 234

  
280
    /**
281
     * <p>
282
     * getFont
283
     * </p>
284
     *
285
     * @param symbolicName
286
     *            a {@link java.lang.String} object.
287
     * @return a {@link org.eclipse.swt.graphics.Font} object.
288
     */
289 235
    public static Font getFont(String symbolicName) {
290 236
        return getFontRegistry().get(symbolicName);
291 237
    }
......
301 247
        return getCurrentTheme().getColorRegistry();
302 248
    }
303 249

  
304
    /**
305
     * <p>
306
     * getColor
307
     * </p>
308
     *
309
     * @param symbolicName
310
     *            a {@link java.lang.String} object.
311
     * @return a {@link org.eclipse.swt.graphics.Color} object.
312
     */
313 250
    public static Color getColor(String symbolicName) {
314 251
        return getColorRegistry().get(symbolicName);
315 252
    }
316 253

  
317
    /**
318
     * <p>
319
     * executeOperation
320
     * </p>
321
     *
322
     * @param operation
323
     *            a
324
     *            {@link eu.etaxonomy.taxeditor.operation.AbstractPostTaxonOperation}
325
     *            object.
326
     * @return a {@link org.eclipse.core.runtime.IStatus} object.
327
     */
328 254
    public static IStatus executeOperation(final AbstractPostOperation operation) {
329 255
        if (getOperationHistory() == null) {
330 256
            throw new IllegalArgumentException(
......
508 434
        return Status.OK_STATUS;
509 435
    }
510 436

  
511

  
512
    /**
513
     * <p>
514
     * getOperationHistory
515
     * </p>
516
     *
517
     * @return a {@link org.eclipse.core.commands.operations.IOperationHistory}
518
     *         object.
519
     */
520 437
    public static IOperationHistory getOperationHistory() {
521 438
        return getWorkbench().getOperationSupport().getOperationHistory();
522 439
    }
523 440

  
524
    /**
525
     * <p>
526
     * setStatusLine
527
     * </p>
528
     *
529
     * @param message
530
     *            a {@link java.lang.String} object.
531
     */
532 441
    public static void setStatusLine(final String message) {
533 442
        Display.getDefault().asyncExec(new Runnable() {
534 443

  
......
541 450

  
542 451
    }
543 452

  
544
    /**
545
     * <p>
546
     * getMonitor
547
     * </p>
548
     *
549
     * @return a {@link org.eclipse.core.runtime.IProgressMonitor} object.
550
     */
551 453
    public static IProgressMonitor getMonitor() {
552 454
        statusLineManager.setCancelEnabled(false);
553 455
        return statusLineManager.getProgressMonitor();
......
636 538
        getProgressService().busyCursorWhile(runnable);
637 539
    }
638 540

  
639
    /**
640
     * <p>
641
     * runInUI
642
     * </p>
643
     *
644
     * @see {@link IProgressService#runInUI(org.eclipse.jface.operation.IRunnableContext, IRunnableWithProgress, ISchedulingRule)}
645
     * @param runnable
646
     *            a {@link org.eclipse.jface.operation.IRunnableWithProgress}
647
     *            object.
648
     * @param rule
649
     *            a {@link org.eclipse.core.runtime.jobs.ISchedulingRule}
650
     *            object.
651
     * @throws java.lang.reflect.InvocationTargetException
652
     *             if any.
653
     * @throws java.lang.InterruptedException
654
     *             if any.
655
     */
656 541
    public static void runInUI(IRunnableWithProgress runnable,
657 542
            ISchedulingRule rule) throws InvocationTargetException,
658 543
            InterruptedException {
659 544
        getProgressService().runInUI(getWorkbenchWindow(), runnable, rule);
660 545
    }
661 546

  
662
    /**
663
     * <p>
664
     * run
665
     * </p>
666
     *
667
     * @param fork
668
     *            a boolean.
669
     * @param cancelable
670
     *            a boolean.
671
     * @param runnable
672
     *            a {@link org.eclipse.jface.operation.IRunnableWithProgress}
673
     *            object.
674
     * @throws java.lang.reflect.InvocationTargetException
675
     *             if any.
676
     * @throws java.lang.InterruptedException
677
     *             if any.
678
     */
679 547
    public static void run(boolean fork, boolean cancelable,
680 548
            IRunnableWithProgress runnable) throws InvocationTargetException,
681 549
            InterruptedException {
682 550
        getProgressService().run(fork, cancelable, runnable);
683 551
    }
684 552

  
685
    /**
686
     * <p>
687
     * getProgressService
688
     * </p>
689
     *
690
     * @return a {@link org.eclipse.ui.progress.IProgressService} object.
691
     */
692 553
    public static IProgressService getProgressService() {
693 554
        IWorkbench workbench = PlatformUI.getWorkbench();
694 555
        return workbench.getProgressService();
695 556
    }
696 557

  
697
    /**
698
     * <p>
699
     * getProgressService2
700
     * </p>
701
     *
702
     * @return a {@link org.eclipse.ui.progress.IWorkbenchSiteProgressService}
703
     *         object.
704
     */
705 558
    public static IWorkbenchSiteProgressService getProgressService2() {
706 559
        return (IWorkbenchSiteProgressService) getService(IWorkbenchSiteProgressService.class);
707 560
    }
708 561

  
709
    /**
710
     * <p>
711
     * getPluginId
712
     * </p>
713
     *
714
     * @return a {@link java.lang.String} object.
715
     */
716 562
    public static String getPluginId() {
717 563
        return "eu.taxeditor";
718 564
    }
719 565

  
720
    /**
721
     * <p>
722
     * getActiveEditor
723
     * </p>
724
     *
725
     * @return a {@link org.eclipse.ui.IEditorPart} object.
726
     */
727 566
    public static IEditorPart getActiveEditor() {
728 567
        return getActivePage() != null ? getActivePage().getActiveEditor()
729 568
                : null;
730 569
    }
731 570

  
732
    /**
733
     * <p>
734
     * getDetailsView
735
     * </p>
736
     *
737
     * @return a {@link eu.etaxonomy.taxeditor.view.detail.DetailsViewPart}
738
     *         object.
739
     */
571
    public static Object getActiveE4Editor() {
572
        if(getActivePage()!=null){
573
            IEditorPart activeEditor = getActivePage().getActiveEditor();
574
            Object wrappedPart = getE4WrappedPart(getActivePage().getActivePart());
575
            return wrappedPart!=null?wrappedPart:activeEditor;
576
        }
577
        return null;
578
    }
579

  
740 580
    public static DetailsViewPart getDetailsView() {
741 581
        return (DetailsViewPart) getView(DetailsViewPart.ID, false);
742 582
    }
743 583

  
744
    /**
745
     * <p>
746
     * refreshDetailsViewer
747
     * </p>
748
     */
749 584
    public static void refreshDetailsViewer() {
750 585
        if (getDetailsView() != null) {
751 586
            ((AbstractCdmDataViewer) getDetailsView().getViewer()).refresh();
752 587
        }
753 588
    }
754 589

  
755
    /**
756
     * <p>
757
     * reflowDetailsViewer
758
     * </p>
759
     */
760 590
    public static void reflowDetailsViewer() {
761 591
        if (getDetailsView() != null) {
762 592
            ((AbstractCdmDataViewer) getDetailsView().getViewer()).reflow();
......
870 700
        private final T term;
871 701
        private final TreeSet<TermNode<T>> children;
872 702

  
873
        /**
874
         * @param term
875
         * @param children
876
         */
877 703
        public TermNode(T term) {
878 704
            super();
879 705
            this.term = term;
......
884 710
            this.children.add(child);
885 711
        }
886 712

  
887
        /**
888
         * @return the children
889
         */
890 713
        public TreeSet<TermNode<T>> getChildren() {
891 714
            return children;
892 715
        }
893 716

  
894
        /**
895
         * @return the term
896
         */
897 717
        public T getTerm() {
898 718
            return term;
899 719
        }
900 720

  
901
        /* (non-Javadoc)
902
         * @see java.lang.Object#hashCode()
903
         */
904 721
        @Override
905 722
        public int hashCode() {
906 723
            final int prime = 31;
......
909 726
            return result;
910 727
        }
911 728

  
912
        /* (non-Javadoc)
913
         * @see java.lang.Object#equals(java.lang.Object)
914
         */
915 729
        @Override
916 730
        public boolean equals(Object obj) {
917 731
            if (this == obj) {
......
934 748
            return true;
935 749
        }
936 750

  
937
        /* (non-Javadoc)
938
         * @see java.lang.Comparable#compareTo(java.lang.Object)
939
         */
940 751
        @Override
941 752
        public int compareTo(TermNode<T> that) {
942 753
            return this.term.getMessage().compareTo(that.term.getMessage());

Also available in: Unified diff