Project

General

Profile

Revision a5b67ac3

IDa5b67ac3d2e90ebe5c4fac0fd7d06fe22511926a
Parent d17343e9
Child 0e4f55de

Added by Patrick Plitzner about 3 years ago

fix #6912 Migrate DataSource view

View differences:

eu.etaxonomy.taxeditor.store/fragment.e4xmi
21 21
    </elements>
22 22
    <elements xsi:type="basic:PartDescriptor" xmi:id="_zTXhUGvBEeeNmdqhxF1CnA" elementId="eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4" label="%view.name.4" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/accessories-text-editor.png" closeable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.view.e4.details.DetailsPartE4"/>
23 23
    <elements xsi:type="basic:PartDescriptor" xmi:id="_coTYkH3eEeeVL5aZ55YsWA" elementId="eu.etaxonomy.taxeditor.view.e4.supplementaldata.SupplementalDataPartE4" label="%view.name.3" closeable="true" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.view.e4.supplementaldata.SupplementalDataPartE4"/>
24
    <elements xsi:type="basic:PartDescriptor" xmi:id="_eKzREIcpEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.view.datasource" label="%view.name" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/system-file-manager.png" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.view.datasource.e4.CdmDataSourceViewPartE4">
25
      <handlers xmi:id="_DINQoIctEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.view.datasource.e4.handler.ChangeConnectionHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.view.datasource.e4.handler.ChangeConnectionHandlerE4" command="_efb88IcsEee-HITNnU9cVw"/>
26
      <handlers xmi:id="_hAnq0IctEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.view.datasource.e4.handler.EditDataSourceHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.view.datasource.e4.handler.EditDataSourceHandlerE4" command="_cs5L0IctEee-HITNnU9cVw"/>
27
      <handlers xmi:id="_rsmsYIctEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.view.datasource.e4.handler.CloneDataSourceHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.view.datasource.e4.handler.CloneDataSourceHandlerE4" command="_o0HcUIctEee-HITNnU9cVw"/>
28
      <handlers xmi:id="_6VVQUIctEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.view.datasource.e4.handler.CreateDataSourceHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.view.datasource.e4.handler.CreateDataSourceHandlerE4" command="_yJiTkIctEee-HITNnU9cVw"/>
29
      <handlers xmi:id="_ASDGYIcuEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.view.datasource.e4.handler.DeleteDataSourceHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.view.datasource.e4.handler.DeleteDataSourceHandlerE4" command="_-g_YcIctEee-HITNnU9cVw"/>
30
      <handlers xmi:id="_T-pz4IcuEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.view.datasource.e4.handler.UpdateDataSourceHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.view.datasource.e4.handler.UpdateDataSourceHandlerE4" command="_ShWvcIcuEee-HITNnU9cVw"/>
31
      <menus xsi:type="menu:PopupMenu" xmi:id="_3aJ1cIcpEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.store.popupmenu.datasourceview">
32
        <children xsi:type="menu:HandledMenuItem" xmi:id="_7lX4sIcpEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.store.datasource.handledmenuitem.createModel" label="%command.label.6" command="_efb88IcsEee-HITNnU9cVw"/>
33
        <children xsi:type="menu:HandledMenuItem" xmi:id="_8D3ykIcpEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.store.datasource.handledmenuitem.newDataSource" label="%command.label.7" command="_yJiTkIctEee-HITNnU9cVw"/>
34
        <children xsi:type="menu:HandledMenuItem" xmi:id="_-ALHMIcpEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.store.datasource.handledmenuitem.edit" label="%command.label.8" command="_cs5L0IctEee-HITNnU9cVw"/>
35
        <children xsi:type="menu:HandledMenuItem" xmi:id="_8ciKMIcpEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.store.datasource.handledmenuitem.clone" label="%command.label.clone" command="_o0HcUIctEee-HITNnU9cVw"/>
36
        <children xsi:type="menu:MenuSeparator" xmi:id="_-6EjoIcpEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.store.menuseparator.1"/>
37
        <children xsi:type="menu:HandledMenuItem" xmi:id="__u4EsIcpEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.store.datasource.handledmenuitem.delete" label="%command.label.9" command="_-g_YcIctEee-HITNnU9cVw"/>
38
        <children xsi:type="menu:MenuSeparator" xmi:id="_AfzyYIcqEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.store.menuseparator.2"/>
39
        <children xsi:type="menu:HandledMenuItem" xmi:id="_BE4OUIcqEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.store.datasource.handledmenuitem.refresh" label="%command.label.11" command="_ShWvcIcuEee-HITNnU9cVw"/>
40
      </menus>
41
    </elements>
24 42
  </fragments>
