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 162102 | Differences between
and this patch

Collapse All | Expand All

(-)Eclipse UI/org/eclipse/ui/internal/IWorkbenchHelpContextIds.java (+3 lines)
Lines 288-293 Link Here
288
	public static final String STARTUP_PREFERENCE_PAGE = PREFIX
288
	public static final String STARTUP_PREFERENCE_PAGE = PREFIX
289
			+ "startup_preference_page_context"; //$NON-NLS-1$
289
			+ "startup_preference_page_context"; //$NON-NLS-1$
290
290
291
	public static final String WORKSPACES_PREFERENCE_PAGE = PREFIX
292
	+ "workspaces_preference_page_context"; //$NON-NLS-1$
293
	
291
	public static final String RESPONSIVE_UI = PREFIX + "responsive_ui_context"; //$NON-NLS-1$
294
	public static final String RESPONSIVE_UI = PREFIX + "responsive_ui_context"; //$NON-NLS-1$
292
295
293
	// // Windows
296
	// // Windows
(-)reference/ref-startup.htm (-14 / +8 lines)
Lines 19-25 Link Here
19
  <img src="PLUGINS_ROOT/org.eclipse.help/command_link.png">
19
  <img src="PLUGINS_ROOT/org.eclipse.help/command_link.png">
20
  <strong>General &gt; Startup and Shutdown</strong></a>
20
  <strong>General &gt; Startup and Shutdown</strong></a>
21
21
22
  preference page allows the selection 
22
  preference page allows the selection
23
  of plug-ins to be automatically activated during workbench startup.&nbsp;</P>
23
  of plug-ins to be automatically activated during workbench startup.&nbsp;</P>
24
24
25
25
Lines 31-62 Link Here
31
<table BORDER CELLSPACING=0 >
31
<table BORDER CELLSPACING=0 >
32
  <caption>
32
  <caption>
33
  </caption>
33
  </caption>
34
  <tr> 
34
  <tr>
35
    <th> <div CLASS="Para">Option</div></th>
35
    <th> <div CLASS="Para">Option</div></th>
36
    <th> <div CLASS="Para">Description</div></th>
36
    <th> <div CLASS="Para">Description</div></th>
37
    <th> <div CLASS="Para">Default</div></th>
37
    <th> <div CLASS="Para">Default</div></th>
38
  </tr>
38
  </tr>
39
  <tr> 
39
  <tr>
40
    <td> <div CLASS="Para">Prompt for workspace on startup</div></td>
41
    <td> <div CLASS="Para">If this option is turned on then the workbench will 
42
        prompt you each time it is started for what workspace to use.</div></td>
43
    <td> <div CLASS="Para">On</div></td>
44
  </tr>
45
  <tr> 
46
    <td> <div CLASS="Para">Refresh workspace on startup</div></td>
40
    <td> <div CLASS="Para">Refresh workspace on startup</div></td>
47
    <td> <div CLASS="Para">If this option is turned on then the workbench will 
41
    <td> <div CLASS="Para">If this option is turned on then the workbench will
48
        synchronize its contents with the file system on startup.</div></td>
42
        synchronize its contents with the file system on startup.</div></td>
49
    <td> <div CLASS="Para">Off</div></td>
43
    <td> <div CLASS="Para">Off</div></td>
50
  </tr>
44
  </tr>
51
  <tr> 
45
  <tr>
52
    <td> <div CLASS="Para">Confirm exit when closing last window</div></td>
46
    <td> <div CLASS="Para">Confirm exit when closing last window</div></td>
53
    <td> <div CLASS="Para">If this option is turned on then the workbench will 
47
    <td> <div CLASS="Para">If this option is turned on then the workbench will
54
        ask if you wish to exit when closing the last window if.</div></td>
48
        ask if you wish to exit when closing the last window if.</div></td>
55
    <td> <div CLASS="Para">On</div></td>
49
    <td> <div CLASS="Para">On</div></td>
56
  </tr>
50
  </tr>
57
  <tr> 
51
  <tr>
58
    <td> <div CLASS="Para">Plug-ins activated on startup</div></td>
52
    <td> <div CLASS="Para">Plug-ins activated on startup</div></td>
