Project

General

Profile

« Previous | Next » 

Revision 1104e1d6

Added by Patrick Plitzner about 7 years ago

ref #6566 Migrate help menu

View differences:

eu.etaxonomy.taxeditor.application/plugin.xml
60 60
            restorable="true">
61 61
      </view>
62 62
   </extension-->
63
   <extension
64
         point="org.eclipse.ui.menus">
65
      <menuContribution
66
            locationURI="menu:org.eclipse.ui.main.menu.help">
67
         <command
68
               commandId="org.eclipse.ui.help.helpContents"
69
               label="%command.label.13"
70
               style="push">
71
         </command>
72
         <command
73
               commandId="org.eclipse.ui.help.helpSearch"
74
               label="%command.label.14"
75
               style="push">
76
         </command>
77
         <separator
78
               name="eu.etaxonomy.taxeditor.ui.help.separator0"
79
               visible="true">
80
         </separator>
81
         <command
82
               commandId="org.eclipse.ui.help.dynamicHelp"
83
               label="%command.label.15"
84
               style="push">
85
         </command>
86
         <separator
87
               name="eu.etaxonomy.taxeditor.ui.help.separator1"
88
               visible="true">
89
         </separator>
90
         <command
91
               commandId="eu.etaxonomy.taxeditor.update"
92
               label="%command.label.17"
93
               style="push">
94
         </command>
95
         <separator
96
               name="eu.etaxonomy.taxeditor.ui.help.separator2"
97
               visible="true">
98
         </separator>
99
         <command
100
               commandId="org.eclipse.ui.help.aboutAction"
101
               label="%command.label.19">
102
         </command>
103
      </menuContribution>
104
   </extension>
105 63
   <extension
106 64
         id="product"
107 65
         point="org.eclipse.core.runtime.products">
......
145 103
         </property>
146 104
      </product>
147 105
   </extension>
148
   <extension
149
         point="org.eclipse.ui.commands">
150
      <command
151
            defaultHandler="eu.etaxonomy.taxeditor.update.UpdateHandler"
152
            id="eu.etaxonomy.taxeditor.update"
153
            name="%command.label.17">
154
      </command>
155
      <command
156
            defaultHandler="eu.etaxonomy.taxeditor.update.InstallNewSoftwareHandler"
157
            id="eu.etaxonomy.taxeditor.install"
158
            name="%command.label.18">
159
      </command>
160
   </extension>
161 106
   
162 107
   
163 108
	<extension
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/update/InstallNewSoftwareHandler.java
1
/*******************************************************************************
2
 *  Copyright (c) 2008, 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.update;
12

  
13
import org.eclipse.core.runtime.jobs.Job;
14
import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
15

  
16
/**
17
 * InstallNewSoftwareHandler invokes the install wizard
18
 * 
19
 * @since 3.5
20
 */
21
public class InstallNewSoftwareHandler extends PreloadingRepositoryHandler {
22

  
23
	/**
24
	 * The constructor.
25
	 */
26
	public InstallNewSoftwareHandler() {
27
		super();
28
	}
29

  
30
	protected void doExecute(LoadMetadataRepositoryJob job) {
31
		getProvisioningUI().openInstallWizard(null, null, job);
32
	}
33

  
34
	protected boolean waitForPreload() {
35
		// If the user cannot see repositories, then we may as well wait
36
		// for existing repos to load so that content is available.  
37
		// If the user can manipulate the repositories, then we don't wait, 
38
		// because we don't know which ones they want to work with.
39
		return !getProvisioningUI().getPolicy().getRepositoriesVisible();
40
	}
41

  
42
	protected void setLoadJobProperties(Job loadJob) {
43
		super.setLoadJobProperties(loadJob);
44
		// If we are doing a background load, we do not wish to authenticate, as the
45
		// user is unaware that loading was needed
46
		if (!waitForPreload()) {
47
			loadJob.setProperty(LoadMetadataRepositoryJob.SUPPRESS_AUTHENTICATION_JOB_MARKER, Boolean.toString(true));
48
			loadJob.setProperty(LoadMetadataRepositoryJob.SUPPRESS_REPOSITORY_EVENTS, Boolean.toString(true));
49
		}
50
	}
51
}
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/update/PreloadingRepositoryHandler.java
1
/*******************************************************************************
2
 * Copyright (c) 2008, 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.update;
12

  
13
import org.eclipse.core.commands.AbstractHandler;
14
import org.eclipse.core.commands.ExecutionEvent;
15
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
16
import org.eclipse.core.runtime.jobs.Job;
17
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
18
import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
19
import org.eclipse.equinox.p2.ui.ProvisioningUI;
20
import org.eclipse.swt.widgets.Shell;
21
import org.eclipse.ui.PlatformUI;
22

  
23
/**
24
 * PreloadingRepositoryHandler provides background loading of
25
 * repositories before executing the provisioning handler.
26
 * 
27
 * @since 3.5
28
 */