25 43
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_3rW8wCXaEeex9MwMOgUeWw" featurename="children" parentElementId="eu.etaxonomy.taxeditor.menu.showView" positionInList="after:bulkeditor.menus.openmenu">
26 44
    <elements xsi:type="menu:HandledMenuItem" xmi:id="_K6sowCaGEeeTEd_pKXBflg" elementId="eu.etaxonomy.taxeditor.store.showViewMenu.details" label="%command.label.0" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/accessories-text-editor.png" command="_bnVKsCZxEeeQLpuomSmVoQ">
......
47 65
    <elements xsi:type="commands:Command" xmi:id="_oftL0GceEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.command.featureTree.addFeature" commandName="Add Feature" description="Add a feature to the feature tree"/>
48 66
    <elements xsi:type="commands:Command" xmi:id="_fNBtQGcjEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.command.featureTree.removeFeature" commandName="Remove Feature" description="Removes a feature from the feature tree"/>
49 67
    <elements xsi:type="commands:Command" xmi:id="_I_yx4GcqEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.command.featureTree.exportTree" commandName="Export Feature Tree"/>
68
    <elements xsi:type="commands:Command" xmi:id="_efb88IcsEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.store.datasource.change" commandName="%command.name"/>
69
    <elements xsi:type="commands:Command" xmi:id="_cs5L0IctEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.store.datasource.edit" commandName="%command.name.0"/>
70
    <elements xsi:type="commands:Command" xmi:id="_o0HcUIctEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.store.datasource.clone" commandName="%command.name.8"/>
71
    <elements xsi:type="commands:Command" xmi:id="_yJiTkIctEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.store.datasource.create" commandName="%command.name.1"/>
72
    <elements xsi:type="commands:Command" xmi:id="_-g_YcIctEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.view.datasource.delete" commandName="%command.name.13"/>
73
    <elements xsi:type="commands:Command" xmi:id="_ShWvcIcuEee-HITNnU9cVw" elementId="eu.etaxonomy.taxeditor.store.datasource.update" commandName="%command.name.3"/>
50 74
  </fragments>
51 75
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_swGH0GhvEee3K4uKJljEYg" featurename="handlers" parentElementId="org.eclipse.e4.legacy.ide.application">
52 76
    <elements xsi:type="commands:Handler" xmi:id="_rVEdIGcjEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.RemoveFeatureHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.handler.RemoveFeatureHandler" command="_fNBtQGcjEee0qLTtA2ZpVQ"/>
eu.etaxonomy.taxeditor.store/plugin.xml
235 235
   <extension
236 236
         point="org.eclipse.ui.views">
237 237
      <view
238
            class="eu.etaxonomy.taxeditor.view.datasource.CdmDataSourceViewPart"
239
            icon="icons/system-file-manager.png"
240
            id="eu.etaxonomy.taxeditor.view.datasource"
241
            name="%view.name"
242
            restorable="true">
243
      </view>
244
      <view
245 238
        allowMultiple="true"
246 239
        class="eu.etaxonomy.taxeditor.view.dataimport.SpecimenImportView"
247 240
        id="eu.etaxonomy.taxeditor.view.dataimport.SpecimenImportView"
......
561 554
         name="%extension.name.0"
562 555
         point="org.eclipse.ui.commands">
563 556
      <command
564
            defaultHandler="eu.etaxonomy.taxeditor.view.datasource.handler.ChangeConnectionHandler"
565
            id="eu.etaxonomy.taxeditor.store.datasource.change"
566
            name="%command.name">
567
      </command>
568
      <command
569
            defaultHandler="eu.etaxonomy.taxeditor.view.datasource.handler.EditDataSourceHandler"
570
            id="eu.etaxonomy.taxeditor.store.datasource.edit"
571
            name="%command.name.0">
572
      </command>
573
      <command
574
            defaultHandler="eu.etaxonomy.taxeditor.view.datasource.handler.CloneDataSourceHandler"
575
            id="eu.etaxonomy.taxeditor.store.datasource.clone"
576
            name="%command.name.8">
577
      </command>
578
      <command
579
            defaultHandler="eu.etaxonomy.taxeditor.view.datasource.handler.CreateDataSourceHandler"
580
            id="eu.etaxonomy.taxeditor.store.datasource.create"
581
            name="%command.name.1">
582
      </command>
583
      <command
584
            defaultHandler="eu.etaxonomy.taxeditor.view.datasource.handler.DeleteDataSourceHandler"
585
            id="eu.etaxonomy.taxeditor.view.datasource.delete"
586
            name="%command.name.13">
587
      </command>
588
      <command
589
            defaultHandler="eu.etaxonomy.taxeditor.view.datasource.handler.UpdateDataSourceHandler"
590
            id="eu.etaxonomy.taxeditor.store.datasource.update"