59
    <td> <div CLASS="Para">This option allows you to select which available plug-ins 
53
    <td> <div CLASS="Para">This option allows you to select which available plug-ins
60
        should be activated on startup.</div></td>
54
        should be activated on startup.</div></td>
61
    <td> <div CLASS="Para"></div></td>
55
    <td> <div CLASS="Para"></div></td>
62
  </tr>
56
  </tr>
(-)contexts_Workbench.xml (+4 lines)
Lines 828-833 Link Here
828
        <description>This page shows you all of the plug-ins that are activated when the workbench starts.</description>
828
        <description>This page shows you all of the plug-ins that are activated when the workbench starts.</description>
829
        <topic label="Preferences - Startup" href="reference/ref-startup.htm"/>
829
        <topic label="Preferences - Startup" href="reference/ref-startup.htm"/>
830
    </context>
830
    </context>
831
    <context id="workspaces_preference_page_context">
832
        <description>This page allows you to control the prompting to select a workspace when the workbench starts.</description>
833
        <topic label="Preferences - Startup Workspaces" href="reference/ref-startup-workspaces.htm"/>
834
    </context>
831
    <context id="working_set_new_wizard_context">
835
    <context id="working_set_new_wizard_context">
832
        <description>This wizard will guide you through the process of creating a working set.</description>
836
        <description>This wizard will guide you through the process of creating a working set.</description>
833
    </context>
837
    </context>
(-)topics_Reference.xml (+1 lines)
Lines 146-151 Link Here
146
			</enablement>
146
			</enablement>
147
		</topic>
147
		</topic>
148
		<topic label="Startup and Shutdown" href="reference/ref-startup.htm"></topic>
148
		<topic label="Startup and Shutdown" href="reference/ref-startup.htm"></topic>
149
		<topic label="Workspaces" href="reference/ref-startup-workspaces.htm"></topic>
149
		<topic label="Team" href="reference/ref-19.htm">
150
		<topic label="Team" href="reference/ref-19.htm">
150
			<enablement>
151
			<enablement>
151
				<test property="org.eclipse.core.runtime.isBundleInstalled" args="org.eclipse.team.ui"/>
152
				<test property="org.eclipse.core.runtime.isBundleInstalled" args="org.eclipse.team.ui"/>
(-)reference/ref-startup-workspaces.htm (+62 lines)
Added Link Here
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML>
2
<HEAD>
3
4
<meta name="copyright" content="Copyright (c) Eric Rizzo and others 2000, 2005. This page is made available under license. For full details see the LEGAL in the documentation book that contains this page." >
5
6
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=ISO-8859-1">
7
<META HTTP-EQUIV="Content-Style-Type" CONTENT="text/css">
8
9
<script language="JavaScript" src="PLUGINS_ROOT/org.eclipse.help/livehelp.js"></script>
10
<LINK REL="STYLESHEET" HREF="../book.css" CHARSET="ISO-8859-1" TYPE="text/css">
11
<title>Startup and Shutdown, Workspaces</title>
12
13
</HEAD>
14
<BODY BGCOLOR="#ffffff">
15
<H1 CLASS="Head"> Startup and Shutdown, Workspaces </H1>
16
<P CLASS="Para"> The
17
18
  <a class="command-link" href='javascript:executeCommand("org.eclipse.ui.window.preferences(preferencePageId=org.eclipse.ui.preferencePages.Startup.Workspaces)")'>
19
  <img src="PLUGINS_ROOT/org.eclipse.help/command_link.png">
20
  <strong>General &gt; Startup and Shutdown &gt; Workspaces</strong></a>
21
22
  preference page allows configuration of the workspace prompting during IDE startup.</P>
23
24
25
<table BORDER CELLSPACING=0 >
26
  <caption>
27
  </caption>
28
  <tr>
29
    <th> <div CLASS="Para">Option</div></th>
30
    <th> <div CLASS="Para">Description</div></th>
31
    <th> <div CLASS="Para">Default</div></th>
32
  </tr>
33
  <tr>
34
    <td> <div CLASS="Para">Prompt for workspace on startup</div></td>
35
    <td> <div CLASS="Para">If this option is turned on then the workbench will
