Project

General

Profile

Revision a088cd55

IDa088cd555a49a16647c4dd84a3ef7529cc5e1f2c
Parent 023093e5
Child 663c54dd

Added by Patrick Plitzner over 1 year ago

ref #7268 Refactored p2 update related classes

  • moved handle and util to store plugin
  • re-wrote update handler to not relate on eclipse internal update site preferences

View differences:

eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/ApplicationWorkbenchWindowAdvisor.java
6 6
import org.eclipse.e4.ui.model.application.ui.menu.MToolBarElement;
7 7
import org.eclipse.e4.ui.model.application.ui.menu.impl.ToolBarImpl;
8 8
import org.eclipse.swt.graphics.Point;
9
import org.eclipse.swt.widgets.Shell;
10 9
import org.eclipse.ui.IWorkbenchWindow;
11 10
import org.eclipse.ui.PlatformUI;
12 11
import org.eclipse.ui.application.ActionBarAdvisor;
......
16 15
import org.eclipse.ui.internal.WorkbenchWindow;
17 16

  
18 17
import eu.etaxonomy.taxeditor.datasource.CdmDataSourceRepository;
18
import eu.etaxonomy.taxeditor.handler.update.P2Util;
19 19
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
20 20
import eu.etaxonomy.taxeditor.store.CdmStore;
21
import eu.etaxonomy.taxeditor.ui.dialog.LoginDialog;
22
import eu.etaxonomy.taxeditor.update.P2Util;
23 21
import eu.etaxonomy.taxeditor.util.ApplicationUtil;
24 22

  
25 23
/**
26
 * <p>ApplicationWorkbenchWindowAdvisor class.</p>
27 24
 *
28 25
 * @author n.hoffmann
29 26
 * @version $Id: $
30 27
 */
31 28
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
32 29

  
33
	/**
34
	 * <p>Constructor for ApplicationWorkbenchWindowAdvisor.</p>
35
	 *
36
	 * @param configurer a {@link org.eclipse.ui.application.IWorkbenchWindowConfigurer} object.
37
	 */
38 30
	public ApplicationWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
39 31
		super(configurer);
40 32
	}
41 33

  
42
	/** {@inheritDoc} */
43 34
	@Override
44 35
    public ActionBarAdvisor createActionBarAdvisor(
45 36
			IActionBarConfigurer configurer) {
46 37
		return new ApplicationActionBarAdvisor(configurer);
47 38
	}
48 39

  
49
	/**
50
	 * <p>preWindowOpen</p>
51
	 */
52 40
	@Override
53 41
    public void preWindowOpen() {
54 42
		IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
......
62 50
		CdmDataSourceRepository.createDefaultH2DataSource();
63 51
	}
64 52

  
65
	/**
66
	 * <p>postWindowOpen</p>
67
	 */
68 53
	@Override
69 54
    public void postWindowOpen() {
70 55
	    IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
......
92 77

  
93 78
	}
94 79

  
95
	/* (non-Javadoc)
96
	 * @see org.eclipse.ui.application.WorkbenchWindowAdvisor#postWindowClose()
97
	 */
98 80
	@Override
99 81
    public void postWindowClose() {
100 82
        P2Util.saveP2RepositoryPreferences();
101 83
    }
102

  
103
	private int authenticate(){
104
		Shell shell = TaxonomicEditorPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow().getShell();
105

  
106
		LoginDialog loginDialog = new LoginDialog(shell);
107
		return loginDialog.open();
108
	}
