forked from microsoft/copilot-for-eclipse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeneralPreferencesPage.java
More file actions
134 lines (114 loc) · 5.27 KB
/
Copy pathGeneralPreferencesPage.java
File metadata and controls
134 lines (114 loc) · 5.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
package com.microsoft.copilot.eclipse.ui.preferences;
import org.eclipse.core.runtime.preferences.ConfigurationScope;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.jface.layout.GridDataFactory;
import org.eclipse.jface.preference.BooleanFieldEditor;
import org.eclipse.jface.preference.FieldEditorPreferencePage;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.osgi.service.prefs.BackingStoreException;
import com.microsoft.copilot.eclipse.core.Constants;
import com.microsoft.copilot.eclipse.core.CopilotCore;
import com.microsoft.copilot.eclipse.ui.CopilotUi;
/**
* General preference page.
*/
public class GeneralPreferencesPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
public static final String ID = "com.microsoft.copilot.eclipse.ui.preferences.GeneralPreferencesPage";
/**
* Constructor.
*/
public GeneralPreferencesPage() {
super(GRID);
}
@Override
public void createFieldEditors() {
Composite parent = getFieldEditorParent();
parent.setLayout(new GridLayout(1, true));
GridLayout gl = new GridLayout(1, true);
gl.marginTop = 2;
gl.marginLeft = 2;
GridDataFactory gdf = GridDataFactory.fillDefaults().span(2, 1).align(SWT.FILL, SWT.FILL).grab(true, false);
// proxy group
Group grpProxy = new Group(parent, SWT.NONE);
grpProxy.setLayout(gl);
gdf.applyTo(grpProxy);
grpProxy.setText(Messages.preferences_page_proxy_settings);
// add proxy configuration link
Composite linkContainer = new Composite(grpProxy, SWT.NONE);
GridLayout glTextIndent = new GridLayout(1, false);
glTextIndent.marginLeft = -3;
glTextIndent.marginBottom = 1;
linkContainer.setLayout(glTextIndent);
PreferencePageUtils.createPreferenceLink(getShell(), linkContainer, Messages.preferences_page_proxy_config_link,
Messages.preferences_page_proxy_config_link_tooltip, "org.eclipse.ui.net.NetPreferences");
// add strict ssl field
Composite ctnSsl = new Composite(grpProxy, SWT.NONE);
ctnSsl.setLayout(gl);
BooleanFieldEditor bfeSsl = new BooleanFieldEditor(Constants.ENABLE_STRICT_SSL,
Messages.preferences_page_enable_strict_ssl, ctnSsl);
bfeSsl.getDescriptionControl(ctnSsl).setToolTipText(Messages.preferences_page_enable_strict_ssl_tooltip);
addField(bfeSsl);
// add Note using WrappableNoteLabel
new WrappableNoteLabel(grpProxy, Messages.preferences_page_note_prefix + " ",
Messages.preferences_page_note_content);
// auth group
Group grpAuth = new Group(parent, SWT.NONE);
grpAuth.setLayout(gl);
gdf.applyTo(grpAuth);
grpAuth.setText(Messages.preferences_page_auth_settings);
// add github enterprise field
Composite ctnGhe = new Composite(grpAuth, SWT.NONE);
ctnGhe.setLayout(gl);
ctnGhe.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
StringFieldEditor sftGhe = new StringFieldEditor(Constants.GITHUB_ENTERPRISE,
Messages.preferences_page_github_enterprise, ctnGhe);
sftGhe.getLabelControl(ctnGhe).setToolTipText(Messages.preferences_page_github_enterprise_tooltip);
addField(sftGhe);
// What's new group
Group whatsNewGroup = new Group(parent, SWT.NONE);
whatsNewGroup.setLayout(gl);
gdf.applyTo(whatsNewGroup);
whatsNewGroup.setText(Messages.preferences_page_whats_new_settings);
// auto show "What is new" field
Composite whatsNewComposite = new Composite(whatsNewGroup, SWT.NONE);
whatsNewComposite.setLayout(gl);
whatsNewComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
BooleanFieldEditor showWhatsNewField = new BooleanFieldEditor(Constants.AUTO_SHOW_WHAT_IS_NEW,
Messages.preferences_page_enable_whats_new, whatsNewComposite);
showWhatsNewField.getDescriptionControl(whatsNewComposite)
.setToolTipText(Messages.preferences_page_enable_whats_new_tooltip);
addField(showWhatsNewField);
}
@Override
public void init(IWorkbench workbench) {
setPreferenceStore(CopilotUi.getPlugin().getPreferenceStore());
}
@Override
public boolean performOk() {
boolean result = super.performOk();
boolean newWhatsNewValue = getPreferenceStore().getBoolean(Constants.AUTO_SHOW_WHAT_IS_NEW);
// Update the new value for fields that must persist in configuration scope
IEclipsePreferences configPrefs = ConfigurationScope.INSTANCE
.getNode(CopilotUi.getPlugin().getBundle().getSymbolicName());
boolean oldWhatsNewValue = configPrefs.getBoolean(Constants.AUTO_SHOW_WHAT_IS_NEW, true);
// Ensure the preference change is updated in configuration scope too
if (oldWhatsNewValue ^ newWhatsNewValue) {
try {
configPrefs.putBoolean(Constants.AUTO_SHOW_WHAT_IS_NEW, newWhatsNewValue);
configPrefs.flush();
} catch (BackingStoreException ex) {
CopilotCore.LOGGER.error("Failed to persist 'Auto show What's New' preference in ConfigurationScope", ex);
}
}
return result;
}
}