36
        prompt you each time it is started for what workspace to use.</div></td>
37
    <td> <div CLASS="Para">On</div></td>
38
  </tr>
39
  <tr>
40
    <td> <div CLASS="Para">Number of recent workspaces to remember</div></td>
41
    <td> <div CLASS="Para">The maximum number of recently-used workspaces that will be remembered and presented in the "Workspace Launcher" dialog.</div></td>
42
    <td> <div CLASS="Para">5</div></td>
43
  </tr>
44
  <tr>
45
    <td> <div CLASS="Para">Recent workspaces</div></td>
46
    <td> <div CLASS="Para">The list of recently used workspaces that are presented in the "Workspace Launcher" dialog.</div></td>
47
    <td> <div CLASS="Para">&lt;none&gt;</div></td>
48
  </tr>
49
</table>
50
51
<P>Here is what the workspaces preference page looks like:&nbsp; </P>
52
53
54
<P>
55
</P>
56
57
58
<P>&nbsp;
59
</P>
60
61
</BODY>
62
</HTML>
(-)src/org/eclipse/ui/internal/ide/messages.properties (+4 lines)
Lines 269-274 Link Here
269
269
270
RebuildAction_text = Rebuild Pro&ject
270
RebuildAction_text = Rebuild Pro&ject
271
RebuildAction_tooltip = Full Build Of Selected Projects
271
RebuildAction_tooltip = Full Build Of Selected Projects
272
RecentWorkspacesPreferencePage_NumberOfWorkspaces_label=&Number of recent workspaces to remember:
273
RecentWorkspacesPreferencePage_PromptAtStartup_label=Prompt for &workspace on startup
274
RecentWorkspacesPreferencePage_RecentWorkspacesList_label=Recent workspaces
275
RecentWorkspacesPreferencePage_RemoveButton_label=&Remove
272
276
273
RefreshAction_text = Re&fresh
277
RefreshAction_text = Re&fresh
274
RefreshAction_toolTip = Refresh
278
RefreshAction_toolTip = Refresh
(-)src/org/eclipse/ui/internal/ide/ChooseWorkspaceData.java (-1 / +13 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 IBM Corporation and others.
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Eric Rizzo - added API to set the list of recent workspaces.
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.internal.ide;
12
package org.eclipse.ui.internal.ide;
12
13
Lines 192-197 Link Here
192
    }
193
    }
193
194
194
    /**
195
    /**
196
     * Sets the list of recent workspaces.
197
     */
198
    public void setRecentWorkspaces(String[] workspaces) {
199
    	if (workspaces == null) {
200
    		recentWorkspaces = new String[0];
201
    	} else {
202
			recentWorkspaces = workspaces;
203
		}
204
    }
205
206
    /**
195
	 * Update the persistent store. Call this function after the currently
207
	 * Update the persistent store. Call this function after the currently
196
	 * selected value has been found to be ok.
208
	 * selected value has been found to be ok.
197
	 */
209
	 */
(-)src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java (+7 lines)
Lines 499-504 Link Here
499
	public static String StartupPreferencePage_launchPromptButton;
499
	public static String StartupPreferencePage_launchPromptButton;
500
	public static String StartupPreferencePage_exitPromptButton;
500
	public static String StartupPreferencePage_exitPromptButton;
501
501
502
	// --- Startup -> Workspaces preferences ---
503
	public static String RecentWorkspacesPreferencePage_NumberOfWorkspaces_label;
504
	public static String RecentWorkspacesPreferencePage_PromptAtStartup_label;
505
	public static String RecentWorkspacesPreferencePage_RecentWorkspacesList_label;
506
	public static String RecentWorkspacesPreferencePage_RemoveButton_label;
507
508
502
	// --- Info ---
509
	// --- Info ---
503
	public static String ResourceInfo_readOnly;
510
	public static String ResourceInfo_readOnly;
504
	public static String ResourceInfo_executable;
511
	public static String ResourceInfo_executable;
