Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 887f079397723b76e284c9b3d8fa3c8948fdded3 (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
/*****************************************************************************
 * Copyright (c) 2015 Christian W. Damus 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:
 *   Christian W. Damus - Initial API and implementation
 *   
 *****************************************************************************/

package org.eclipse.papyrus.infra.editor.welcome.internal.preferences;

import java.io.IOException;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.layout.GridLayoutFactory;
import org.eclipse.papyrus.infra.editor.welcome.internal.Activator;
import org.eclipse.papyrus.infra.properties.ui.preferences.Preferences;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

/**
 * The specialized preference page for the <em>Welcome Page</em> contents.
 */
public class WelcomeContentPreferencePage extends Preferences {

	public WelcomeContentPreferencePage() {
		super();
	}

	@Override
	protected void createHeaderContents(Composite parent) {
		Composite header = new Composite(parent, SWT.NONE);
		GridLayoutFactory.swtDefaults().numColumns(2).margins(0, 0).applyTo(header);

		new Label(header, SWT.NONE).setText("Default Welcome Page layout:");
		Button resetButton = new Button(header, SWT.PUSH);
		resetButton.setText("Reset");
		resetButton.setToolTipText("Revert the default Welcome Page layout to factory defaults");
		resetButton.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				resetWelcomePageLayout();
			}
		});
	}

	private void resetWelcomePageLayout() {
		if (MessageDialog.openConfirm(getShell(), "Reset Default Welcome Page Layout", "Are you sure you want to reset the default Welcome Page layout to factory defaults?\nThis will affect all Welcome Pages that have not customized the layout.")) {
			try {
				Activator.getDefault().getWelcomeModelManager().deleteDefaultWelcomeResource();
			} catch (IOException e) {
				Activator.log.error("Failed to delete the workspace's default welcome layout.", e); //$NON-NLS-1$
			}
		}
	}
}

Back to the top