109 84
}
110 85

  
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/update/P2Util.java
1
package eu.etaxonomy.taxeditor.update;
2

  
3
import java.net.URI;
4
import java.net.URISyntaxException;
5
import java.util.ArrayList;
6
import java.util.List;
7

  
8
import org.eclipse.equinox.internal.p2.ui.ProvUI;
9
import org.eclipse.equinox.internal.p2.ui.model.ElementUtils;
10
import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
11
import org.eclipse.equinox.p2.repository.IRepository;
12
import org.eclipse.equinox.p2.repository.IRepositoryManager;
13
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
14
import org.eclipse.equinox.p2.ui.ProvisioningUI;
15

  
16
import eu.etaxonomy.taxeditor.model.MessagingUtils;
17
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
18
import eu.etaxonomy.taxeditor.util.ApplicationUtil;
19

  
20
/**
21
 * This class is a utility class for updating the editor from a p2 update site,
22
 * greatly inspired by the links given below.
23
 *
24
 *
25
 * To Do :
26
 * - Allow configurable update sites
27
 *
28
 * Notes :
29
 *
30
 *
31
 * @see http://wiki.eclipse.org/Equinox/p2/Adding_Self-Update_to_an_RCP_Application
32
 * @see http://bugs.eclipse.org/281226
33
 * @see http://www.vogella.com/tutorials/EclipseP2Update/article.html
34
 */
35
public class P2Util {
36

  
37
    private static String EDIT_NIGHTLY_UPDATE_SITE = "http://cybertaxonomy.eu/download/taxeditor/update/nightly/";
38
    private static String EDIT_NIGHTLY_UPDATE_SITE_NAME = "Taxonomic Editor Nightly";
39

  
40
    private static String EDIT_STABLE_UPDATE_SITE = "http://cybertaxonomy.eu/download/taxeditor/update/stable/";
41
    private static String EDIT_STABLE_UPDATE_SITE_NAME = "Taxonomic Editor Stable";
42

  
43
    /**
44
     * Retrieve and load the saved list of repositories from the preference store,
45
     * making sure that at least the default repository is always loaded.
46
     */
47
    @SuppressWarnings("restriction")
48
    public static void setP2UpdateRepositories() {
49
        List<MetadataRepositoryElement> repoElements = new ArrayList<MetadataRepositoryElement>();
50
        List<MetadataRepositoryElement> savedRepoElements = new ArrayList<>();
51

  
52
        MetadataRepositoryElement mre = new MetadataRepositoryElement(null, getP2UpdateRepository(), true);
53
        mre.setNickname(getP2UpdateRepositoryName());
54
        savedRepoElements.add(mre);
55

  
56
        repoElements.addAll(savedRepoElements);
57

  
58
        ElementUtils.updateRepositoryUsingElements(ProvisioningUI.getDefaultUI(),repoElements
59
                .toArray(new MetadataRepositoryElement[]{} ));
60

  
61
    }
62

  
63
    public static String getP2UpdateRepositoryName(){
64
        return ApplicationUtil.isStable()?EDIT_STABLE_UPDATE_SITE_NAME:EDIT_NIGHTLY_UPDATE_SITE_NAME;
65
    }
66

  
67
    public static URI getP2UpdateRepository(){
68
        try {
69
            return ApplicationUtil.isStable()?new URI(EDIT_STABLE_UPDATE_SITE):new URI(EDIT_NIGHTLY_UPDATE_SITE);
70
        } catch (URISyntaxException e) {
71
            MessagingUtils.error(P2Util.class, e);
72
        }
73
        return null;
74
    }
75

  
76
    /**
77
     * {@link org.eclipse.equinox.p2.ui.RepositoryManipulationPage} which handles the repsitory site list
78
     * in preferences does not create a preference store and hence the changes are not saved. This means
79
     * that we need to save it ourselves.
80
     *
81
     * This method saves the list of current repositories in the preference store as a string with
82
     * specific delimiters.
83
     */
84

  
85
    public static void saveP2RepositoryPreferences() {
86

  
87
        IMetadataRepositoryManager metaManager = ProvUI.getMetadataRepositoryManager(ProvisioningUI.getDefaultUI().getSession());
88

  
89
        URI[] currentlyEnabled = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
90
        URI[] currentlyDisabled = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_DISABLED);
91

  
92
        List<MetadataRepositoryElement> repoElements = new ArrayList<MetadataRepositoryElement>();
93

  
94
        for(URI repo : currentlyEnabled) {
95
            boolean enabled = true;
96
            String nickname = metaManager.getRepositoryProperty(repo, IRepository.PROP_NICKNAME);
97
            MetadataRepositoryElement element = new MetadataRepositoryElement(null, repo, true);
98
            element.setNickname(nickname);
99
            element.setEnabled(enabled);
100
            repoElements.add(element);
101
        }
102

  
103
        for(URI repo : currentlyDisabled) {
104
            boolean enabled = false;
105
            String nickname = metaManager.getRepositoryProperty(repo, IRepository.PROP_NICKNAME);
106
            MetadataRepositoryElement element = new MetadataRepositoryElement(null, repo, true);
107
            element.setNickname(nickname);
108
            element.setEnabled(enabled);
109
            repoElements.add(element);
110
        }
111
        PreferencesUtil.setP2Repositories(repoElements);
112
    }