(-)plugin.properties (+1 lines)
Lines 219-224 Link Here
219
PreferenceKeywords.Restore = restore
219
PreferenceKeywords.Restore = restore
220
PreferenceKeywords.State = state
220
PreferenceKeywords.State = state
221
PreferenceKeywords.Encoding = encoding
221
PreferenceKeywords.Encoding = encoding
222
PreferenceKeywords.RecentWorkspaces = workspaces prompt recent startup
222
223
223
# TODO This stuff is just to help me work on the parsing of the menus extension
224
# TODO This stuff is just to help me work on the parsing of the menus extension
224
# point.  It is likely not in its final form yet.
225
# point.  It is likely not in its final form yet.
(-)plugin.xml (-1 / +4 lines)
Lines 411-416 Link Here
411
            id="org.eclipse.ui.ide.startupAndShutdown"
411
            id="org.eclipse.ui.ide.startupAndShutdown"
412
            label="%PreferenceKeywords.StartupAndShutdown"/>
412
            label="%PreferenceKeywords.StartupAndShutdown"/>
413
      <keyword
413
      <keyword
414
            id="org.eclipse.ui.ide.recentWorkspaces"
415
            label="%PreferenceKeywords.RecentWorkspaces"/>
416
      <keyword
414
            id="org.eclipse.ui.ide.workspace"
417
            id="org.eclipse.ui.ide.workspace"
415
            label="%PreferenceKeywords.Workspace"/>
418
            label="%PreferenceKeywords.Workspace"/>
416
      <keyword
419
      <keyword
Lines 2234-2240 Link Here
2234
            type="org.eclipse.core.resources.IMarker">
2237
            type="org.eclipse.core.resources.IMarker">
2235
      </propertyTester>
2238
      </propertyTester>
2236
   </extension>
2239
   </extension>
2237
      <extension
2240
   <extension
2238
         point="org.eclipse.ui.installationPages">
2241
         point="org.eclipse.ui.installationPages">
2239
          <page
2242
          <page
2240
            name="%installationPage.feature.name"
2243
            name="%installationPage.feature.name"
(-)src/org/eclipse/ui/internal/ide/application/dialogs/IDEStartupPreferencePage.java (-29 / +2 lines)
Lines 1-5 Link Here
1
/*******************************************************************************
1
/*******************************************************************************
2
 * Copyright (c) 2004, 2007 IBM Corporation and others.
2
 * Copyright (c) 2004, 2009 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
5
 * which accompanies this distribution, and is available at
Lines 7-12 Link Here
7
 *
7
 *
8
 * Contributors:
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
9
 *     IBM Corporation - initial API and implementation
10
 *     Eric Rizzo - removed "prompt for workspace on startup" checkbox
10
 *******************************************************************************/
11
 *******************************************************************************/
11
package org.eclipse.ui.internal.ide.application.dialogs;
12
package org.eclipse.ui.internal.ide.application.dialogs;
12
13
Lines 21-27 Link Here
21
import org.eclipse.ui.PlatformUI;
22
import org.eclipse.ui.PlatformUI;
22
import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
23
import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
23
import org.eclipse.ui.internal.dialogs.StartupPreferencePage;
24
import org.eclipse.ui.internal.dialogs.StartupPreferencePage;
24
import org.eclipse.ui.internal.ide.ChooseWorkspaceData;
25
import org.eclipse.ui.internal.ide.IDEInternalPreferences;
25
import org.eclipse.ui.internal.ide.IDEInternalPreferences;
26
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
26
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
27
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
27
import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin;
Lines 38-45 Link Here
38
38
39
    private Button refreshButton;
39
    private Button refreshButton;
40
40
41
    private Button launchPromptButton;
42
43
    private Button exitPromptButton;
41
    private Button exitPromptButton;
