Project

General

Profile

« Previous | Next » 

Revision de620fc8

Added by Patrick Plitzner almost 6 years ago

ref #6913 Remove datasource handler

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/handler/AbstractDataSourceHandler.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.handler;
11

  
12
import org.eclipse.core.commands.AbstractHandler;
13
import org.eclipse.core.commands.ExecutionEvent;
14
import org.eclipse.core.commands.ExecutionException;
15
import org.eclipse.jface.viewers.ISelection;
16
import org.eclipse.jface.viewers.StructuredSelection;
17
import org.eclipse.ui.handlers.HandlerUtil;
18

  
19
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
20

  
21
/**
22
 * @author n.hoffmann
23
 * @created 19.05.2009
24
 * @version 1.0
25
 */
26
abstract class AbstractDataSourceHandler extends AbstractHandler {
27

  
28
	/* (non-Javadoc)
29
	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
30
	 */
31
	/** {@inheritDoc} */
32
	@Override
33
    public Object execute(ExecutionEvent event) throws ExecutionException {
34

  
35
//		boolean refresh = specificExecute(event);
36

  
37
//		CdmDataSourceViewPart view = (CdmDataSourceViewPart) StoreUtil.showView(CdmDataSourceViewPart.ID);
38
//		if(refresh) {
39
//            view.refresh();
40
//        }
41

  
42
		return null;
43
	}
44

  
45
	/**
46
	 * <p>getSelectedDataSourceContainer</p>
47
	 *
48
	 * @param event a {@link org.eclipse.core.commands.ExecutionEvent} object.
49
	 * @return a {@link eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer} object.
50
	 */
51
	protected CdmMetaDataAwareDataSourceContainer getSelectedDataSourceContainer(ExecutionEvent event){
52
		ISelection menuSelection = HandlerUtil.getCurrentSelection(event);
53
		CdmMetaDataAwareDataSourceContainer container = (CdmMetaDataAwareDataSourceContainer) ((StructuredSelection) menuSelection).getFirstElement();
54
		return container;
55
	}
56

  
57
	/**
58
	 * <p>specificExecute</p>
59
	 *
60
	 * @param event a {@link org.eclipse.core.commands.ExecutionEvent} object.
61
	 * @return a boolean.
62
	 */
63
	public abstract boolean specificExecute(ExecutionEvent event);
64
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/handler/ChangeConnectionHandler.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.handler;
11

  
12
import org.eclipse.core.commands.AbstractHandler;
13
import org.eclipse.core.commands.ExecutionEvent;
14
import org.eclipse.jface.viewers.ISelection;
15
import org.eclipse.jface.viewers.IStructuredSelection;
16
import org.eclipse.ui.handlers.HandlerUtil;
17

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

  
24
/**
25
 * @author n.hoffmann
26
 * @created 15.04.2009
27
 * @version 1.0
28
 */
29
public class ChangeConnectionHandler extends AbstractHandler {
30

  
31
	/** {@inheritDoc} */
32
	@Override
33
    public Object execute(ExecutionEvent event) {
34
		ISelection selection = HandlerUtil.getCurrentSelection(event);
35

  
36
		if(selection != null && selection instanceof IStructuredSelection){
37
			CdmMetaDataAwareDataSourceContainer container = (CdmMetaDataAwareDataSourceContainer) ((IStructuredSelection) selection).getFirstElement();
38

  
39
			if(CdmStore.isConnecting()){
40
				MessagingUtils.warningDialog(Messages.ChangeConnectionHandler_ALREADY_CONNECTING, this, Messages.ChangeConnectionHandler_CURRENTLY_CONNECTING_ALREADY);
41
				return null;
42
			}
43

  
44
			try {
45
				container.getCdmSource().checkConnection();
46
				boolean confirmed = MessagingUtils.confirmDialog(Messages.ChangeConnectionHandler_CREATE_DATAMODEL, String.format(Messages.ChangeConnectionHandler_REALLY_CREATE_DATAMODEL, container.getCdmSource().getName()));
47

  
48
				if(confirmed){
49
					CdmDataSourceRepository.changeDataSource(container.getCdmSource());
50
				}
51
			} catch (Exception e) {
52
				MessagingUtils.warningDialog(Messages.ChangeConnectionHandler_DATASOURCE_NOT_AVAILABLE, this, Messages.ChangeConnectionHandler_NOT_AVAILABLE_REASONS);
53
				MessagingUtils.warn(getClass(), e);
54
				return null;
55
			}
56
		}
57

  
58
		return null;
59
	}
60
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/handler/CloneDataSourceHandler.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.handler;
11

  
12
import org.eclipse.core.commands.ExecutionEvent;
13
import org.eclipse.core.runtime.IStatus;
14
import org.eclipse.jface.wizard.Wizard;
15
import org.eclipse.jface.wizard.WizardDialog;
16
import org.eclipse.ui.handlers.HandlerUtil;
17

  
18
import eu.etaxonomy.cdm.config.ICdmSource;
19
import eu.etaxonomy.cdm.database.ICdmDataSource;
20
import eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceWizard;
21
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
22

  
23
/**
24
 * <p>CloneDataSourceHandler class.</p>
25
 *
26
 */
27
public class CloneDataSourceHandler extends AbstractDataSourceHandler {
28

  
29
	/* (non-Javadoc)
30
	 * @see eu.etaxonomy.taxeditor.store.datasource.handler.AbstractDataSourceHandler#specificExecute(org.eclipse.core.commands.ExecutionEvent)
31
	 */
32
	/** {@inheritDoc} */
33
	@Override
34
	public boolean specificExecute(ExecutionEvent event) {
35
		CdmMetaDataAwareDataSourceContainer container = getSelectedDataSourceContainer(event);
36
		ICdmSource cdmSource = container.getCdmSource();
37
		//FIXME:Remoting we need another wizard for ICdmRemoteSource
38
		if(cdmSource instanceof ICdmDataSource) {
39
			Wizard wizard = new CdmDataSourceWizard((ICdmDataSource)cdmSource, CdmDataSourceWizard.Mode.CLONE);
40
			WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), wizard);
41

  
42
			int result = dialog.open();
43

  
44
			if(result == IStatus.OK){
45
//				CdmDataSourceViewPart view = (CdmDataSourceViewPart) StoreUtil.getView(CdmDataSourceViewPart.ID, false);
46
//				if(view != null){
47
//					container.getMetaDataFromDataSource();
48
//					view.getViewer().update(new CdmMetaDataAwareDataSourceContainer[]{container}, null);
49
//
50
//				}
51
			}
52
		}
53

  
54
		return true;
55
	}
56
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/handler/CreateDataSourceHandler.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.handler;
11

  
12
import org.eclipse.core.commands.ExecutionEvent;
13
import org.eclipse.core.runtime.IStatus;
14
import org.eclipse.jface.wizard.WizardDialog;
15
import org.eclipse.swt.widgets.Shell;
16
import org.eclipse.ui.handlers.HandlerUtil;
17

  
18
import eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceWizard;
19

  
20
/**
21
 * <p>CreateDataSourceHandler class.</p>
22
 *
23
 * @author n.hoffmann
24
 * @created 15.04.2009
25
 * @version 1.0
26
 */
27
public class CreateDataSourceHandler extends AbstractDataSourceHandler {
28

  
29
	/* (non-Javadoc)
30
	 * @see eu.etaxonomy.taxeditor.store.datasource.handler.AbstractDataSourceHandler#specificExecute(org.eclipse.core.commands.ExecutionEvent)
31
	 */
32
	/** {@inheritDoc} */
33
	@Override
34
	public boolean specificExecute(ExecutionEvent event) {
35
		Shell shell = HandlerUtil.getActiveShell(event);
36
		CdmDataSourceWizard wizard = new CdmDataSourceWizard(); 
37
		
38
		WizardDialog dialog = new WizardDialog(shell, wizard);
39
	    		
40
		return dialog.open() == IStatus.OK;
41
	}
42
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/handler/DeleteDataSourceHandler.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.handler;
11

  
12
import org.eclipse.core.commands.ExecutionEvent;
13
import org.eclipse.jface.dialogs.MessageDialog;
14
import org.eclipse.jface.viewers.ISelection;
15
import org.eclipse.jface.viewers.IStructuredSelection;
16
import org.eclipse.ui.handlers.HandlerUtil;
17

  
18
import eu.etaxonomy.cdm.database.CdmPersistentDataSource;
19
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
20
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
21

  
22
/**
23
 * @author n.hoffmann
24
 * @created 15.04.2009
25
 * @version 1.0
26
 */
27
public class DeleteDataSourceHandler extends AbstractDataSourceHandler {
28

  
29
	/** {@inheritDoc} */
30
	@Override
31
	public boolean specificExecute(ExecutionEvent event) {
32
		ISelection selection = HandlerUtil.getActivePart(event).getSite().getSelectionProvider().getSelection();
33
		if(selection instanceof IStructuredSelection){
34
			Object[] selectedObjects = ((IStructuredSelection) selection).toArray();
35

  
36
			if(! MessageDialog.openConfirm(HandlerUtil.getActiveShell(event), "Confirm Deletion", "Do you want to delete the selected datasources?")){
37
				return false;
38
			}
39
			// Delete from persistent data sources
40
			for(Object object : selectedObjects){
41
				CdmPersistentDataSource dataSource = (CdmPersistentDataSource) ((CdmMetaDataAwareDataSourceContainer) object).getCdmSource();
42
				CdmDataSourceRepository.delete(dataSource);
43
			}
44

  
45
			return true;
46
		}
47
		return false;
48
	}
49
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/handler/EditDataSourceHandler.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.handler;
11

  
12
import org.eclipse.core.commands.ExecutionEvent;
13
import org.eclipse.core.runtime.IStatus;
14
import org.eclipse.jface.wizard.Wizard;
15
import org.eclipse.jface.wizard.WizardDialog;
16
import org.eclipse.ui.handlers.HandlerUtil;
17

  
18
import eu.etaxonomy.cdm.config.ICdmSource;
19
import eu.etaxonomy.cdm.database.ICdmDataSource;
20
import eu.etaxonomy.taxeditor.datasource.wizard.CdmDataSourceWizard;
21
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
22

  
23
/**
24
 * <p>EditDataSourceHandler class.</p>
25
 *
26
 * @author n.hoffmann
27
 * @created 15.04.2009
28
 * @version 1.0
29
 */
30
public class EditDataSourceHandler extends AbstractDataSourceHandler {
31

  
32
	/* (non-Javadoc)
33
	 * @see eu.etaxonomy.taxeditor.store.datasource.handler.AbstractDataSourceHandler#specificExecute(org.eclipse.core.commands.ExecutionEvent)
34
	 */
35
	/** {@inheritDoc} */
36
	@Override
37
	public boolean specificExecute(ExecutionEvent event) {
38
		CdmMetaDataAwareDataSourceContainer container = getSelectedDataSourceContainer(event);
39
		ICdmSource cdmSource = container.getCdmSource();
40
		//FIXME:Remoting we need another wizard for ICdmRemoteSource
41
		if(cdmSource instanceof ICdmDataSource) {
42
			Wizard wizard = new CdmDataSourceWizard((ICdmDataSource)cdmSource, CdmDataSourceWizard.Mode.EDIT);
43
			WizardDialog dialog = new WizardDialog(HandlerUtil.getActiveShell(event), wizard);
44

  
45
			int result = dialog.open();
46

  
47
			if(result == IStatus.OK){
48
//				CdmDataSourceViewPart view = (CdmDataSourceViewPart) StoreUtil.getView(CdmDataSourceViewPart.ID, false);
49
//				if(view != null){
50
//					container.getMetaDataFromDataSource();
51
//					view.getViewer().update(new CdmMetaDataAwareDataSourceContainer[]{container}, null);
52
//
53
//				}
54
			}
55
		}
56

  
57
		return false;
58
	}
59
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/handler/UpdateDataSourceHandler.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.handler;
11

  
12
import org.eclipse.core.commands.ExecutionEvent;
13
import org.eclipse.core.runtime.IProgressMonitor;
14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.core.runtime.jobs.Job;
16
import org.eclipse.jface.dialogs.MessageDialog;
17
import org.eclipse.swt.SWT;
18
import org.eclipse.swt.widgets.Display;
19
import org.eclipse.ui.handlers.HandlerUtil;
20
import org.eclipse.ui.progress.IProgressConstants;
21

  
22
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
23

  
24
/**
25
 * <p>UpdateDataSourceHandler class.</p>
26
 *
27
 * @author n.hoffmann
28
 * @created Sep 22, 2010
29
 * @version 1.0
30
 */
31
public class UpdateDataSourceHandler extends AbstractDataSourceHandler {
32

  
33
	/* (non-Javadoc)
34
	 * @see eu.etaxonomy.taxeditor.datasource.handler.AbstractDataSourceHandler#specificExecute(org.eclipse.core.commands.ExecutionEvent)
35
	 */
36
	/** {@inheritDoc} */
37
	@Override
38
	public boolean specificExecute(ExecutionEvent event) {
39
		final CdmMetaDataAwareDataSourceContainer container = getSelectedDataSourceContainer(event);
40

  
41
		final Display display = Display.getCurrent();
42
		if(! MessageDialog.open(MessageDialog.CONFIRM, HandlerUtil.getActiveShell(event), "Update Datasource", "WARNING!\n\n" +
43
				"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 " +
44
				"Are you sure you want to update the datasource?", SWT.NONE)){
45
			return false;
46
		}
47
		Job job = new Job("Updating datasource " + container.getCdmSource().getName()){
48

  
49
			@Override
50
			protected IStatus run(IProgressMonitor monitor) {
51
//				CdmUpdater updater = new CdmUpdater();
52
				IStatus status = null;
53
//				ICdmSource cdmSource = container.getCdmSource();
54
//				//FIXME:Remoting we need another updater for ICdmRemoteSource
55
//				if(cdmSource instanceof ICdmDataSource) {
56
//				try{
57
//					SchemaUpdateResult result = updater.updateToCurrentVersion(
58
//							(ICdmDataSource)cdmSource, CdmProgressMonitorAdapter.CreateMonitor(monitor));
59
//					if(result.isSuccess()){
60
//						display.asyncExec(new Runnable(){
61
//
62
//							@Override
63
//							public void run() {
64
//
65
//								CdmDataSourceViewPart view = (CdmDataSourceViewPart) StoreUtil.getView(CdmDataSourceViewPart.ID, false);
66
//								if(view != null){
67
//								    container.getMetaDataFromDataSource();
68
//									view.getViewer().update(new CdmMetaDataAwareDataSourceContainer[]{container}, null);
69
//								}
70
//
71
//							}
72
//						});
73
//						status = Status.OK_STATUS;
74
//					}else{
75
//						throw new RuntimeException("An error occurred during the update.");
76
//					}
77
//				}catch(Exception e){
78
//					status = new Status(IStatus.ERROR, TaxeditorStorePlugin.PLUGIN_ID, e.getMessage(), e);
79
//					MessagingUtils.errorDialog("Could not complete updater", updater, status.getMessage(), status.getPlugin(), e, true);
80
//				}
81
//				}
82

  
83
				return status;
84
			}
85

  
86
		};
87

  
88
		job.setPriority(Job.BUILD);
89
		job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
90
		job.schedule();
91

  
92
		return false;
93
	}
94
}

Also available in: Unified diff