113
}
eu.etaxonomy.taxeditor.store/META-INF/MANIFEST.MF
20 20
 eu.etaxonomy.taxeditor.handler,
21 21
 eu.etaxonomy.taxeditor.handler.defaultHandler,
22 22
 eu.etaxonomy.taxeditor.handler.defaultHandler.e4,
23
 eu.etaxonomy.taxeditor.handler.update,
23 24
 eu.etaxonomy.taxeditor.io,
24 25
 eu.etaxonomy.taxeditor.io.wizard,
25 26
 eu.etaxonomy.taxeditor.labels,
......
90 91
 org.eclipse.e4.core.contexts;bundle-version="1.5.1",
91 92
 org.eclipse.osgi.services,
92 93
 org.eclipse.e4.core.services,
93
 org.eclipse.nebula.widgets.compositetable;bundle-version="1.0.0"
94
 org.eclipse.nebula.widgets.compositetable;bundle-version="1.0.0",
95
 org.eclipse.equinox.p2.repository,
96
 org.eclipse.equinox.p2.ui,
97
 org.eclipse.equinox.p2.operations,
98
 org.eclipse.equinox.p2.metadata,
99
 org.eclipse.equinox.p2.core,
100
 org.eclipse.equinox.p2.engine
94 101
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
95 102
Bundle-ActivationPolicy: lazy
96 103
Import-Package: eu.etaxonomy.taxeditor.webapp,
eu.etaxonomy.taxeditor.store/fragment.e4xmi
117 117
    <elements xsi:type="commands:Command" xmi:id="_KQP_sK2gEeeykrJkROy5EA" elementId="eu.etaxonomy.taxeditor.store.operations.reconnect" commandName="%command.name.RE_CONNECT"/>
118 118
    <elements xsi:type="commands:Command" xmi:id="_SXZF8K2gEeeykrJkROy5EA" elementId="eu.etaxonomy.taxeditor.store.openPasswordWizzard" commandName="%command.name.10"/>
119 119
    <elements xsi:type="commands:Command" xmi:id="_dQ0swL-rEeegz7IDD8MJaw" elementId="eu.etaxonomy.taxeditor.store.open.InspectSessionsDialog" commandName="Inspect Session"/>
120
    <elements xsi:type="commands:Command" xmi:id="_jSJrsBWPEeiazYUJirF0Pw" elementId="eu.etaxonomy.taxeditor.store.command.update" commandName="Check for updates"/>
120 121
  </fragments>
121 122
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_swGH0GhvEee3K4uKJljEYg" featurename="handlers" parentElementId="xpath:/">
122 123
    <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"/>
......
145 146
    <elements xsi:type="commands:Handler" xmi:id="_8g19gK2sEeeykrJkROy5EA" elementId="eu.etaxonomy.taxeditor.handler.e4.ShowRemotingLoginWindowHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.handler.e4.ShowRemotingLoginWindowHandlerE4" command="_R00rwK2dEeeykrJkROy5EA"/>
146 147
    <elements xsi:type="commands:Handler" xmi:id="_D6BxkK2tEeeykrJkROy5EA" elementId="eu.etaxonomy.taxeditor.handler.e4.OpenPasswordWizzardHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.handler.e4.OpenPasswordWizzardHandlerE4" command="_SXZF8K2gEeeykrJkROy5EA"/>