44
42
45
    /*
43
    /*
Lines 54-60 Link Here
54
52
55
        Composite composite = createComposite(parent);
53
        Composite composite = createComposite(parent);
56
54
57
        createLaunchPromptPref(composite);
58
        createRefreshWorkspaceOnStartupPref(composite);
55
        createRefreshWorkspaceOnStartupPref(composite);
59
        createExitPromptPref(composite);
56
        createExitPromptPref(composite);
60
57
Lines 72-79 Link Here
72
    protected void performDefaults() {
69
    protected void performDefaults() {
73
        IPreferenceStore store = getIDEPreferenceStore();
70
        IPreferenceStore store = getIDEPreferenceStore();
74
71
75
        launchPromptButton.setSelection(true);
76
77
        refreshButton
72
        refreshButton
78
                .setSelection(store
73
                .setSelection(store
79
                        .getDefaultBoolean(IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP));
74
                        .getDefaultBoolean(IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP));
Lines 94-107 Link Here
94
        store.setValue(IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP,
89
        store.setValue(IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP,
95
                refreshButton.getSelection());
90
                refreshButton.getSelection());
96
91
97
        // TODO: This should get the value from the configuration preference
98
        //       area, but dj said we shouldn't use it yet; some final details are
99
        //       being worked out. Hopefully it will be available soon, at which time
100
        //       the entire recentWorkspaces.xml file can be removed. But until then,
101
        //       this preference reads/writes the file each time.
102
        ChooseWorkspaceData.setShowDialogValue(launchPromptButton
103
                .getSelection());
104
105
        // store the exit prompt on last window close setting
92
        // store the exit prompt on last window close setting
106
        store.setValue(IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW,
93
        store.setValue(IDEInternalPreferences.EXIT_PROMPT_ON_CLOSE_LAST_WINDOW,
107
                exitPromptButton.getSelection());
94
                exitPromptButton.getSelection());
Lines 119-138 Link Here
119
                IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP));
106
                IDEInternalPreferences.REFRESH_WORKSPACE_ON_STARTUP));
120
    }
107
    }
121
108
122
    protected void createLaunchPromptPref(Composite composite) {
123
        launchPromptButton = new Button(composite, SWT.CHECK);
124
        launchPromptButton.setText(IDEWorkbenchMessages.StartupPreferencePage_launchPromptButton);
125
        launchPromptButton.setFont(composite.getFont());
126
127
        // TODO: This should get the value from the configuration preference
128
        //       area, but dj said we shouldn't use it yet; some final details are
129
        //       being worked out. Hopefully it will be available soon, at which time
130
        //       the entire recentWorkspaces.xml file can be removed. But until then,
131
        //       this preference reads/writes the file each time.
132
        launchPromptButton.setSelection(ChooseWorkspaceData
133
                .getShowDialogValue());
134
    }
135
136
    protected void createExitPromptPref(Composite composite) {
109
    protected void createExitPromptPref(Composite composite) {
137
        exitPromptButton = new Button(composite, SWT.CHECK);
110
        exitPromptButton = new Button(composite, SWT.CHECK);
138
        exitPromptButton.setText(IDEWorkbenchMessages.StartupPreferencePage_exitPromptButton);
111
        exitPromptButton.setText(IDEWorkbenchMessages.StartupPreferencePage_exitPromptButton);
(-)plugin.xml (+7 lines)
Lines 19-24 Link Here
19
            id="org.eclipse.ui.preferencePages.Startup">
19
            id="org.eclipse.ui.preferencePages.Startup">
20
         <keywordReference id="org.eclipse.ui.ide.startupAndShutdown"/>
20
         <keywordReference id="org.eclipse.ui.ide.startupAndShutdown"/>
21
      </page>
21
      </page>
22
     <page
23
            name="%PreferencePages.Startup.Workspaces"
24
            category="org.eclipse.ui.preferencePages.Startup"
25
            class="org.eclipse.ui.internal.ide.application.dialogs.RecentWorkspacesPreferencePage"
26
            id="org.eclipse.ui.preferencePages.Startup.Workspaces">
27
         <keywordReference id="org.eclipse.ui.ide.recentWorkspaces"/>
28
      </page>
22
    </extension>
29
    </extension>
23
     <extension
30
     <extension
24
         point="org.eclipse.ui.perspectives">
31
         point="org.eclipse.ui.perspectives">
(-)plugin.properties (+1 lines)
Lines 12-17 Link Here
12
Plugin.providerName = Eclipse.org
12
Plugin.providerName = Eclipse.org
13
13
14
PreferencePages.Startup = Startup and Shutdown
14
PreferencePages.Startup = Startup and Shutdown
15
PreferencePages.Startup.Workspaces = Workspaces
15
16
16
Perspective.resourcePerspective = Resource
17
Perspective.resourcePerspective = Resource
17
Perspective.resourceDescription = This perspective is designed to provide general resource viewing and navigation. 
18
Perspective.resourceDescription = This perspective is designed to provide general resource viewing and navigation. 
(-)src/org/eclipse/ui/internal/ide/application/dialogs/RecentWorkspacesPreferencePage.java (+187 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2009 Eric Rizzo 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
 *     Eric Rizzo - initial API and implementation
10
 *******************************************************************************/