29
abstract class PreloadingRepositoryHandler extends AbstractHandler {
30

  
31
	/**
32
	 * The constructor.
33
	 */
34
	public PreloadingRepositoryHandler() {
35
		// constructor
36
	}
37

  
38
	/**
39
	 * Execute the command.
40
	 */
41
	public Object execute(ExecutionEvent event) {
42
		doExecuteAndLoad();
43
		return null;
44
	}
45

  
46
	void doExecuteAndLoad() {
47
		if (preloadRepositories()) {
48
			//cancel any load that is already running
49
			Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY);
50
			final LoadMetadataRepositoryJob loadJob = new LoadMetadataRepositoryJob(getProvisioningUI());
51
			setLoadJobProperties(loadJob);
52
			if (waitForPreload()) {
53
				loadJob.addJobChangeListener(new JobChangeAdapter() {
54
					public void done(IJobChangeEvent event) {
55
						if (PlatformUI.isWorkbenchRunning())
56
							if (event.getResult().isOK()) {
57
								PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
58
									public void run() {
59
										doExecute(loadJob);
60
									}
61
								});
62
							}
63
					}
64
				});
65
				loadJob.setUser(true);
66
				loadJob.schedule();
67

  
68
			} else {
69
				loadJob.setSystem(true);
70
				loadJob.setUser(false);
71
				loadJob.schedule();
72
				doExecute(null);
73
			}
74
		} else {
75
			doExecute(null);
76
		}
77
	}
78

  
79
	protected abstract void doExecute(LoadMetadataRepositoryJob job);
80

  
81
	protected boolean preloadRepositories() {
82
		return true;
83
	}
84

  
85
	protected boolean waitForPreload() {
86
		return true;
87
	}
88

  
89
	protected void setLoadJobProperties(Job loadJob) {
90
		loadJob.setProperty(LoadMetadataRepositoryJob.ACCUMULATE_LOAD_ERRORS, Boolean.toString(true));
91
	}
92

  
93
	protected ProvisioningUI getProvisioningUI() {
94
		return ProvisioningUI.getDefaultUI();
95
	}
96

  
97
	/**
98
	 * Return a shell appropriate for parenting dialogs of this handler.
99
	 * @return a Shell
100
	 */
101
	protected Shell getShell() {
102
		return PlatformUI.getWorkbench().getModalDialogShellProvider().getShell();
103
	}
104
}
eu.etaxonomy.taxeditor.application/src/main/java/eu/etaxonomy/taxeditor/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.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
}
eu.etaxonomy.taxeditor.workbench/META-INF/MANIFEST.MF
9 9
 org.eclipse.e4.ui.workbench,
10 10
 org.eclipse.e4.ui.model.workbench;bundle-version="1.2.0",
11 11
 org.eclipse.e4.core.di.annotations;bundle-version="1.5.0",
12
 org.apache.log4j;bundle-version="1.2.15"
12
 org.apache.log4j;bundle-version="1.2.15",
13
 org.eclipse.equinox.p2.ui,