147 148
    <elements xsi:type="commands:Handler" xmi:id="_H98S8K2tEeeykrJkROy5EA" elementId="eu.etaxonomy.taxeditor.handler.e4.SwitchUserHandlerE4" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.handler.e4.SwitchUserHandlerE4" command="_S868QK2dEeeykrJkROy5EA"/>
149
    <elements xsi:type="commands:Handler" xmi:id="_zdDe8BWNEeiazYUJirF0Pw" elementId="eu.etaxonomy.taxeditor.handler.update.UpdateHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.handler.update.UpdateHandler" command="_jSJrsBWPEeiazYUJirF0Pw"/>
148 150
  </fragments>
149 151
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_qT4hgIfTEeecZ4F2Y9Z0Og" featurename="children" parentElementId="eu.etaxonomy.taxeditor.workbench.menu.window" positionInList="before:eu.etaxonomy.taxeditor.application.windowMenu.last">
150 152
    <elements xsi:type="menu:Menu" xmi:id="_LT3P8IfcEeecZ4F2Y9Z0Og" elementId="eu.etaxonomy.taxeditor.store.menu.termeditor" label="Term Editor">
......
204 206
      <parameters xmi:id="_mNW72rMnEeeMU61m8yqdaA" elementId="eu.etaxonomy.taxeditor.store.showView.parameter.dataSourceView" name="eu.etaxonomy.taxeditor.workbench.commandparameter.partName" value="eu.etaxonomy.taxeditor.view.datasource"/>
205 207
    </elements>
206 208
  </fragments>
209
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_lnmLABWNEeiazYUJirF0Pw" featurename="children" parentElementId="eu.etaxonomy.taxeditor.workbench.menu.help" positionInList="after:eu.etaxonomy.taxeditor.workbench.menuseparator.beforeHelp">
210
    <elements xsi:type="menu:HandledMenuItem" xmi:id="_uHiLwBWNEeiazYUJirF0Pw" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.handledmenuitemlabel6" label="Check for updates" command="_jSJrsBWPEeiazYUJirF0Pw"/>
211
  </fragments>
207 212
</fragment:ModelFragments>
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/update/P2Util.java
1
package eu.etaxonomy.taxeditor.handler.update;
2

  
3
import java.net.URI;
4
import java.net.URISyntaxException;
5
import java.util.ArrayList;
6
import java.util.List;
7

  
8
import org.eclipse.equinox.internal.p2.ui.ProvUI;
9
import org.eclipse.equinox.internal.p2.ui.model.ElementUtils;
10
import org.eclipse.equinox.internal.p2.ui.model.MetadataRepositoryElement;
11
import org.eclipse.equinox.p2.repository.IRepository;
12
import org.eclipse.equinox.p2.repository.IRepositoryManager;
13
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
14
import org.eclipse.equinox.p2.ui.ProvisioningUI;
15

  
16
import eu.etaxonomy.taxeditor.model.MessagingUtils;
17
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
18
import eu.etaxonomy.taxeditor.util.ApplicationUtil;
19

  
20
/**
21
 * This class is a utility class for updating the editor from a p2 update site,
22
 * greatly inspired by the links given below.
23
 *
24
 *
25
 * To Do :
26
 * - Allow configurable update sites
27
 *
28
 * Notes :
29
 *
30
 *
31
 * @see http://wiki.eclipse.org/Equinox/p2/Adding_Self-Update_to_an_RCP_Application
32
 * @see http://bugs.eclipse.org/281226
33
 * @see http://www.vogella.com/tutorials/EclipseP2Update/article.html
34
 */