591
            name="%command.name.3">
592
      </command>
593
      <command
594 557
            defaultHandler="eu.etaxonomy.taxeditor.handler.ShowLoginWindowHandler"
595 558
            id="eu.etaxonomy.taxeditor.store.operations.showLoginWindow"
596 559
            name="%command.name.4">
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/e4/CdmDataSourceViewPartE4.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

  
10
package eu.etaxonomy.taxeditor.view.datasource.e4;
11

  
12
import java.util.ArrayList;
13
import java.util.List;
14

  
15
import javax.annotation.PostConstruct;
16
import javax.annotation.PreDestroy;
17
import javax.inject.Inject;
18

  
19
import org.apache.log4j.Logger;
20
import org.eclipse.core.runtime.IProgressMonitor;
21
import org.eclipse.core.runtime.IStatus;
22
import org.eclipse.core.runtime.Status;
23
import org.eclipse.core.runtime.jobs.Job;
24
import org.eclipse.e4.ui.di.Focus;
25
import org.eclipse.e4.ui.services.EMenuService;
26
import org.eclipse.e4.ui.workbench.modeling.ESelectionService;
27
import org.eclipse.jface.viewers.ISelectionChangedListener;
28
import org.eclipse.jface.viewers.StructuredViewer;
29
import org.eclipse.jface.viewers.TableViewer;
30
import org.eclipse.jface.viewers.TableViewerColumn;
31
import org.eclipse.swt.SWT;
32
import org.eclipse.swt.events.SelectionAdapter;
33
import org.eclipse.swt.events.SelectionEvent;
34
import org.eclipse.swt.layout.FillLayout;
35
import org.eclipse.swt.widgets.Composite;
36
import org.eclipse.swt.widgets.Display;
37
import org.eclipse.swt.widgets.Table;
38
import org.eclipse.swt.widgets.TableColumn;
39
import org.eclipse.ui.IMemento;
40

  
41
import eu.etaxonomy.cdm.config.ICdmSource;
42
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
43
import eu.etaxonomy.taxeditor.l10n.Messages;
44
import eu.etaxonomy.taxeditor.model.AbstractUtility;
45
import eu.etaxonomy.taxeditor.model.ContextListenerAdapter;
46
import eu.etaxonomy.taxeditor.model.IContextListener;
47
import eu.etaxonomy.taxeditor.store.CdmStore;
48
import eu.etaxonomy.taxeditor.view.datasource.CdmDataSourceContentProvider;
49
import eu.etaxonomy.taxeditor.view.datasource.CdmDataSourceLabelProvider;
50
import eu.etaxonomy.taxeditor.view.datasource.CdmDataSourceViewerComparator;
51
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
52

  
53
/**
54
 *
55
 * @author pplitzner
56
 * @date 22.08.2017
57
 *
58
 */
