Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 328067
Collapse All | Expand All

(-)plugin.properties (+1 lines)
Lines 29-34 Link Here
29
extensionPointServerMonitors=Server Monitors
29
extensionPointServerMonitors=Server Monitors
30
extensionPointInstallableServers=Installable Servers
30
extensionPointInstallableServers=Installable Servers
31
extensionPointInstallableRuntimes=Installable Runtimes
31
extensionPointInstallableRuntimes=Installable Runtimes
32
extensionPointSaveEditorPrompter=Save Editor Prompter
32
33
33
extensionPointRuntimeFacetComponentProviders=Runtime Facet Component Providers
34
extensionPointRuntimeFacetComponentProviders=Runtime Facet Component Providers
34
35
(-)plugin.xml (+1 lines)
Lines 20-25 Link Here
20
  <extension-point id="installableRuntimes" name="%extensionPointInstallableRuntimes" schema="schema/installableRuntimes.exsd"/>
20
  <extension-point id="installableRuntimes" name="%extensionPointInstallableRuntimes" schema="schema/installableRuntimes.exsd"/>
21
  <extension-point id="runtimeFacetComponentProviders" name="%extensionPointRuntimeFacetComponentProviders" schema="schema/runtimeFacetComponentProviders.exsd"/>
21
  <extension-point id="runtimeFacetComponentProviders" name="%extensionPointRuntimeFacetComponentProviders" schema="schema/runtimeFacetComponentProviders.exsd"/>
22
  <extension-point id="runtimeModuleType" name="%runtimeModuleType" schema="schema/runtimeModuleType.exsd"/>
22
  <extension-point id="runtimeModuleType" name="%runtimeModuleType" schema="schema/runtimeModuleType.exsd"/>
23
  <extension-point id="saveEditorPrompter" name="%extensionPointSaveEditorPrompter" schema="schema/saveEditorPrompter.exsd"/>
23
24
24
  <extension point="org.eclipse.wst.server.core.moduleTypes">
25
  <extension point="org.eclipse.wst.server.core.moduleTypes">
25
    <moduleType
26
    <moduleType
(-)schema/saveEditorPrompter.exsd (+121 lines)
Added Link Here
1
<?xml version='1.0' encoding='UTF-8'?>
2
<!-- Schema file written by PDE -->
3
<schema targetNamespace="org.eclipse.wst.server.core" xmlns="http://www.w3.org/2001/XMLSchema">
4
<annotation>
5
      <appInfo>
6
         <meta.schema plugin="org.eclipse.wst.server.core" id="saveEditorPrompter" name="%saveEditorPrompter"/>
7
      </appInfo>
8
      <documentation>
9
         This is an internal extension point that should only be adopted by org.eclipse.wst.server.core. It is used to transfer the control to the UI and save all the editors are open before continuing
10
      </documentation>
11
   </annotation>
12
13
   <element name="extension">
14
      <annotation>
15
         <appInfo>
16
            <meta.element />
17
         </appInfo>
18
      </annotation>
19
      <complexType>
20
         <sequence>
21
            <element ref="saveEditorPrompter"/>
22
         </sequence>
23
         <attribute name="point" type="string" use="required">
24
            <annotation>
25
               <documentation>
26
                  
27
               </documentation>
28
            </annotation>
29
         </attribute>
30
         <attribute name="id" type="string">
31
            <annotation>
32
               <documentation>
33
                  
34
               </documentation>
35
            </annotation>
36
         </attribute>
37
         <attribute name="name" type="string">
38
            <annotation>
39
               <documentation>
40
                  
41
               </documentation>
42
               <appInfo>
43
                  <meta.attribute translatable="true"/>
44
               </appInfo>
45
            </annotation>
46
         </attribute>
47
      </complexType>
48
   </element>
49
50
   <element name="saveEditorPrompter">
51
      <complexType>
52
         <attribute name="id" type="string" use="required">
53
            <annotation>
54
               <documentation>
55
                  
56
               </documentation>
57
            </annotation>
58
         </attribute>
59
         <attribute name="class" type="string" use="required">
60
            <annotation>
61
               <documentation>
62
                  
63
               </documentation>
64
               <appInfo>
65
                  <meta.attribute kind="java" basedOn="org.eclipse.wst.server.core.internal.SaveEditorPrompter:"/>
66
               </appInfo>
67
            </annotation>
68
         </attribute>
69
      </complexType>
70
   </element>
71
72
   <annotation>
73
      <appInfo>
74
         <meta.section type="since"/>
75
      </appInfo>
76
      <documentation>
77
         [Enter the first release in which this extension point appears.]
78
      </documentation>
79
   </annotation>
80
81
   <annotation>
82
      <appInfo>
83
         <meta.section type="examples"/>
84
      </appInfo>
85
      <documentation>
86
         [Enter extension point usage example here.]