35
public class P2Util {
36

  
37
    private static String EDIT_NIGHTLY_UPDATE_SITE = "http://cybertaxonomy.eu/download/taxeditor/update/nightly/";
38
    private static String EDIT_NIGHTLY_UPDATE_SITE_NAME = "Taxonomic Editor Nightly";
39

  
40
    private static String EDIT_STABLE_UPDATE_SITE = "http://cybertaxonomy.eu/download/taxeditor/update/stable/";
41
    private static String EDIT_STABLE_UPDATE_SITE_NAME = "Taxonomic Editor Stable";
42

  
43
    /**
44
     * Retrieve and load the saved list of repositories from the preference store,
45
     * making sure that at least the default repository is always loaded.
46
     */
47
    @SuppressWarnings("restriction")
48
    public static void setP2UpdateRepositories() {
49
        List<MetadataRepositoryElement> repoElements = new ArrayList<MetadataRepositoryElement>();
50
        List<MetadataRepositoryElement> savedRepoElements = new ArrayList<>();
51

  
52
        MetadataRepositoryElement mre = new MetadataRepositoryElement(null, getP2UpdateRepository(), true);
53
        mre.setNickname(getP2UpdateRepositoryName());
54
        savedRepoElements.add(mre);
55

  
56
        repoElements.addAll(savedRepoElements);
57

  
58
        ElementUtils.updateRepositoryUsingElements(ProvisioningUI.getDefaultUI(),repoElements
59
                .toArray(new MetadataRepositoryElement[]{} ));
60

  
61
    }
62

  
63
    public static String getP2UpdateRepositoryName(){
64
        return ApplicationUtil.isStable()?EDIT_STABLE_UPDATE_SITE_NAME:EDIT_NIGHTLY_UPDATE_SITE_NAME;
65
    }
66

  
67
    public static URI getP2UpdateRepository(){
68
        try {
69
            return ApplicationUtil.isStable()?new URI(EDIT_STABLE_UPDATE_SITE):new URI(EDIT_NIGHTLY_UPDATE_SITE);
70
        } catch (URISyntaxException e) {
71
            MessagingUtils.error(P2Util.class, e);
72
        }
73
        return null;
74
    }
75

  
76
    /**
77
     * {@link org.eclipse.equinox.p2.ui.RepositoryManipulationPage} which handles the repsitory site list
78
     * in preferences does not create a preference store and hence the changes are not saved. This means
79
     * that we need to save it ourselves.
80
     *
81
     * This method saves the list of current repositories in the preference store as a string with
82
     * specific delimiters.
83
     */
84

  
85
    public static void saveP2RepositoryPreferences() {
86

  
87
        IMetadataRepositoryManager metaManager = ProvUI.getMetadataRepositoryManager(ProvisioningUI.getDefaultUI().getSession());
88

  
89
        URI[] currentlyEnabled = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
90
        URI[] currentlyDisabled = metaManager.getKnownRepositories(IRepositoryManager.REPOSITORIES_DISABLED);
91

  
92
        List<MetadataRepositoryElement> repoElements = new ArrayList<MetadataRepositoryElement>();
93

  
94
        for(URI repo : currentlyEnabled) {
95
            boolean enabled = true;
96
            String nickname = metaManager.getRepositoryProperty(repo, IRepository.PROP_NICKNAME);
97
            MetadataRepositoryElement element = new MetadataRepositoryElement(null, repo, true);
98
            element.setNickname(nickname);
99
            element.setEnabled(enabled);
100
            repoElements.add(element);
101
        }
102

  
103
        for(URI repo : currentlyDisabled) {
104
            boolean enabled = false;
105
            String nickname = metaManager.getRepositoryProperty(repo, IRepository.PROP_NICKNAME);
106
            MetadataRepositoryElement element = new MetadataRepositoryElement(null, repo, true);
107
            element.setNickname(nickname);
108
            element.setEnabled(enabled);
109
            repoElements.add(element);
110
        }
111
        PreferencesUtil.setP2Repositories(repoElements);
112
    }
113
}
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/handler/update/UpdateHandler.java
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package eu.etaxonomy.taxeditor.handler.update;
12

  
13
import java.net.URI;
14

  
15
import org.eclipse.core.runtime.IProgressMonitor;
16
import org.eclipse.core.runtime.IStatus;
17
import org.eclipse.core.runtime.Status;
18
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
19
import org.eclipse.core.runtime.jobs.Job;
20
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
21
import org.eclipse.e4.core.di.annotations.Execute;
22
import org.eclipse.e4.ui.di.UISynchronize;
23
import org.eclipse.e4.ui.workbench.IWorkbench;
24
import org.eclipse.equinox.p2.core.IProvisioningAgent;
25
import org.eclipse.equinox.p2.operations.ProvisioningJob;
26
import org.eclipse.equinox.p2.operations.ProvisioningSession;
27
import org.eclipse.equinox.p2.operations.UpdateOperation;
28
import org.eclipse.jface.dialogs.MessageDialog;
29
import org.eclipse.swt.widgets.Shell;
30

  
31
/**
32
 * UpdateHandler invokes the check for updates UI
33
 *
34
 * @since 3.4
35
 */
