Project

General

Profile

Revision a9bea304

IDa9bea304208b61d155d65b8355455fbf658a372e
Parent c6c263b6
Child 26cc98f0

Added by Patrick Plitzner over 3 years ago

ref #7010 Adapt datasource handlers for multiple selection

View differences:

eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/e4/CdmDataSourceViewPartE4.java
44 44
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
45 45
import eu.etaxonomy.taxeditor.event.WorkbenchEventConstants;
46 46
import eu.etaxonomy.taxeditor.l10n.Messages;
47
import eu.etaxonomy.taxeditor.model.AbstractUtility;
48 47
import eu.etaxonomy.taxeditor.model.ContextListenerAdapter;
49 48
import eu.etaxonomy.taxeditor.model.IContextListener;
50 49
import eu.etaxonomy.taxeditor.store.CdmStore;
......
195 194

  
196 195

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

  
201 200
        //create context menu
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/e4/handler/AbstractDataSourceHandlerE4.java
11 11

  
12 12
import javax.inject.Named;
13 13

  
14
import org.eclipse.e4.core.di.annotations.CanExecute;
14 15
import org.eclipse.e4.core.di.annotations.Execute;
16
import org.eclipse.e4.core.di.annotations.Optional;
15 17
import org.eclipse.e4.ui.di.UISynchronize;
16 18
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
19
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
17 20
import org.eclipse.e4.ui.services.IServiceConstants;
18
import org.eclipse.e4.ui.workbench.modeling.EPartService;
19
import org.eclipse.e4.ui.workbench.modeling.EPartService.PartState;
21
import org.eclipse.jface.viewers.IStructuredSelection;
20 22
import org.eclipse.swt.widgets.Shell;
21 23

  
22 24
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
......
33 35
    protected UISynchronize sync;
34 36

  
35 37
	@Execute
