Skip to main content
summaryrefslogtreecommitdiffstats
blob: 002e04f7a329cb31f0b4241e5ea5172a9b1f81a3 (plain) (blame)
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*******************************************************************************
 * Copyright (c) 2006, 2016 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.help.ui.internal.preferences;

import java.util.List;

import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.IEclipsePreferences;
import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.help.internal.base.HelpBasePlugin;
import org.eclipse.help.internal.base.IHelpBaseConstants;
import org.eclipse.help.internal.base.remote.DefaultPreferenceFileHandler;
import org.eclipse.help.internal.base.remote.RemoteHelp;
import org.eclipse.help.ui.internal.IHelpUIConstants;
import org.eclipse.help.ui.internal.Messages;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage;
import org.eclipse.ui.PlatformUI;

/**
 * Preference page to set remote infocenters
 */
public class HelpContentPreferencePage extends PreferencePage implements
		IWorkbenchPreferencePage {

	private ICTable table;
	private ICButtons buttons;

	private Button searchLocalHelpOnly;
	private Button searchLocalHelpFirst;
	private Button searchLocalHelpLast;
	private Label descLabel;

	/**
	 * Creates the preference page
	 */
	public HelpContentPreferencePage() {
	}

	@Override
	public void init(IWorkbench workbench) {
	}

	public ICTable getTable()
	{
		return table;
	}

	@Override
	protected Control createContents(Composite parent) {
		PlatformUI.getWorkbench().getHelpSystem().setHelp(parent,
				IHelpUIConstants.PREF_PAGE_HELP_CONTENT);

		initializeDialogUnits(parent);

		descLabel = new Label(parent, SWT.NONE);
		descLabel.setText(Messages.HelpContentPage_title);
		Dialog.applyDialogFont(descLabel);

		createSearchLocalHelpOnly(parent);
		createSearchLocalHelpFirst(parent);
		createSearchLocalHelpLast(parent);

/*		remoteICPage = new InfocenterDisplay(this);
		remoteICPage.createContents(parent);
*/
		initializeTableEnablement(parent,searchLocalHelpOnly.getSelection());

		return parent;
	}

	@Override
	protected void performDefaults() {
		super.performDefaults();

		List<IC> ics = ICPreferences.getDefaultICs();
		table.setICs(ics);

		// Restore Defaults functionality here
/*		HelpContentBlock currentBlock=remoteICPage.getHelpContentBlock();
		currentBlock.getRemoteICviewer().getRemoteICList().removeAllRemoteICs(currentBlock.getRemoteICList());
		currentBlock.getRemoteICviewer().getRemoteICList().loadDefaultPreferences();
		currentBlock.restoreDefaultButtons();
*/
		boolean remoteHelpOn = new DefaultPreferenceFileHandler().isRemoteHelpOn();
		boolean remoteHelpPreferred = new DefaultPreferenceFileHandler().isRemoteHelpPreferred();
		searchLocalHelpOnly.setSelection(!remoteHelpOn);
		searchLocalHelpFirst.setSelection(remoteHelpOn && !remoteHelpPreferred);
		searchLocalHelpLast.setSelection(remoteHelpOn && remoteHelpPreferred);
		changeListener.handleEvent(null);
	}

	@Override
	public boolean performOk() {

		IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(HelpBasePlugin.PLUGIN_ID);
		/*
		 * (non-Javadoc)
		 *
		 * @see org.eclipse.jface.preference.PreferencePage#performOk()
		 */
		prefs.putBoolean(IHelpBaseConstants.P_KEY_REMOTE_HELP_ON, !(searchLocalHelpOnly.getSelection()));
		prefs.putBoolean(IHelpBaseConstants.P_KEY_REMOTE_HELP_PREFERRED, searchLocalHelpLast.getSelection());


		List<IC> ics = table.getICs();
		ICPreferences.setICs(ics);

    	RemoteHelp.notifyPreferenceChange();
		return super.performOk();
	}

	@Override
	protected GridData setButtonLayoutData(Button button) {
		return super.setButtonLayoutData(button);
	}

	private void createSearchLocalHelpOnly(Composite parent) {
		searchLocalHelpOnly = new Button(parent, SWT.RADIO);
		searchLocalHelpOnly.setText(Messages.SearchEmbeddedHelpOnly);
		searchLocalHelpOnly.addListener(SWT.Selection, changeListener);

		boolean isRemoteOn = Platform.getPreferencesService().getBoolean
		    (HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_ON, false, null);

		searchLocalHelpOnly.setSelection(!isRemoteOn);
		Dialog.applyDialogFont(searchLocalHelpOnly);
	}

	private void createSearchLocalHelpFirst(Composite parent) {
		searchLocalHelpFirst = new Button(parent, SWT.RADIO);
		searchLocalHelpFirst.setText(Messages.SearchEmbeddedHelpFirst);
		searchLocalHelpFirst.addListener(SWT.Selection, changeListener);

		boolean isRemoteOn = Platform.getPreferencesService().getBoolean
	    	(HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_ON, false, null);
		boolean isRemotePreferred = Platform.getPreferencesService().getBoolean
	    	(HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_PREFERRED, false, null);

		searchLocalHelpFirst.setSelection(isRemoteOn && !isRemotePreferred);
		Dialog.applyDialogFont(searchLocalHelpFirst);
	}

	private void createSearchLocalHelpLast(Composite parent) {
		searchLocalHelpLast = new Button(parent, SWT.RADIO);
		searchLocalHelpLast.setText(Messages.SearchEmbeddedHelpLast);
		searchLocalHelpLast.addListener(SWT.Selection, changeListener);

		boolean isRemoteOn = Platform.getPreferencesService().getBoolean
			(HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_ON, false, null);
		boolean isRemotePreferred = Platform.getPreferencesService().getBoolean
			(HelpBasePlugin.PLUGIN_ID, IHelpBaseConstants.P_KEY_REMOTE_HELP_PREFERRED, false, null);

		searchLocalHelpLast.setSelection(isRemoteOn && isRemotePreferred);
		Dialog.applyDialogFont(searchLocalHelpLast);
	}

	/*
	 * Initialize the table enablement with the current checkbox selection
	 */

	private void initializeTableEnablement(Composite parent, boolean isRemoteHelpDisabled)
	{
		Composite top = new Composite(parent, SWT.NONE);

		GridLayout layout = new GridLayout();
		layout.numColumns = 2;
		layout.marginHeight = 2;
		layout.marginWidth = 2;
		top.setLayout(layout);

		top.setLayoutData(new GridData(GridData.FILL_BOTH));

		table = new ICTable(top);
		buttons = new ICButtons(top,this);

		changeListener.handleEvent(null);
	}

	/*
	 * Listens for any change in the UI and checks for valid input and correct
	 * enablement.
	 */
	private Listener changeListener = event -> {

		boolean isRemoteHelpEnabled = !(searchLocalHelpOnly.getSelection());

		// Disable/Enable table
		table.getTable().setEnabled(isRemoteHelpEnabled);
		buttons.setEnabled(isRemoteHelpEnabled);
	};

}

Back to the top