36
public class UpdateHandler {
37

  
38
    @Execute
39
    public void execute(final IProvisioningAgent agent, final Shell shell, final UISynchronize sync,
40
            final IWorkbench workbench) {
41
        Job updateJob = new Job("Update Job") {
42
            @Override
43
            protected IStatus run(final IProgressMonitor monitor) {
44
                return checkForUpdates(agent, shell, sync, workbench, monitor);
45
            }
46
        };
47
        updateJob.schedule();
48
    }
49

  
50
    private IStatus checkForUpdates(final IProvisioningAgent agent, final Shell shell, final UISynchronize sync,
51
            final IWorkbench workbench, IProgressMonitor monitor) {
52

  
53
        // configure update operation
54
        final ProvisioningSession session = new ProvisioningSession(agent);
55
        final UpdateOperation operation = new UpdateOperation(session);
56
        configureUpdate(operation);
57

  
58
        // check for updates, this causes I/O
59
        final IStatus status = operation.resolveModal(monitor);
60

  
61
        // failed to find updates (inform user and exit)
62
        if (status.getCode() == UpdateOperation.STATUS_NOTHING_TO_UPDATE) {
63
            showMessage(shell, sync);
64
            return Status.CANCEL_STATUS;
65
        }
66

  
67
        // run installation
68
        final ProvisioningJob provisioningJob = operation.getProvisioningJob(monitor);
69

  
70
        // updates cannot run from within Eclipse IDE!!!
71
        if (provisioningJob == null) {
72
            System.err.println("Trying to update from the Eclipse IDE? This won't work!");
73
            return Status.CANCEL_STATUS;
74
        }
75
        configureProvisioningJob(provisioningJob, shell, sync, workbench);
76

  
77
        provisioningJob.schedule();
78
        return Status.OK_STATUS;
79

  
80
    }
81

  
82
    private void configureProvisioningJob(ProvisioningJob provisioningJob, final Shell shell, final UISynchronize sync,
83
            final IWorkbench workbench) {
84

  
85
        // register a job change listener to track
86
        // installation progress and notify user upon success
87
        provisioningJob.addJobChangeListener(new JobChangeAdapter() {
88
            @Override
89
            public void done(IJobChangeEvent event) {
90
                if (event.getResult().isOK()) {
91
                    sync.syncExec(new Runnable() {
92

  
93
                        @Override
94
                        public void run() {
95
                            boolean restart = MessageDialog.openQuestion(shell, "Updates installed, restart?",
96
                                    "Updates have been installed. Do you want to restart?");
97
                            if (restart) {
98
                                workbench.restart();
99
                            }
100
                        }
101
                    });
102

  
103
                }
104
                super.done(event);
105
            }
106
        });
107

  
108
    }
109

  
110
    private void showMessage(final Shell parent, final UISynchronize sync) {
111
        sync.syncExec(new Runnable() {
112

  
113
            @Override
114
            public void run() {
115
                MessageDialog.openWarning(parent, "No update",
116
                        "No updates for the current installation have been found.");
117
            }
118
        });
119
    }
120

  
121
    private UpdateOperation configureUpdate(final UpdateOperation operation) {
122
        // create uri and check for validity
123
        URI uri = null;
124
        uri = P2Util.getP2UpdateRepository();
125

  
126
        // set location of artifact and metadata repo
127
        operation.getProvisioningContext().setArtifactRepositories(new URI[] { uri });
128
        operation.getProvisioningContext().setMetadataRepositories(new URI[] { uri });
129
        return operation;
130
    }
131

  
132
}
eu.etaxonomy.taxeditor.workbench/fragment.e4xmi
61 61
        <children xsi:type="menu:MenuSeparator" xmi:id="_7NbM4CQ7EeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.workbench.menuseparator.0"/>