59
public class CdmDataSourceViewPartE4 {
60

  
61
    private static final Logger logger = Logger.getLogger(CdmDataSourceViewPartE4.class);
62

  
63
	private class ContextListener extends ContextListenerAdapter{
64
		@Override
65
		public void contextAboutToStop(IMemento memento, IProgressMonitor monitor) {
66
			monitor.subTask("Refreshing Datasource View"); //$NON-NLS-1$
67
			viewer.refresh();
68
		}
69

  
70
		@Override
71
		public void contextStop(IMemento memento, IProgressMonitor monitor) {
72
			monitor.subTask("Refreshing Datasource View"); //$NON-NLS-1$
73
			viewer.refresh();
74
		}
75

  
76
		@Override
77
		public void contextStart(IMemento memento, IProgressMonitor monitor) {
78
			monitor.subTask("Refreshing Datasource View"); //$NON-NLS-1$
79
			viewer.refresh();
80
		}
81
	}
82

  
83
	private class DataSourceJob extends Job{
84

  
85
		private final List<ICdmSource> cdmSources;
86

  
87
		/**
88
		 * @param name
89
		 */
90
		public DataSourceJob(String title, List<ICdmSource> cdmSources) {
91
			super(title);
92
			this.cdmSources = cdmSources;
93
		}
94

  
95
		@Override
96
		public IStatus run(final IProgressMonitor monitor) {
97
			try{
98
				logger.debug("Begin of eclipse core runtime Job to Retrieve datasources"); //$NON-NLS-1$
99
				monitor.beginTask("Retrieving datasources", cdmSources.size() + 1);			 //$NON-NLS-1$
100

  
101
				final List<CdmMetaDataAwareDataSourceContainer> containers = new ArrayList<CdmMetaDataAwareDataSourceContainer>();
102

  
103
				for(ICdmSource cdmSource : cdmSources){
104
					containers.add(new CdmMetaDataAwareDataSourceContainer(cdmSource));
105
				}
106

  
107
				Display.getDefault().asyncExec(new Runnable() {
108

  
109
					@Override
110
					public void run() {
111
						viewer.setInput(containers);
112
					}
113
				});
114
				monitor.worked(1);
115

  
116
				for(final CdmMetaDataAwareDataSourceContainer container : containers){
117
					if(logger.isDebugEnabled()) {
118
                        logger.debug("  #" + container.hashCode() + " : next DataSourceContainer");						 //$NON-NLS-1$ //$NON-NLS-2$
119
                    }
120
					container.getMetaDataFromDataSource();
121
					if(logger.isDebugEnabled())
122
                     {
123
                        logger.debug("  #" + container.hashCode() + " : metadata retrieved, creating new runnable ...");	 //$NON-NLS-1$ //$NON-NLS-2$
124
                    }
125
					Display.getDefault().asyncExec(new Runnable() {
126

  
127
						@Override
128
						public void run() {
129
							if(logger.isDebugEnabled())
130
                             {
131
                                logger.debug("  #" + container.hashCode() + " starting sub thread to update ...");	 //$NON-NLS-1$ //$NON-NLS-2$
132
                            }
133
							viewer.update(container, null);
134
							if(logger.isDebugEnabled())
135
                             {
136
                                logger.debug("  #" + container.hashCode() + " end of sub thread to update ...");	 //$NON-NLS-1$ //$NON-NLS-2$
137
                            }
138
						}
139
					});
140
					if(logger.isDebugEnabled())
141
                     {
142
                        logger.debug("  #" + container.hashCode() + " done");	 //$NON-NLS-1$ //$NON-NLS-2$
143
                    }
144
					monitor.worked(1);
145
				}
146

  
147
			}finally{
148
				monitor.done();
149
			}
150
			return Status.OK_STATUS;
151
		}
152
	}
153

  
154
	private TableViewer viewer;
155

  
156
	//FIXME E4 migrate
157
//	private IWorkbenchSiteProgressService service;
158

  
159
	private IContextListener contextListener;
160

  
161
	private CdmDataSourceViewerComparator comparator;
162

  
163
	public CdmDataSourceViewPartE4(){
164
	}
165

  
166

  
167
    private ISelectionChangedListener selectionChangedListener;
168

  
169
    @Inject
170
    private ESelectionService selService;
171

  
172
    @PostConstruct
173
    public void create(Composite parent, EMenuService menuService) {
174
//		service = getSite().getAdapter(IWorkbenchSiteProgressService.class);
175
		contextListener = new ContextListener();
176
		CdmStore.getContextManager().addContextListener(contextListener);
177

  
178
		// Create top composite
179
		FillLayout fillLayout = new FillLayout();
180
		fillLayout.marginWidth = 0;
181
		fillLayout.marginHeight = 0;
182
		fillLayout.type = SWT.VERTICAL;
183
		parent.setLayout(fillLayout);
184

  
185
		viewer = new TableViewer(parent, SWT.MULTI | SWT.H_SCROLL
186
												| SWT.V_SCROLL | SWT.FULL_SELECTION);
187

  
188
		createColumns(viewer);
189

  
190
		viewer.setContentProvider(new CdmDataSourceContentProvider());
191
		viewer.setLabelProvider(new CdmDataSourceLabelProvider());
192
		comparator = new CdmDataSourceViewerComparator();
193
		viewer.setComparator(comparator);
194

  
195

  
196
        // Propagate selection from viewer
197
        selectionChangedListener = (event -> selService.setSelection(AbstractUtility.getElementsFromSelectionChangedEvent(event)));
198
        viewer.addSelectionChangedListener(selectionChangedListener);
199

  
200
        //create context menu
201
        menuService.registerContextMenu(viewer.getControl(), "eu.etaxonomy.taxeditor.store.popupmenu.datasourceview");
202

  
203
		refresh();
204
	}
205

  
206

  
207
	// This will create the columns for the table
208
	private void createColumns(TableViewer viewer) {
209
		Table table = viewer.getTable();
210
		String[] titles = {Messages.CdmDataSourceViewPart_12, Messages.CdmDataSourceViewPart_11, Messages.CdmDataSourceViewPart_10, Messages.CdmDataSourceViewPart_9, Messages.CdmDataSourceViewPart_8, Messages.CdmDataSourceViewPart_7, Messages.CdmDataSourceViewPart_5, Messages.CdmDataSourceViewPart_4, Messages.CdmDataSourceViewPart_3, Messages.CdmDataSourceViewPart_2};
211
		int[] bounds = { 24, 200, 100, 50 , 80, 120, 100, 100, 50, 300};
212

  
213
		for (int i = 0; i < titles.length; i++) {
214
			TableViewerColumn column = new TableViewerColumn(viewer, SWT.NONE);
215
			column.getColumn().setText(titles[i]);
216
			column.getColumn().setWidth(bounds[i]);
217
			column.getColumn().setResizable(true);
218
			column.getColumn().setMoveable(true);
219
			column.getColumn().addSelectionListener(getSelectionAdapter(column.getColumn(), i));
220
			if(i == 1){
221
				table.setSortColumn(column.getColumn());
222
			}
223
		}
224
		table.setHeaderVisible(true);
225
		table.setLinesVisible(true);
226
		table.setSortDirection(SWT.UP);
227

  
228
	}
229

  
230
	public void refresh(){
231
		DataSourceJob dataSourceJob = new DataSourceJob(Messages.CdmDataSourceViewPart_1, CdmDataSourceRepository.getAll());
232
		dataSourceJob.schedule();
233
	}
234

  
235
	/** {@inheritDoc} */
236
	@PreDestroy
237
	public void dispose() {
238
		CdmStore.getContextManager().removeContextListener(contextListener);
239
	}
240

  
241
	/** {@inheritDoc} */
242
	@Focus
243
	public void setFocus() {
244
		viewer.getControl().setFocus();
245
	}
246

  
247
	//FIXME E4 migrate
248
//	/** {@inheritDoc} */
249
//	@Override
250
//	public void showBusy(boolean busy) {
251
//		super.showBusy(busy);
252
////		viewer.getTable().setEnabled(!busy);
253
//		if(busy){
254
//			partNameCache = getPartName();
255
//			setPartName(Messages.CdmDataSourceViewPart_1);
256
//		}else{
257
//			if(partNameCache != null){
258
//				setPartName(partNameCache);
259
//			}
260
//		}
261
//	}
262

  
263
	public StructuredViewer getViewer() {
264
		return viewer;
265
	}
266

  
267
//	public IWorkbenchSiteProgressService getService() {
268
//		return service;
269
//	}
270

  
271
	private SelectionAdapter getSelectionAdapter(final TableColumn column,
272
			final int index) {
273
		SelectionAdapter selectionAdapter = new SelectionAdapter() {
274
			@Override
275
			public void widgetSelected(SelectionEvent e) {
276
				comparator.setColumn(index);
277
				int dir = viewer.getTable().getSortDirection();
278
				if (viewer.getTable().getSortColumn() == column) {
279
					dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
280
				} else {
281
					dir = SWT.DOWN;
282
				}
283
				viewer.getTable().setSortDirection(dir);
284
				viewer.getTable().setSortColumn(column);
285
				viewer.refresh();
286
			}
287
		};
288
		return selectionAdapter;
289
	}
290
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/e4/handler/AbstractDataSourceHandlerE4.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

  
10
package eu.etaxonomy.taxeditor.view.datasource.e4.handler;
11

  
12
import javax.inject.Named;
13

  
14
import org.eclipse.e4.core.di.annotations.Execute;
15
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
16
import org.eclipse.e4.ui.services.IServiceConstants;
17
import org.eclipse.e4.ui.workbench.modeling.EPartService;
18
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
19
import org.eclipse.swt.widgets.Shell;
20

  
21
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
22
import eu.etaxonomy.taxeditor.view.datasource.e4.CdmDataSourceViewPartE4;
23

  
24
/**
25
 *
26
 * @author pplitzner
27
 * @date 22.08.2017
28
 *
29
 */
30
abstract class AbstractDataSourceHandlerE4 {
31

  
32
	@Execute
33
    public void execute(EPartService partService,
34
            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
35
            @Named(IServiceConstants.ACTIVE_SELECTION)CdmMetaDataAwareDataSourceContainer container,
36
            MPart dataSourcePart) {
37

  
38
		boolean refresh = specificExecute((CdmDataSourceViewPartE4) dataSourcePart.getObject(), container, shell);
39

  
40
		MPart dataSourceView = partService.showPart(
41
                "eu.etaxonomy.taxeditor.view.datasource",
42
                PartState.ACTIVATE);
43

  
44
		CdmDataSourceViewPartE4 view = (CdmDataSourceViewPartE4) dataSourceView.getObject();
45
		if(refresh) {
46
            view.refresh();
47
        }
48
	}
49

  
50
	public abstract boolean specificExecute(CdmDataSourceViewPartE4 dataSourceViewPart, CdmMetaDataAwareDataSourceContainer container, Shell shell);
51
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/e4/handler/ChangeConnectionHandlerE4.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

  
10
package eu.etaxonomy.taxeditor.view.datasource.e4.handler;
11

  
12
import javax.inject.Named;
13

  
14
import org.eclipse.e4.core.di.annotations.CanExecute;
15
import org.eclipse.e4.core.di.annotations.Execute;
16
import org.eclipse.e4.ui.services.IServiceConstants;
17

  
18
import eu.etaxonomy.cdm.model.metadata.CdmMetaDataPropertyName;
19
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
20
import eu.etaxonomy.taxeditor.l10n.Messages;
21
import eu.etaxonomy.taxeditor.model.MessagingUtils;
22
import eu.etaxonomy.taxeditor.store.CdmStore;
23
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
24

  
25
/**
26
 *
27
 * @author pplitzner
28
 * @date 22.08.2017
29
 *
30
 */
31
public class ChangeConnectionHandlerE4 {
32

  
33
    @Execute
34
    public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)CdmMetaDataAwareDataSourceContainer container) {
35

  
36
			if(CdmStore.isConnecting()){
37
				MessagingUtils.warningDialog(Messages.ChangeConnectionHandler_ALREADY_CONNECTING, this, Messages.ChangeConnectionHandler_CURRENTLY_CONNECTING_ALREADY);
38
				return ;
39
			}
40

  
41
			try {
42
				container.getCdmSource().checkConnection();
43
				boolean confirmed = MessagingUtils.confirmDialog(Messages.ChangeConnectionHandler_CREATE_DATAMODEL, String.format(Messages.ChangeConnectionHandler_REALLY_CREATE_DATAMODEL, container.getCdmSource().getName()));
44

  
45
				if(confirmed){
46
					CdmDataSourceRepository.changeDataSource(container.getCdmSource());
47
				}
48
			} catch (Exception e) {
49
				MessagingUtils.warningDialog(Messages.ChangeConnectionHandler_DATASOURCE_NOT_AVAILABLE, this, Messages.ChangeConnectionHandler_NOT_AVAILABLE_REASONS);
50
				MessagingUtils.warn(getClass(), e);
51
				return ;
52
		}
53

  
54
		return ;
55
	}
56

  
57
	@CanExecute
58
	public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)CdmMetaDataAwareDataSourceContainer container){
59
	    String schemaVersion = container.getMetaData(CdmMetaDataPropertyName.DB_SCHEMA_VERSION);
60
	    return schemaVersion.equals(CdmMetaDataAwareDataSourceContainer.DEFAULT_ENTRY);
61
	}