87
      </documentation>
88
   </annotation>
89
90
   <annotation>
91
      <appInfo>
92
         <meta.section type="apiinfo"/>
93
      </appInfo>
94
      <documentation>
95
         [Enter API information here.]
96
      </documentation>
97
   </annotation>
98
99
   <annotation>
100
      <appInfo>
101
         <meta.section type="implementation"/>
102
      </appInfo>
103
      <documentation>
104
         [Enter information about supplied implementation of this extension point.]
105
      </documentation>
106
   </annotation>
107
108
   <annotation>
109
      <appInfo>
110
         <meta.section type="copyright"/>
111
      </appInfo>
112
      <documentation>
113
         Copyright (c) 2010 IBM Corporation and others.&lt;br&gt;
114
All rights reserved. This program and the accompanying materials are made 
115
available under the terms of the Eclipse Public License v1.0 which accompanies 
116
this distribution, and is available at 
117
&lt;a href=&quot;http://www.eclipse.org/legal/epl-v10.html&quot;&gt;http://www.eclipse.org/legal/epl-v10.html&lt;/a&gt;
118
      </documentation>
119
   </annotation>
120
121
</schema>
(-)servercore/org/eclipse/wst/server/core/internal/SaveEditorPrompter.java (+37 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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
12
package org.eclipse.wst.server.core.internal;
13
14
/**
15
 * <p>
16
 * SaveEditorPrompter is the abstract implementation of the .saveEditorPrompter extension 
17
 * point. This class is used for prompting to the user to save all the editors. The class 
18
 * transfer the control from the non-ui code to the UI code via an the extension point
19
 * </p>
20
 * <b>This class is not intended to be extended adopters.</b> 
21
 * 
22
 */
23
public class SaveEditorPrompter {
24
	
25
	/**
26
	 * Move the control to the UI and save all the editors according to <code>org.eclipse.debug.internal.ui.IInternalDebugUIConstants.PREF_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH</code>  
27
	 */
28
	public void saveAllEditors(){
29
		// nothing to do, should be implemented		
30
	}
31
	public void setDebugNeverSave(){
32
		// nothing to do, should be implemented		
33
	}
34
	public void setDebugOriginalValue(){
35
		// nothing to do, should be implemented		
36
	}
37
}
(-)servercore/org/eclipse/wst/server/core/internal/Server.java (-4 / +16 lines)
Lines 1911-1917 Link Here
1911
			else
1911
			else
1912
				pub = StartJob.PUBLISH_BEFORE;
1912
				pub = StartJob.PUBLISH_BEFORE;
1913
		}
1913
		}
1914
1914
		
1915
		if (ServerPlugin.isRunningGUIMode()){
1916
			ServerPlugin.getSaveEditorHelper().saveAllEditors();
1917
		}
1918
		
1915
		StartJob startJob = new StartJob(mode2);
1919
		StartJob startJob = new StartJob(mode2);