14
 org.eclipse.equinox.p2.metadata;bundle-version="2.3.100",
15
 org.eclipse.equinox.p2.operations;bundle-version="2.4.200"
13 16
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
14 17
Bundle-ActivationPolicy: lazy
eu.etaxonomy.taxeditor.workbench/fragment.e4xmi
53 53
        </children>
54 54
      </children>
55 55
      <children xsi:type="menu:Menu" xmi:id="_FaGnvyQNEeen_7LZsZSNoA" elementId="eu.etaxonomy.taxeditor.workbench.menu.help" label="%menu.label.2">
56
        <children xsi:type="menu:HandledMenuItem" xmi:id="_dTyBcCQsEeeq76l4saMAFQ" elementId="id.commandlabel16" label="%command.label.16" command="_UZ_WQCQsEeeq76l4saMAFQ"/>
57
        <children xsi:type="menu:HandledMenuItem" xmi:id="_d0m2kCQsEeeq76l4saMAFQ" elementId="id.commandlabel20" label="%command.label.20" command="_UZ2zYCQsEeeq76l4saMAFQ"/>
56
        <children xsi:type="menu:HandledMenuItem" xmi:id="_3cDNACQ7EeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.workbench.menu.help.help_contents" label="%command.label.13" command="_xOYw4CQ7EeeKsvEah5BAoQ"/>
57
        <children xsi:type="menu:HandledMenuItem" xmi:id="_HqntYCQ8EeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.workbench.menu.help.search" label="%command.label.14" command="_-t3NwCQ7EeeKsvEah5BAoQ"/>
58
        <children xsi:type="menu:MenuSeparator" xmi:id="_7NbM4CQ7EeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.workbench.menuseparator.0"/>
59
        <children xsi:type="menu:HandledMenuItem" xmi:id="_Wg-doCQ8EeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.workbench.menu.help.dynamic" label="%command.label.15" command="_UIXAcCQ8EeeKsvEah5BAoQ"/>
60
        <children xsi:type="menu:HandledMenuItem" xmi:id="_dTyBcCQsEeeq76l4saMAFQ" elementId="eu.etaxonomy.taxeditor.workbench.menu.help.parser" label="%command.label.16" command="_UZ_WQCQsEeeq76l4saMAFQ"/>
61
        <children xsi:type="menu:MenuSeparator" xmi:id="_QZlooCQ8EeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.workbench.menuseparator.1"/>
62
        <children xsi:type="menu:HandledMenuItem" xmi:id="_JCjXYCRBEeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.workbench.handledmenuitem.commandlabel17" label="%command.label.17" command="_rSmScCQ8EeeKsvEah5BAoQ"/>
63
        <children xsi:type="menu:MenuSeparator" xmi:id="_moFrICQ8EeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.workbench.menuseparator.2"/>
64
        <children xsi:type="menu:HandledMenuItem" xmi:id="_MtO5YCRBEeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.workbench.handledmenuitem.commandlabel19" label="%command.label.19" command="_tmIbUCQ8EeeKsvEah5BAoQ"/>
65
        <children xsi:type="menu:HandledMenuItem" xmi:id="_d0m2kCQsEeeq76l4saMAFQ" elementId="eu.etaxonomy.taxeditor.workbench.menu.help.about_edit" label="%command.label.20" command="_UZ2zYCQsEeeq76l4saMAFQ"/>
58 66
      </children>
59 67
    </elements>
60 68
  </fragments>
......
86 94
    <elements xsi:type="commands:Command" xmi:id="_UZ_WQCQsEeeq76l4saMAFQ" elementId="eu.etaxonomy.taxeditor.workbench.help.parser" commandName="%command.name"/>
87 95
    <elements xsi:type="commands:Command" xmi:id="_VawPsCQsEeeq76l4saMAFQ" elementId="eu.etaxonomy.taxeditor.workbench.DatabaseSettings" commandName="%command.label.23"/>