11
package org.eclipse.ui.internal.ide.application.dialogs;
12
13
import java.util.ArrayList;
14
import java.util.Arrays;
15
16
import org.eclipse.core.runtime.Platform;
17
import org.eclipse.jface.preference.PreferencePage;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.events.SelectionAdapter;
20
import org.eclipse.swt.events.SelectionEvent;
21
import org.eclipse.swt.layout.GridData;
22
import org.eclipse.swt.layout.GridLayout;
23
import org.eclipse.swt.widgets.Button;
24
import org.eclipse.swt.widgets.Composite;
25
import org.eclipse.swt.widgets.Control;
26
import org.eclipse.swt.widgets.Group;
27
import org.eclipse.swt.widgets.Label;
28
import org.eclipse.swt.widgets.List;
29
import org.eclipse.swt.widgets.Spinner;
30
import org.eclipse.ui.IWorkbench;
31
import org.eclipse.ui.IWorkbenchPreferencePage;
32
import org.eclipse.ui.PlatformUI;
33
import org.eclipse.ui.internal.IWorkbenchHelpContextIds;
34
import org.eclipse.ui.internal.ide.ChooseWorkspaceData;
35
import org.eclipse.ui.internal.ide.IDEWorkbenchMessages;
36
37
/**
38
 * Preference page for editing the list of recent workspaces and whether or not
39
 * the user is prompted at startup.
40
 * 
41
 * @since 3.5
42
 */
43
public class RecentWorkspacesPreferencePage extends PreferencePage
44
	implements IWorkbenchPreferencePage {
45
46
	private static final int MIN_WORKSPACS = 5;
47
	private static final int MAX_WORKSPACES = 99;
48
	private static final int MAX_WORKSPACES_DIGIT_COUNT = 2;
49
50
	private ChooseWorkspaceData workspacesData;
51
52
	private Button promptOption;
53
	private Spinner maxWorkspacesField;
54
	private List workspacesList;
55
	private Button removeButton;
56
57
58
	public void init(IWorkbench workbench) {
59
		workspacesData = new ChooseWorkspaceData(Platform.getInstanceLocation().getURL());
60
	}
61
62
	public Control createContents(Composite parent) {
63
    	PlatformUI.getWorkbench().getHelpSystem().setHelp(parent,
64
				IWorkbenchHelpContextIds.WORKSPACES_PREFERENCE_PAGE);
65
66
		Composite container = new Composite(parent, SWT.NULL);
67
		final GridLayout gridLayout = new GridLayout();
68
		gridLayout.numColumns = 2;
69
		gridLayout.marginHeight = 0;
70
		gridLayout.marginWidth = 0;
71
		container.setLayout(gridLayout);
72
73
		createPromptOption(container);
74
		createMaxWorkspacesField(container);
75
		createWorkspacesList(container);
76
77
		return container;
78
	}
79
80
81
	protected void createPromptOption(Composite parent) {
82
		promptOption = new Button(parent, SWT.CHECK);
83
		promptOption.setText(IDEWorkbenchMessages.RecentWorkspacesPreferencePage_PromptAtStartup_label);
84
		promptOption.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1));
85
86
		promptOption.setSelection(workspacesData.getShowDialog());
87
		promptOption.addSelectionListener(new SelectionAdapter(){
88
				public void widgetSelected(SelectionEvent event) {
89
					workspacesData.toggleShowDialog();
90
				}
91
			});
92
	}