62
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/e4/handler/CloneDataSourceHandlerE4.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

  
10
package eu.etaxonomy.taxeditor.view.datasource.e4.handler;
11

  
12
import javax.inject.Named;
13

  
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.e4.core.di.annotations.CanExecute;
16
import org.eclipse.e4.ui.services.IServiceConstants;
17
import org.eclipse.jface.wizard.Wizard;
18
import org.eclipse.jface.wizard.WizardDialog;
19
import org.eclipse.swt.widgets.Shell;
20

  
21
import eu.etaxonomy.cdm.config.ICdmSource;
22
import eu.etaxonomy.cdm.database.ICdmDataSource;
23
import eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceWizard;
24
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
25
import eu.etaxonomy.taxeditor.view.datasource.e4.CdmDataSourceViewPartE4;
26

  
27
/**
28
 *
29
 * @author pplitzner
30
 * @date 22.08.2017
31
 *
32
 */
33
public class CloneDataSourceHandlerE4 extends AbstractDataSourceHandlerE4 {
34

  
35
	/** {@inheritDoc} */
36
	@Override
37
	public boolean specificExecute(CdmDataSourceViewPartE4 dataSourceViewPart, CdmMetaDataAwareDataSourceContainer container, Shell shell) {
38
		ICdmSource cdmSource = container.getCdmSource();
39
		//FIXME:Remoting we need another wizard for ICdmRemoteSource
40
		if(cdmSource instanceof ICdmDataSource) {
41
			Wizard wizard = new CdmDataSourceWizard((ICdmDataSource)cdmSource, CdmDataSourceWizard.Mode.CLONE);
42
			WizardDialog dialog = new WizardDialog(shell, wizard);
43

  
44
			int result = dialog.open();
45

  
46
			if(result == IStatus.OK){
47
				if(dataSourceViewPart != null){
48
					container.getMetaDataFromDataSource();
49
					dataSourceViewPart.getViewer().update(new CdmMetaDataAwareDataSourceContainer[]{container}, null);
50
				}
51
			}
52
		}
53
		return true;
54
	}
55

  
56
    @CanExecute
57
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)CdmMetaDataAwareDataSourceContainer container){
58
        return container!=null;
59
    }
