Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 39e29cbcdcabfd5dce3b3b7f10232a0bfbf971db (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
/*******************************************************************************
 * Copyright (c) 2014 fhv.at and others.
 *
 * This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License 2.0
 * which accompanies this distribution, and is available at
 * https://www.eclipse.org/legal/epl-2.0/
 *
 * SPDX-License-Identifier: EPL-2.0
 *
 * Contributors:
 *     Andrej ten Brummelhuis <andrejbrummelhuis@gmail.com> - initial implementation (Bug 395283)
 *     Marco Descher <marco@descher.at> - Bug 442647
 *******************************************************************************/
package org.eclipse.e4.tools.emf.ui.internal.common.component.dialogs;

import org.eclipse.core.runtime.preferences.InstanceScope;
import org.eclipse.e4.tools.emf.ui.common.Plugin;
import org.eclipse.jface.dialogs.DialogSettings;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.dialogs.TitleAreaDialog;
import org.eclipse.swt.widgets.Shell;
import org.osgi.service.prefs.BackingStoreException;
import org.osgi.service.prefs.Preferences;

public abstract class SaveDialogBoundsSettingsDialog extends TitleAreaDialog {

	private static final String DIALOG_ORIGIN_X = "DIALOG_X_ORIGIN"; //$NON-NLS-1$
	private static final String DIALOG_ORIGIN_Y = "DIALOG_Y_ORIGIN"; //$NON-NLS-1$
	private static final String DIALOG_WIDTH = "DIALOG_WIDTH"; //$NON-NLS-1$
	private static final String DIALOG_HEIGHT = "DIALOG_HEIGHT"; //$NON-NLS-1$
	private static final int DIALOG_MINIMUM_HEIGHT = 300;
	private static final int DIALOG_MINIMUM_WIDTH = 400;

	private IDialogSettings dialogSettings = new DialogSettings(Plugin.ID);

	private Preferences preferences = InstanceScope.INSTANCE.getNode(Plugin.ID);

	public SaveDialogBoundsSettingsDialog(Shell parentShell) {
		super(parentShell);

		dialogSettings.put(DIALOG_HEIGHT, preferences.getInt(DIALOG_HEIGHT, -1));
		dialogSettings.put(DIALOG_WIDTH, preferences.getInt(DIALOG_WIDTH, -1));
		dialogSettings.put(DIALOG_ORIGIN_X, preferences.getInt(DIALOG_ORIGIN_X, -1));
		dialogSettings.put(DIALOG_ORIGIN_Y, preferences.getInt(DIALOG_ORIGIN_Y, -1));
	}

	private void saveDialogSettings() {
		preferences.put(DIALOG_HEIGHT, dialogSettings.get(DIALOG_HEIGHT));
		preferences.put(DIALOG_WIDTH, dialogSettings.get(DIALOG_WIDTH));
		preferences.put(DIALOG_ORIGIN_X, dialogSettings.get(DIALOG_ORIGIN_X));
		preferences.put(DIALOG_ORIGIN_Y, dialogSettings.get(DIALOG_ORIGIN_Y));
		try {
			preferences.flush();
		} catch (BackingStoreException e) {
			e.printStackTrace();
		}
	}

	@Override
	protected void configureShell(Shell newShell) {
		super.configureShell(newShell);
		newShell.setMinimumSize(DIALOG_MINIMUM_WIDTH, DIALOG_MINIMUM_HEIGHT);
	}

	@Override
	protected boolean isResizable() {
		return true;
	}

	@Override
	public boolean close() {
		boolean returnValue = super.close();
		saveDialogSettings();
		return returnValue;
	}

	@Override
	protected IDialogSettings getDialogBoundsSettings() {
		return dialogSettings;
	}

	public Preferences getPreferences() {
		return preferences;
	}
}

Back to the top