88 96
    <elements xsi:type="commands:Command" xmi:id="_Va29YCQsEeeq76l4saMAFQ" elementId="eu.etaxonomy.taxeditor.workbench.DatabaseRepairFunctionality" commandName="%command.label.24"/>
97
    <elements xsi:type="commands:Command" xmi:id="_xOYw4CQ7EeeKsvEah5BAoQ" elementId="org.eclipse.ui.help.helpContents" commandName="%command.label.13"/>
98
    <elements xsi:type="commands:Command" xmi:id="_-t3NwCQ7EeeKsvEah5BAoQ" elementId="org.eclipse.ui.help.helpSearch" commandName="%command.label.14"/>
99
    <elements xsi:type="commands:Command" xmi:id="_UIXAcCQ8EeeKsvEah5BAoQ" elementId="org.eclipse.ui.help.dynamicHelp" commandName="%command.label.15"/>
100
    <elements xsi:type="commands:Command" xmi:id="_rSmScCQ8EeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.update" commandName="%command.label.17"/>
101
    <elements xsi:type="commands:Command" xmi:id="_tmIbUCQ8EeeKsvEah5BAoQ" elementId="org.eclipse.ui.help.aboutAction" commandName="%command.label.19"/>
102
    <elements xsi:type="commands:Command" xmi:id="_koenACRAEeeKsvEah5BAoQ" elementId="eu.etaxonomy.taxeditor.install" commandName="%command.label.18"/>
89 103
  </fragments>
90 104
  <fragments xsi:type="fragment:StringModelFragment" xmi:id="_WLNcQCQsEeeq76l4saMAFQ" featurename="handlers" parentElementId="org.eclipse.e4.legacy.ide.application">
91 105
    <elements xsi:type="commands:Handler" xmi:id="_WLNcQSQsEeeq76l4saMAFQ" elementId="eu.etaxonomy.taxeditor.OpenExternalAboutPlatformHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.workbench/eu.etaxonomy.taxeditor.workbench.OpenExternalAboutPlatformHandler" command="_UZ2zYCQsEeeq76l4saMAFQ"/>
92 106
    <elements xsi:type="commands:Handler" xmi:id="_WLNcQiQsEeeq76l4saMAFQ" elementId="eu.etaxonomy.taxeditor.OpenExternalParserHelpHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.workbench/eu.etaxonomy.taxeditor.workbench.OpenExternalParserHelpHandler" command="_UZ_WQCQsEeeq76l4saMAFQ"/>
93 107
    <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"/>
94 108
    <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"/>
109
    <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"/>
110
    <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"/>
95 111
  </fragments>
96 112
</fragment:ModelFragments>
eu.etaxonomy.taxeditor.workbench/src/eu/etaxonomy/taxeditor/workbench/update/InstallNewSoftwareHandler.java
1
/*******************************************************************************
2
 *  Copyright (c) 2008, 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.core.runtime.jobs.Job;
14
import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
15

  
16
/**
17
 * InstallNewSoftwareHandler invokes the install wizard
18
 *
19
 * @since 3.5
20
 */