60
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/e4/handler/CreateDataSourceHandlerE4.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

  
10
package eu.etaxonomy.taxeditor.view.datasource.e4.handler;
11

  
12
import org.eclipse.core.runtime.IStatus;
13
import org.eclipse.jface.wizard.WizardDialog;
14
import org.eclipse.swt.widgets.Shell;
15

  
16
import eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceWizard;
17
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
18
import eu.etaxonomy.taxeditor.view.datasource.e4.CdmDataSourceViewPartE4;
19

  
20
/**
21
 *
22
 * @author pplitzner
23
 * @date 22.08.2017
24
 *
25
 */
26
public class CreateDataSourceHandlerE4 extends AbstractDataSourceHandlerE4 {
27

  
28
    /** {@inheritDoc} */
29
    @Override
30
    public boolean specificExecute(CdmDataSourceViewPartE4 dataSourceViewPart, CdmMetaDataAwareDataSourceContainer container, Shell shell) {
31
		CdmDataSourceWizard wizard = new CdmDataSourceWizard();
32

  
33
		WizardDialog dialog = new WizardDialog(shell, wizard);
34

  
35
		return dialog.open() == IStatus.OK;
36
	}
37
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/e4/handler/DeleteDataSourceHandlerE4.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

  
10
package eu.etaxonomy.taxeditor.view.datasource.e4.handler;
11

  
12
import javax.inject.Named;
13

  
14
import org.eclipse.e4.core.di.annotations.CanExecute;
15
import org.eclipse.e4.ui.services.IServiceConstants;
16
import org.eclipse.jface.dialogs.MessageDialog;
17
import org.eclipse.swt.widgets.Shell;
18

  
19
import eu.etaxonomy.cdm.database.CdmPersistentDataSource;
20
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
21
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
22
import eu.etaxonomy.taxeditor.view.datasource.e4.CdmDataSourceViewPartE4;
23

  
24
/**
25
 *
26
 * @author pplitzner
27
 * @date 22.08.2017
28
 *
29
 */
30
public class DeleteDataSourceHandlerE4 extends AbstractDataSourceHandlerE4 {
31

  
32
    /** {@inheritDoc} */
33
    @Override
34
    public boolean specificExecute(CdmDataSourceViewPartE4 dataSourceViewPart, CdmMetaDataAwareDataSourceContainer container, Shell shell) {
35
        if(! MessageDialog.openConfirm(shell, "Confirm Deletion", "Do you want to delete the selected datasources?")){
36
            return false;
37
        }
38
        CdmPersistentDataSource dataSource = (CdmPersistentDataSource) container.getCdmSource();
39
        CdmDataSourceRepository.delete(dataSource);
40
        return true;
41
    }
42

  
43
    @CanExecute
44
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)CdmMetaDataAwareDataSourceContainer container){
45
        return container!=null;
46
    }