62 62
        <children xsi:type="menu:HandledMenuItem" xmi:id="_Wg-doCQ8EeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.workbench.menu.help.dynamic" label="%command.label.15" mnemonics="D" command="_UIXAcCQ8EeeKsvEah5BAoQ"/>
63 63
        <children xsi:type="menu:HandledMenuItem" xmi:id="_dTyBcCQsEeeq76l4saMAFQ" elementId="eu.etaxonomy.taxeditor.workbench.menu.help.parser" label="%command.label.16" mnemonics="P" command="_UZ_WQCQsEeeq76l4saMAFQ"/>
64
        <children xsi:type="menu:MenuSeparator" xmi:id="_QZlooCQ8EeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.workbench.menuseparator.1"/>
65
        <children xsi:type="menu:HandledMenuItem" xmi:id="_JCjXYCRBEeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.workbench.handledmenuitem.commandlabel17" label="%command.label.17" mnemonics="C" command="_rSmScCQ8EeeKsvEah5BAoQ"/>
64
        <children xsi:type="menu:MenuSeparator" xmi:id="_QZlooCQ8EeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.workbench.menuseparator.beforeHelp"/>
66 65
        <children xsi:type="menu:MenuSeparator" xmi:id="_moFrICQ8EeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.workbench.menuseparator.2"/>
67 66
        <children xsi:type="menu:HandledMenuItem" xmi:id="_MtO5YCRBEeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.workbench.handledmenuitem.commandlabel19" label="%command.label.19" mnemonics="T" command="_tmIbUCQ8EeeKsvEah5BAoQ"/>
68 67
        <children xsi:type="menu:HandledMenuItem" xmi:id="_d0m2kCQsEeeq76l4saMAFQ" elementId="eu.etaxonomy.taxeditor.workbench.menu.help.about_edit" label="%command.label.20" mnemonics="E" command="_UZ2zYCQsEeeq76l4saMAFQ"/>
......
100 99
    <elements xsi:type="commands:Command" xmi:id="_xOYw4CQ7EeeKsvEah5BAoQ" elementId="org.eclipse.ui.help.helpContents" commandName="%command.label.13"/>
101 100
    <elements xsi:type="commands:Command" xmi:id="_-t3NwCQ7EeeKsvEah5BAoQ" elementId="org.eclipse.ui.help.helpSearch" commandName="%command.label.14"/>
102 101
    <elements xsi:type="commands:Command" xmi:id="_UIXAcCQ8EeeKsvEah5BAoQ" elementId="org.eclipse.ui.help.dynamicHelp" commandName="%command.label.15"/>
103
    <elements xsi:type="commands:Command" xmi:id="_rSmScCQ8EeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.update" commandName="%command.label.17"/>
104 102
    <elements xsi:type="commands:Command" xmi:id="_tmIbUCQ8EeeKsvEah5BAoQ" elementId="org.eclipse.ui.help.aboutAction" commandName="%command.label.19"/>
105 103
    <elements xsi:type="commands:Command" xmi:id="_koenACRAEeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.install" commandName="%command.label.18"/>
106 104
    <elements xsi:type="commands:Command" xmi:id="_fdEqUCUKEeeHw5lTgGMs1Q" elementId="eu.etaxonomy.taxeditor.workbench.ImportSettings" commandName="%command.label.25"/>
......
116 114
    <elements xsi:type="commands:Handler" xmi:id="_WLNcQyQsEeeq76l4saMAFQ" elementId="eu.etaxonomy.taxeditor.handler.OpenDatabaseRepairWizardHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.handler.OpenDatabaseRepairWizardHandler" command="_Va29YCQsEeeq76l4saMAFQ"/>