21
public class InstallNewSoftwareHandler extends PreloadingRepositoryHandler {
22

  
23
	/**
24
	 * The constructor.
25
	 */
26
	public InstallNewSoftwareHandler() {
27
		super();
28
	}
29

  
30
	@Override
31
    protected void doExecute(LoadMetadataRepositoryJob job) {
32
		getProvisioningUI().openInstallWizard(null, null, job);
33
	}
34

  
35
	@Override
36
    protected boolean waitForPreload() {
37
		// If the user cannot see repositories, then we may as well wait
38
		// for existing repos to load so that content is available.
39
		// If the user can manipulate the repositories, then we don't wait,
40
		// because we don't know which ones they want to work with.
41
		return !getProvisioningUI().getPolicy().getRepositoriesVisible();
42
	}
43

  
44
	@Override
45
    protected void setLoadJobProperties(Job loadJob) {
46
		super.setLoadJobProperties(loadJob);
47
		// If we are doing a background load, we do not wish to authenticate, as the
48
		// user is unaware that loading was needed
49
		if (!waitForPreload()) {
50
			loadJob.setProperty(LoadMetadataRepositoryJob.SUPPRESS_AUTHENTICATION_JOB_MARKER, Boolean.toString(true));
51
			loadJob.setProperty(LoadMetadataRepositoryJob.SUPPRESS_REPOSITORY_EVENTS, Boolean.toString(true));
52
		}
53
	}
54
}
eu.etaxonomy.taxeditor.workbench/src/eu/etaxonomy/taxeditor/workbench/update/PreloadingRepositoryHandler.java
1
/*******************************************************************************
2
 * Copyright (c) 2008, 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.core.runtime.jobs.IJobChangeEvent;
14
import org.eclipse.core.runtime.jobs.Job;
15
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
16
import org.eclipse.e4.core.di.annotations.Execute;
17
import org.eclipse.equinox.p2.ui.LoadMetadataRepositoryJob;
18
import org.eclipse.equinox.p2.ui.ProvisioningUI;
19
import org.eclipse.swt.widgets.Shell;
20
import org.eclipse.ui.PlatformUI;
21

  
22
/**
23
 * PreloadingRepositoryHandler provides background loading of
24
 * repositories before executing the provisioning handler.
25
 *
26
 * @since 3.5
27
 */
28
abstract class PreloadingRepositoryHandler{
29

  
30
	/**
31
	 * The constructor.
32
	 */
33
	public PreloadingRepositoryHandler() {
34
		// constructor
35
	}
36

  
37
	/**
38
	 * Execute the command.
39
	 */
40
	@Execute
41
	public Object execute() {
42
		doExecuteAndLoad();
43
		return null;
44
	}
45

  
46
	private void doExecuteAndLoad() {
47
		if (preloadRepositories()) {
48
			//cancel any load that is already running
49
			Job.getJobManager().cancel(LoadMetadataRepositoryJob.LOAD_FAMILY);
50
			final LoadMetadataRepositoryJob loadJob = new LoadMetadataRepositoryJob(getProvisioningUI());
51
			setLoadJobProperties(loadJob);
52
			if (waitForPreload()) {
53
				loadJob.addJobChangeListener(new JobChangeAdapter() {
54
					@Override
55
                    public void done(IJobChangeEvent event) {
56
						if (PlatformUI.isWorkbenchRunning()) {
57
                            if (event.getResult().isOK()) {
58
								PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
59
									@Override
60
                                    public void run() {
61
										doExecute(loadJob);
62
									}
63
								});
64
							}
65
                        }
66
					}
67
				});
68
				loadJob.setUser(true);
69
				loadJob.schedule();
70

  
71
			} else {
72
				loadJob.setSystem(true);
73
				loadJob.setUser(false);
74
				loadJob.schedule();
75
				doExecute(null);
76
			}
77
		} else {
78
			doExecute(null);
79
		}
80
	}
81

  
82
	protected abstract void doExecute(LoadMetadataRepositoryJob job);
83

  
84
	protected boolean preloadRepositories() {
85
		return true;
86
	}
87

  
88
	protected boolean waitForPreload() {
89
		return true;
90
	}
91

  
92
	protected void setLoadJobProperties(Job loadJob) {
93
		loadJob.setProperty(LoadMetadataRepositoryJob.ACCUMULATE_LOAD_ERRORS, Boolean.toString(true));
94
	}
95

  
96
	protected ProvisioningUI getProvisioningUI() {
97
		return ProvisioningUI.getDefaultUI();
98
	}
99

  
100
	/**
101
	 * Return a shell appropriate for parenting dialogs of this handler.
102
	 * @return a Shell
103
	 */
104
	protected Shell getShell() {
105
		return PlatformUI.getWorkbench().getModalDialogShellProvider().getShell();
106
	}
107
}
eu.etaxonomy.taxeditor.workbench/src/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