47
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/e4/handler/EditDataSourceHandlerE4.java
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

  
10
package eu.etaxonomy.taxeditor.view.datasource.e4.handler;
11

  
12
import javax.inject.Named;
13

  
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.e4.core.di.annotations.CanExecute;
16
import org.eclipse.e4.ui.services.IServiceConstants;
17
import org.eclipse.jface.wizard.Wizard;
18
import org.eclipse.jface.wizard.WizardDialog;
19
import org.eclipse.swt.widgets.Shell;
20

  
21
import eu.etaxonomy.cdm.config.ICdmSource;
22
import eu.etaxonomy.cdm.database.ICdmDataSource;
23
import eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceWizard;
24
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
25
import eu.etaxonomy.taxeditor.view.datasource.e4.CdmDataSourceViewPartE4;
26

  
27
/**
28
 *
29
 * @author pplitzner
30
 * @date 22.08.2017
31
 *
32
 */
33
public class EditDataSourceHandlerE4 extends AbstractDataSourceHandlerE4 {
34

  
35
    /** {@inheritDoc} */
36
    @Override
37
    public boolean specificExecute(CdmDataSourceViewPartE4 dataSourceViewPart, CdmMetaDataAwareDataSourceContainer container, Shell shell) {
38
		ICdmSource cdmSource = container.getCdmSource();
39
		//FIXME:Remoting we need another wizard for ICdmRemoteSource
40
		if(cdmSource instanceof ICdmDataSource) {
41
			Wizard wizard = new CdmDataSourceWizard((ICdmDataSource)cdmSource, CdmDataSourceWizard.Mode.EDIT);
42
			WizardDialog dialog = new WizardDialog(shell, wizard);
43

  
44
			int result = dialog.open();
45

  
46
			if(result == IStatus.OK){
47
				if(dataSourceViewPart != null){
48
					container.getMetaDataFromDataSource();
49
					dataSourceViewPart.getViewer().update(new CdmMetaDataAwareDataSourceContainer[]{container}, null);
50
				}
51
			}
52
		}
53
		return false;
54
	}
55

  
56
    @CanExecute
57
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)CdmMetaDataAwareDataSourceContainer container){
58
        return container!=null;
59
    }