36
    public void execute(EPartService partService,
38
    public void execute(
37 39
            @Named(IServiceConstants.ACTIVE_SHELL)Shell shell,
38
            @Named(IServiceConstants.ACTIVE_SELECTION)CdmMetaDataAwareDataSourceContainer container,
40
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
41
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
39 42
            UISynchronize sync) {
40 43

  
41 44
	    this.sync = sync;
42 45

  
43
		MPart dataSourceView = partService.showPart(
44
                "eu.etaxonomy.taxeditor.view.datasource",
45
                PartState.ACTIVATE);
46
		CdmDataSourceViewPartE4 view = (CdmDataSourceViewPartE4) thisPart.getObject();
46 47

  
47
		CdmDataSourceViewPartE4 view = (CdmDataSourceViewPartE4) dataSourceView.getObject();
48

  
49
		boolean refresh = specificExecute(view, container, shell);
48
		boolean refresh = specificExecute(view,
49
		        (CdmMetaDataAwareDataSourceContainer) selection.getFirstElement(), shell);
50 50

  
51 51
		if(refresh) {
52 52
            view.refresh();
53 53
        }
54 54
	}
55 55

  
56
    @CanExecute
57
    public boolean canExecute(
58
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
59
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
60
            MHandledMenuItem menuItem) {
61
        boolean canExecute = false;
62
        canExecute = thisPart.getObject() instanceof CdmDataSourceViewPartE4
63
                && selection!=null
64
                && selection.size()==1
65
                && selection.getFirstElement() instanceof CdmMetaDataAwareDataSourceContainer;
66
        menuItem.setVisible(canExecute);
67
        return canExecute;
68
    }
69

  
56 70
	public abstract boolean specificExecute(CdmDataSourceViewPartE4 dataSourceViewPart, CdmMetaDataAwareDataSourceContainer container, Shell shell);
57 71
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/e4/handler/ChangeConnectionHandlerE4.java
13 13

  
14 14
import org.eclipse.e4.core.di.annotations.CanExecute;
15 15
import org.eclipse.e4.core.di.annotations.Execute;
16
import org.eclipse.e4.core.di.annotations.Optional;
17
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
18
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
16 19
import org.eclipse.e4.ui.services.IServiceConstants;
20
import org.eclipse.jface.viewers.IStructuredSelection;
17 21

  
18 22
import eu.etaxonomy.cdm.model.metadata.CdmMetaDataPropertyName;
19 23
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
......
21 25
import eu.etaxonomy.taxeditor.model.MessagingUtils;
22 26
import eu.etaxonomy.taxeditor.store.CdmStore;
23 27
import eu.etaxonomy.taxeditor.view.datasource.CdmMetaDataAwareDataSourceContainer;
28
import eu.etaxonomy.taxeditor.view.datasource.e4.CdmDataSourceViewPartE4;
24 29

  
25 30
/**
26 31
 *
......
31 36
public class ChangeConnectionHandlerE4 {
32 37

  
33 38
    @Execute
34
    public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)CdmMetaDataAwareDataSourceContainer container) {
39
    public void execute(@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection) {
35 40

  
36 41
			if(CdmStore.isConnecting()){
37 42
				MessagingUtils.warningDialog(Messages.ChangeConnectionHandler_ALREADY_CONNECTING, this, Messages.ChangeConnectionHandler_CURRENTLY_CONNECTING_ALREADY);
......
39 44
			}
40 45

  
41 46
			try {
47
			    CdmMetaDataAwareDataSourceContainer container = (CdmMetaDataAwareDataSourceContainer) selection.getFirstElement();
42 48
				container.getCdmSource().checkConnection();
43 49
				boolean confirmed = MessagingUtils.confirmDialog(Messages.ChangeConnectionHandler_CREATE_DATAMODEL, String.format(Messages.ChangeConnectionHandler_REALLY_CREATE_DATAMODEL, container.getCdmSource().getName()));
44 50

  
......
54 60
		return ;
55 61
	}
56 62

  
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);
63
    @CanExecute
64
    public boolean canExecute(
65
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
66
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
67
            MHandledMenuItem menuItem) {
68
        boolean canExecute = false;
69
        canExecute = thisPart.getObject() instanceof CdmDataSourceViewPartE4
70
                && selection!=null
71
                && selection.size()==1
72
                && selection.getFirstElement() instanceof CdmMetaDataAwareDataSourceContainer
73
                && ((CdmMetaDataAwareDataSourceContainer) selection.getFirstElement()).getMetaData(CdmMetaDataPropertyName.DB_SCHEMA_VERSION).equals(CdmMetaDataAwareDataSourceContainer.DEFAULT_ENTRY);
74
	    menuItem.setVisible(canExecute);
75
	    return canExecute;
61 76
	}
62 77
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/e4/handler/CloneDataSourceHandlerE4.java
9 9

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

  
12
import javax.inject.Named;
13

  
14 12
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.e4.core.di.annotations.CanExecute;
16
import org.eclipse.e4.ui.services.IServiceConstants;
17 13
import org.eclipse.jface.wizard.Wizard;
18 14
import org.eclipse.jface.wizard.WizardDialog;
19 15
import org.eclipse.swt.widgets.Shell;
......
53 49
		return true;
54 50
	}
55 51

  
56
    @CanExecute
57
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)CdmMetaDataAwareDataSourceContainer container){
58
        return container!=null;
59
    }
60 52
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/e4/handler/CreateDataSourceHandlerE4.java
9 9

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

  
12
import javax.inject.Named;
13

  
12 14
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.e4.core.di.annotations.CanExecute;
16
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
17
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
18
import org.eclipse.e4.ui.services.IServiceConstants;
13 19
import org.eclipse.jface.wizard.WizardDialog;
14 20
import org.eclipse.swt.widgets.Shell;
15 21

  
......
34 40

  
35 41
		return dialog.open() == IStatus.OK;
36 42
	}
43

  
44
    @CanExecute
45
    public boolean canExecute(
46
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
47
            MHandledMenuItem menuItem) {
48
        boolean canExecute = false;
49
        canExecute = thisPart.getObject() instanceof CdmDataSourceViewPartE4;
50
        menuItem.setVisible(canExecute);
51
        return canExecute;
52
    }
37 53
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/e4/handler/DeleteDataSourceHandlerE4.java
9 9

  
10 10
package eu.etaxonomy.taxeditor.view.datasource.e4.handler;
11 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 12
import org.eclipse.jface.dialogs.MessageDialog;
17 13
import org.eclipse.swt.widgets.Shell;
18 14

  
......
40 36
        return true;
41 37
    }
42 38

  
43
    @CanExecute
44
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)CdmMetaDataAwareDataSourceContainer container){
45
        return container!=null;
46
    }
47 39
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/e4/handler/EditDataSourceHandlerE4.java
9 9

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

  
12
import javax.inject.Named;
13

  
14 12
import org.eclipse.core.runtime.IStatus;
15
import org.eclipse.e4.core.di.annotations.CanExecute;
16
import org.eclipse.e4.ui.services.IServiceConstants;
17 13
import org.eclipse.jface.wizard.Wizard;
18 14
import org.eclipse.jface.wizard.WizardDialog;
19 15
import org.eclipse.swt.widgets.Shell;
......
53 49
		return false;
54 50
	}
55 51

  
56
    @CanExecute
57
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)CdmMetaDataAwareDataSourceContainer container){
58
        return container!=null;
59
    }
60 52
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/datasource/e4/handler/UpdateDataSourceHandlerE4.java
16 16
import org.eclipse.core.runtime.Status;
17 17
import org.eclipse.core.runtime.jobs.Job;
18 18
import org.eclipse.e4.core.di.annotations.CanExecute;
19
import org.eclipse.e4.core.di.annotations.Optional;
20
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
21
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
19 22
import org.eclipse.e4.ui.services.IServiceConstants;
20 23
import org.eclipse.jface.dialogs.MessageDialog;
24
import org.eclipse.jface.viewers.IStructuredSelection;
21 25
import org.eclipse.swt.SWT;
22 26
import org.eclipse.swt.widgets.Shell;
23 27
import org.eclipse.ui.progress.IProgressConstants;
......
92 96
    }
93 97

  
94 98

  
99
    @Override
95 100
    @CanExecute
96
    public boolean canExecute(@Named(IServiceConstants.ACTIVE_SELECTION)CdmMetaDataAwareDataSourceContainer container){
97
        return !container.isDataSourceCompatible();
101
    public boolean canExecute(
102
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
103
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart,
104
            MHandledMenuItem menuItem) {
105
        boolean canExecute = false;
106
        canExecute = thisPart.getObject() instanceof CdmDataSourceViewPartE4
107
                && selection!=null
108
                && selection.size()==1
109
                && selection.getFirstElement() instanceof CdmMetaDataAwareDataSourceContainer
110
                && !((CdmMetaDataAwareDataSourceContainer) selection.getFirstElement()).isDataSourceCompatible();
111
        menuItem.setVisible(canExecute);
112
        return canExecute;
98 113
    }
99 114
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)