1916
		if (opListener != null && pub != StartJob.PUBLISH_AFTER) {
1920
		if (opListener != null && pub != StartJob.PUBLISH_AFTER) {
1917
			startJob.addJobChangeListener(new JobChangeAdapter() {
1921
			startJob.addJobChangeListener(new JobChangeAdapter() {
Lines 3198-3212 Link Here
3198
3202
3199
	protected void startImpl2(String mode2, IProgressMonitor monitor) throws CoreException {
3203
	protected void startImpl2(String mode2, IProgressMonitor monitor) throws CoreException {
3200
		Trace.trace(Trace.FINEST, "Starting server: " + Server.this.toString() + ", launchMode: " + mode2);
3204
		Trace.trace(Trace.FINEST, "Starting server: " + Server.this.toString() + ", launchMode: " + mode2);
3201
		
3205
		SaveEditorPrompter editorHelper = (ServerPlugin.isRunningGUIMode()) ? ServerPlugin.getSaveEditorHelper() : null;
3202
		// make sure that the delegate is loaded and the server state is correct
3206
		// make sure that the delegate is loaded and the server state is correct
3203
		loadAdapter(ServerBehaviourDelegate.class, monitor);
3207
		loadAdapter(ServerBehaviourDelegate.class, monitor);
3204
		
3208
		
3205
		try {
3209
		try {
3206
			ILaunchConfiguration launchConfig = getLaunchConfiguration(true, monitor);
3210
			ILaunchConfiguration launchConfig = getLaunchConfiguration(true, monitor);
3207
			//if (launchConfig == null)
3211
			
3208
			//	throw new CoreException();
3212
			if (editorHelper != null){
3213
				editorHelper.setDebugNeverSave();
3214
			}
3215
			
3209
			launch = launchConfig.launch(mode2, monitor); // , true); - causes workspace lock
3216
			launch = launchConfig.launch(mode2, monitor); // , true); - causes workspace lock
3217
			
3218
			if (editorHelper != null){
3219
				editorHelper.setDebugOriginalValue();
3220
			}
3221
			
3210
			Trace.trace(Trace.FINEST, "Launch: " + launch);
3222
			Trace.trace(Trace.FINEST, "Launch: " + launch);
3211
		} catch (CoreException e) {
3223
		} catch (CoreException e) {
3212
			Trace.trace(Trace.SEVERE, "Error starting server " + Server.this.toString(), e);
3224
			Trace.trace(Trace.SEVERE, "Error starting server " + Server.this.toString(), e);
(-)servercore/org/eclipse/wst/server/core/internal/ServerPlugin.java (-5 / +57 lines)
Lines 10-27 Link Here
10
 *******************************************************************************/
10
 *******************************************************************************/
11
package org.eclipse.wst.server.core.internal;
11
package org.eclipse.wst.server.core.internal;
12
12
13
import java.io.*;
13
import java.io.File;
14
import java.util.*;
15
import java.text.DateFormat;
14
import java.text.DateFormat;
15
import java.util.*;
16
16
17
import org.eclipse.core.resources.IProject;
17
import org.eclipse.core.resources.IProject;
18
import org.eclipse.core.runtime.*;
18
import org.eclipse.core.runtime.*;
19
import org.eclipse.core.runtime.jobs.Job;
19
import org.eclipse.core.runtime.jobs.Job;
20
import org.eclipse.osgi.util.NLS;
20
import org.eclipse.osgi.util.NLS;
21
import org.eclipse.wst.server.core.*;
21
import org.eclipse.wst.server.core.*;
22
import org.osgi.framework.BundleContext;
22
import org.osgi.framework.*;
23
import org.osgi.framework.BundleEvent;
24
import org.osgi.framework.BundleListener;
25
/**
23
/**
26
 * The main server plugin class.
24
 * The main server plugin class.
27
 */
25
 */
Lines 69-74 Link Here
69
	//	cached copy of all installable runtimes
67
	//	cached copy of all installable runtimes
70
	private static List<IInstallableRuntime> installableRuntimes;
68
	private static List<IInstallableRuntime> installableRuntimes;
71
69
70
	// cached copy of SaveEditorPrompter
71
	private static SaveEditorPrompter saveEditorPrompter;
72
	
73
	// cached copy of isRunningInGUICache
74
	public static boolean isRunningInGUICache = false;
75
72
	// registry listener
76
	// registry listener
73
	private static IRegistryChangeListener registryListener;
77
	private static IRegistryChangeListener registryListener;
74
	
78
	
Lines 1282-1285 Link Here
1282
			return Platform.getProduct().getProperty(key);
1286
			return Platform.getProduct().getProperty(key);
1283
		return value;
1287
		return value;
1284
	}
1288
	}
1289
	
1290
	public static boolean isRunningGUIMode(){
1291
		// check only when the the plugin is not Bundle.ACTIVE
1292
		if (isRunningInGUICache == true){
1293
			return isRunningInGUICache;
1294
		}
1295
1296
		Bundle swtEclipseUIbndl = Platform.getBundle("org.eclipse.ui");  //running in GUI mode if it is active.
1297
		if(swtEclipseUIbndl != null){
1298
			isRunningInGUICache= (swtEclipseUIbndl.getState() == Bundle.ACTIVE);
1299
			return isRunningInGUICache; 
1300
		}			
1301
		return false;
1302
	}	
1303
1304
1305
	/**
1306
	 * Transfer the control to the UI and prompts to save all the editors
1307
	 */
1308
	public static SaveEditorPrompter getSaveEditorHelper() {
1309
		loadSaveEditorExtension();
1310
		return saveEditorPrompter;
1311
	}
1312
1313
	private static void loadSaveEditorExtension() {
1314
		if (saveEditorPrompter != null)
1315
			return;
1316
		Trace.trace(Trace.EXTENSION_POINT, "->- Loading .saveEditorPrompter extension point ->-");
1317
		
1318
		IExtensionRegistry registry = Platform.getExtensionRegistry();
1319
		IConfigurationElement[] cf = registry.getConfigurationElementsFor(ServerPlugin.PLUGIN_ID, "saveEditorPrompter");
1320
		
1321
		int size = cf.length;
1322
		try{
1323
			saveEditorPrompter = (SaveEditorPrompter)cf[0].createExecutableExtension("class");
1324
			Trace.trace(Trace.EXTENSION_POINT, "  Loaded saveEditorPrompter: " + cf[0].getAttribute("id"));
1325
		} catch (CoreException ce){
1326
			Trace.trace(Trace.SEVERE, "  Could not load saveEditorPrompter: " + cf[0].getAttribute("id"), ce);			
1327
		}
1328
		if (size < 1) {
1329
			Trace.trace(Trace.WARNING, "  More than one .saveEditorPrompter found, only one loaded =>"+ cf[0].getAttribute("id"));
1330
		}
1331
		
1332
		Trace.trace(Trace.EXTENSION_POINT, "-<- Done loading .saveEditorPrompter extension point -<-");
1333
		
1334
	}
1335
	
1336
	
1285
}
1337
}
(-)plugin.xml (+7 lines)
Lines 623-626 Link Here
623
      </enablement>
623
      </enablement>
624
   </decorator>
624
   </decorator>
625
</extension>
625
</extension>
626
<extension
627
      point="org.eclipse.wst.server.core.saveEditorPrompter">
628
   <saveEditorPrompter
629
         class="org.eclipse.wst.server.ui.internal.SaveEditorPrompter"
630
         id="org.eclipse.wst.server.ui.saveEditorPrompter1">
631
   </saveEditorPrompter>
632
</extension>
626
</plugin>
633
</plugin>
(-)serverui/org/eclipse/wst/server/ui/internal/SaveEditorPrompter.java (+78 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2010 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 org.eclipse.wst.server.ui.internal;
12
13
import org.eclipse.debug.ui.DebugUITools;
14
import org.eclipse.jface.preference.IPreferenceStore;
15
import org.eclipse.swt.widgets.Display;
16
import org.eclipse.ui.IWorkbench;
17
import org.eclipse.ui.PlatformUI;
18
19
public class SaveEditorPrompter extends
20
		org.eclipse.wst.server.core.internal.SaveEditorPrompter { 
21
	
22
	private String cachedSaveBeforeLaunch;
23
	
24
	@Override
25
	public void saveAllEditors() {
26
		IWorkbench w = PlatformUI.getWorkbench();
27
		String saveBeforeLaunch = DebugUITools.getPreferenceStore().getString(org.eclipse.debug.internal.ui.IInternalDebugUIConstants.PREF_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH);
28
		if (saveBeforeLaunch.equalsIgnoreCase(org.eclipse.jface.dialogs.MessageDialogWithToggle.ALWAYS)){
29
			Display d =PlatformUI.getWorkbench().getDisplay();
30
			d.asyncExec(new SaveAllEditorsRunnable(w,false));
31
		}
32
		else if (saveBeforeLaunch.equalsIgnoreCase(org.eclipse.jface.dialogs.MessageDialogWithToggle.PROMPT)){
33
			Display d =PlatformUI.getWorkbench().getDisplay();
34
			d.asyncExec(new SaveAllEditorsRunnable(w,true));
35
		}
36
	}
37
	
38
	private class SaveAllEditorsRunnable implements Runnable{
39
		IWorkbench w;
40
		boolean confirm;
41
		public SaveAllEditorsRunnable(IWorkbench w, boolean confirm){
42
			this.w = w;
43
			this.confirm = confirm;
44
		}
45
		
46
		public void run() {
47
			w.saveAllEditors(confirm);
48
		}
49
	}
50
		
51
	/**
52
	 * Sets <code>org.eclipse.debug.internal.ui.IInternalDebugUIConstants.PREF_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH</code> to 
53
	 * the given value. The given value should be one of the following:
54
	 * <ul>
55
	 * <li><code>org.eclipse.jface.dialogs.MessageDialogWithToggle.ALWAYS</code></li>
56
	 * <li><code>org.eclipse.jface.dialogs.MessageDialogWithToggle.NEVER</code></li>
57
	 * <li><code>org.eclipse.jface.dialogs.MessageDialogWithToggle.PROMPT</code></li>
58
	 * </ul>  
59
	 * @see org.eclipse.jface.dialogs.MessageDialogWithToggle
60
	 */
61
	public String setDebugSaveBeforeLaunching(String newValue){
62
		IPreferenceStore debugPrefs = DebugUITools.getPreferenceStore();
63
		String oldValue = debugPrefs.getString(org.eclipse.debug.internal.ui.IInternalDebugUIConstants.PREF_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH);
64
		debugPrefs.setValue(org.eclipse.debug.internal.ui.IInternalDebugUIConstants.PREF_SAVE_DIRTY_EDITORS_BEFORE_LAUNCH, newValue);
65
		return oldValue; 
66
	}
67
	
68
	public void setDebugNeverSave(){
69
		cachedSaveBeforeLaunch = setDebugSaveBeforeLaunching(org.eclipse.jface.dialogs.MessageDialogWithToggle.NEVER);
70
	}
71
	
72
	public void setDebugOriginalValue(){
73
		if (cachedSaveBeforeLaunch == null){
74
			cachedSaveBeforeLaunch = org.eclipse.jface.dialogs.MessageDialogWithToggle.PROMPT;
75
		}
76
		setDebugSaveBeforeLaunching(cachedSaveBeforeLaunch);
77
	}
78
}

Return to bug 328067