117 115
    <elements xsi:type="commands:Handler" xmi:id="_WLNcRCQsEeeq76l4saMAFQ" elementId="eu.etaxonomy.taxeditor.handler.OpenDatabasePreferencesWizardHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.handler.OpenDatabasePreferencesWizardHandler" command="_VawPsCQsEeeq76l4saMAFQ"/>
118 116
    <elements xsi:type="commands:Handler" xmi:id="_S6Rf4CRAEeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.update.InstallNewSoftwareHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.workbench/eu.etaxonomy.taxeditor.workbench.update.InstallNewSoftwareHandler" command="_koenACRAEeeKsvEah5BAoQ"/>
119
    <elements xsi:type="commands:Handler" xmi:id="_uzAhUCRAEeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.update.UpdateHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.workbench/eu.etaxonomy.taxeditor.workbench.update.UpdateHandler" command="_rSmScCQ8EeeKsvEah5BAoQ"/>
120 117
    <elements xsi:type="commands:Handler" xmi:id="_nSIiECUKEeeHw5lTgGMs1Q" elementId="eu.etaxonomy.taxeditor.handler.OpenImportPreferenceHandler" command="_fdEqUCUKEeeHw5lTgGMs1Q"/>
121 118
    <elements xsi:type="commands:Handler" xmi:id="_2fnUYCZ0EeeQLpuomSmVoQ" elementId="eu.etaxonomy.taxeditor.workbench.OpenPartHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.workbench/eu.etaxonomy.taxeditor.workbench.OpenPartHandler" command="_hMjgECZsEeer_rabtodzWA"/>
122 119
    <elements xsi:type="commands:Handler" xmi:id="_dBGosFp0Eee4PsIXei-TMg" elementId="eu.etaxonomy.taxeditor.workbench.SaveHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.workbench/eu.etaxonomy.taxeditor.workbench.SaveHandler" command="_X-56IFp0Eee4PsIXei-TMg"/>
eu.etaxonomy.taxeditor.workbench/src/main/java/eu/etaxonomy/taxeditor/workbench/update/UpdateHandler.java
1
/*******************************************************************************
2
 * Copyright (c) 2007, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 *******************************************************************************/
11
package eu.etaxonomy.taxeditor.workbench.update;
12

  
13
import org.eclipse.equinox.internal.p2.ui.dialogs.UpdateSingleIUWizard;
14
import org.eclipse.equinox.p2.operations.RepositoryTracker;
15
import org.eclipse.equinox.p2.operations.UpdateOperation;
16
import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
17
import org.eclipse.jface.wizard.WizardDialog;
18

  
19
/**
20
 * UpdateHandler invokes the check for updates UI
21
 *
22
 * @since 3.4
23
 */
24
public class UpdateHandler extends PreloadingRepositoryHandler {
25

  
26
    boolean hasNoRepos = false;
27

  
28
    @Override
29
    protected void doExecute(LoadMetadataRepositoryJob job) {
30
        if (hasNoRepos) {
31
            return;
32
        }
33
        UpdateOperation operation = getProvisioningUI().getUpdateOperation(null, null);
34

  
35

  
36
        // check for updates
37
        operation.resolveModal(null);
38
        if (getProvisioningUI().getPolicy().continueWorkingWithOperation(operation, getShell())) {
39
            if (UpdateSingleIUWizard.validFor(operation)) {
40
                // Special case for only updating a single root
41
                UpdateSingleIUWizard wizard = new UpdateSingleIUWizard(getProvisioningUI(), operation);
42
                WizardDialog dialog = new WizardDialog(getShell(), wizard);
43
                dialog.create();
44
                dialog.open();
45
            } else {
46
                // Open the normal version of the update wizard
47
                getProvisioningUI().openUpdateWizard(false, operation, job);
48
            }
49
        }
50
    }
51

  
52
    @Override
53
    protected boolean preloadRepositories() {
54
        hasNoRepos = false;
55
        RepositoryTracker repoMan = getProvisioningUI().getRepositoryTracker();
56
        if (repoMan.getKnownRepositories(getProvisioningUI().getSession()).length == 0) {
57
            hasNoRepos = true;
58
            return false;
59
        }
60
        return super.preloadRepositories();
61
    }
62
}

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)