93
94
95
	protected void createMaxWorkspacesField(Composite parent) {
96
		final Label maxWorkspacesLabel = new Label(parent, SWT.NONE);
97
		maxWorkspacesLabel.setText(IDEWorkbenchMessages.RecentWorkspacesPreferencePage_NumberOfWorkspaces_label);
98
		maxWorkspacesField = new Spinner(parent, SWT.BORDER);
99
		maxWorkspacesField.setTextLimit(MAX_WORKSPACES_DIGIT_COUNT);
100
		maxWorkspacesField.setMinimum(MIN_WORKSPACS);
101
		maxWorkspacesField.setMaximum(MAX_WORKSPACES);
102
103
		maxWorkspacesField.setSelection(workspacesData.getRecentWorkspaces().length);
104
	}
105
106
107
	protected void createWorkspacesList(Composite parent) {
108
		final Group recentWorkspacesGroup = new Group(parent, SWT.NONE);
109
		recentWorkspacesGroup.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 2, 1));
110
		recentWorkspacesGroup.setText(IDEWorkbenchMessages.RecentWorkspacesPreferencePage_RecentWorkspacesList_label);
111
		final GridLayout gridLayout_1 = new GridLayout();
112
		gridLayout_1.numColumns = 2;
113
		recentWorkspacesGroup.setLayout(gridLayout_1);
114
		
115
		workspacesList = new List(recentWorkspacesGroup, SWT.BORDER | SWT.MULTI);
116
		final GridData gd_workspacesList = new GridData(SWT.FILL, SWT.FILL, true, true);
117
		workspacesList.setLayoutData(gd_workspacesList);
118
		
119
		removeButton = new Button(recentWorkspacesGroup, SWT.NONE);
120
		final GridData gd_removeButton = new GridData(SWT.CENTER, SWT.TOP, false, false);
121
		removeButton.setLayoutData(gd_removeButton);
122
		removeButton.setText(IDEWorkbenchMessages.RecentWorkspacesPreferencePage_RemoveButton_label);
123
		removeButton.setEnabled(false);
124
125
		removeButton.addSelectionListener(new SelectionAdapter(){
126
				public void widgetSelected(SelectionEvent event) {
127
					removeSelectedWorkspaces();
128
				}
129
			});
130
131
		workspacesList.addSelectionListener(new SelectionAdapter() {
132
				public void widgetSelected(SelectionEvent event) {
133
					removeButton.setEnabled(workspacesList.getSelectionCount() > 0);
134
				}
135
			});
136
137
		String[] recentWorkspaces = workspacesData.getRecentWorkspaces();
138
		for (int i = 0; i < recentWorkspaces.length; i++) {
139
			String aWorkspace = recentWorkspaces[i];
140
			if (aWorkspace != null) {
141
				workspacesList.add(aWorkspace);
142
			}
143
		}
144
	}
145
146
147
	protected void removeSelectedWorkspaces() {
148
		// This would be a lot less code if we could use Jakarta CollectionUtils and/or ArrayUtils
149
150
		int[] selected = workspacesList.getSelectionIndices();
151
		java.util.List workspaces = new ArrayList(Arrays.asList(workspacesList.getItems()));
152
153
		// Iterate bottom-up because removal changes indices in the list
154
		for (int i = selected.length-1; i >= 0; i--) {
155
			workspaces.remove(selected[i]);
156
		}
157
158
		String[] newItems = new String[workspaces.size()];
159
		workspaces.toArray(newItems);
160
		workspacesList.setItems(newItems);
161
	}
162
163
164
	protected void performDefaults() {
165
		promptOption.setSelection(true);
166
		super.performDefaults();
167
	}
168
169
170
	public boolean performOk() {
171
		int maxWorkspaces = maxWorkspacesField.getSelection();
172
		String[] workspaces = new String[maxWorkspaces];
173
		String[] listItems = workspacesList.getItems();
174
175
		if (maxWorkspaces < listItems.length) {
176
			// TODO: maybe alert the user that the list will be truncated?
177
			System.arraycopy(listItems, 0, workspaces, 0, maxWorkspaces);
178
		} else  {
179
			System.arraycopy(listItems, 0, workspaces, 0, listItems.length);
180
		}
181
182
		workspacesData.setRecentWorkspaces(workspaces);
183
		workspacesData.writePersistedData();
184
		return true;
185
	}
186
187
}

Return to bug 162102