60
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/e4/handler/UpdateDataSourceHandlerE4.java
1
/**
2
 * Copyright (C) 2007 EDIT
3
 * European Distributed Institute of Taxonomy
4
 * http://www.e-taxonomy.eu
5
 *
6
 * The contents of this file are subject to the Mozilla Public License Version 1.1
7
 * See LICENSE.TXT at the top of this package for the full license terms.
8
 */
9

  
10
package eu.etaxonomy.taxeditor.view.datasource.e4.handler;
11

  
12
import javax.inject.Named;
13

  
14
import org.eclipse.core.runtime.IProgressMonitor;
15
import org.eclipse.core.runtime.IStatus;
16
import org.eclipse.core.runtime.Status;
17
import org.eclipse.core.runtime.jobs.Job;
18
import org.eclipse.e4.core.di.annotations.CanExecute;
19
import org.eclipse.e4.ui.services.IServiceConstants;
20
import org.eclipse.jface.dialogs.MessageDialog;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.widgets.Display;
23
import org.eclipse.swt.widgets.Shell;
24
import org.eclipse.ui.progress.IProgressConstants;
25

  
26
import eu.etaxonomy.cdm.config.ICdmSource;
27
import eu.etaxonomy.cdm.database.ICdmDataSource;
28
import eu.etaxonomy.cdm.database.update.CdmUpdater;
29
import eu.etaxonomy.cdm.database.update.SchemaUpdateResult;
30
import eu.etaxonomy.taxeditor.model.CdmProgressMonitorAdapter;
31
import eu.etaxonomy.taxeditor.model.MessagingUtils;
32
import eu.etaxonomy.taxeditor.store.internal.TaxeditorStorePlugin;
33
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
34
import eu.etaxonomy.taxeditor.view.datasource.e4.CdmDataSourceViewPartE4;
35

  
36
/**
37
 *
38
 * @author pplitzner
39
 * @date 22.08.2017
40
 *
41
 */
42
public class UpdateDataSourceHandlerE4 extends AbstractDataSourceHandlerE4 {
43

  
44
    /** {@inheritDoc} */
45
    @Override
46
    public boolean specificExecute(CdmDataSourceViewPartE4 dataSourceViewPart, CdmMetaDataAwareDataSourceContainer container, Shell shell) {
47
        final Display display = Display.getCurrent();
48
        if(! MessageDialog.open(MessageDialog.CONFIRM, shell, "Update Datasource", "WARNING!\n\n" +
49
                "This will change your data base structure! Be sure you have an up-to-date backup of your data before running the update! \n\n " +
50
                "Are you sure you want to update the datasource?", SWT.NONE)){
51
            return false;
52
        }
53
        Job job = new Job("Updating datasource " + container.getCdmSource().getName()){
54

  
55
            @Override
56
            protected IStatus run(IProgressMonitor monitor) {
57
                CdmUpdater updater = new CdmUpdater();
58
                IStatus status = null;
59
                ICdmSource cdmSource = container.getCdmSource();
60
                //FIXME:Remoting we need another updater for ICdmRemoteSource
61
                if(cdmSource instanceof ICdmDataSource) {
62
                    try{
63
                        SchemaUpdateResult result = updater.updateToCurrentVersion(
64
                                (ICdmDataSource)cdmSource, CdmProgressMonitorAdapter.CreateMonitor(monitor));
65
                        if(result.isSuccess()){
66
                            display.asyncExec(new Runnable(){
67

  
68
                                @Override
69
                                public void run() {
70
                                    if(dataSourceViewPart!= null){
71
                                        container.getMetaDataFromDataSource();
72
                                        dataSourceViewPart.getViewer().update(new CdmMetaDataAwareDataSourceContainer[]{container}, null);
73
                                    }
74

  
75
                                }
76
                            });
77
                            status = Status.OK_STATUS;
78
                        }else{
79
                            throw new RuntimeException("An error occurred during the update.");
80
                        }
81
                    }catch(Exception e){
82
                        status = new Status(IStatus.ERROR, TaxeditorStorePlugin.PLUGIN_ID, e.getMessage(), e);
83
                        MessagingUtils.errorDialog("Could not complete updater", updater, status.getMessage(), status.getPlugin(), e, true);
84
                    }
85
                }
86

  
87
                return status;
88
            }
89

  
90
        };
91

  
92
        job.setPriority(Job.BUILD);
93
        job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
94
        job.schedule();
95

  
96
        return false;
97
    }
98

  
99

  
100
    @CanExecute
101
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)CdmMetaDataAwareDataSourceContainer container){
102
        return container.isDataSourceCompatible();
103
    }
104
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)