KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > properties > PluginDevelopmentPage


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation 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  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.properties;
12
13 import org.eclipse.core.resources.IProject;
14 import org.eclipse.core.resources.ProjectScope;
15 import org.eclipse.jface.dialogs.Dialog;
16 import org.eclipse.pde.internal.core.ICoreConstants;
17 import org.eclipse.pde.internal.core.PDECore;
18 import org.eclipse.pde.internal.ui.PDEPlugin;
19 import org.eclipse.pde.internal.ui.PDEUIMessages;
20 import org.eclipse.swt.SWT;
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.ui.IWorkbenchPropertyPage;
28 import org.eclipse.ui.dialogs.PropertyPage;
29 import org.osgi.service.prefs.BackingStoreException;
30 import org.osgi.service.prefs.Preferences;
31
32 public class PluginDevelopmentPage extends PropertyPage implements
33         IWorkbenchPropertyPage {
34
35     private Button fExtensionButton;
36     private Button fEquinoxButton;
37     
38     public PluginDevelopmentPage() {
39         noDefaultAndApplyButton();
40     }
41
42     protected Control createContents(Composite parent) {
43         Composite composite = new Composite(parent, SWT.NONE);
44         composite.setLayout(new GridLayout());
45         composite.setLayoutData(new GridData(GridData.FILL_BOTH));
46         
47         Group group = new Group(composite, SWT.NONE);
48         group.setText(PDEUIMessages.PluginDevelopmentPage_presentation);
49         group.setLayout(new GridLayout());
50         group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
51         
52         fExtensionButton = new Button(group, SWT.CHECK);
53         fExtensionButton.setText(PDEUIMessages.PluginDevelopmentPage_extensions);
54
55         fEquinoxButton = new Button(group, SWT.CHECK);
56         fEquinoxButton.setText(PDEUIMessages.PluginDevelopmentPage_equinox);
57
58         initialize();
59         Dialog.applyDialogFont(composite);
60         return composite;
61     }
62
63     private void initialize() {
64         Preferences pref = getPreferences((IProject)getElement().getAdapter(IProject.class));
65         if (pref != null) {
66             fExtensionButton.setSelection(pref.getBoolean(ICoreConstants.EXTENSIONS_PROPERTY, true));
67             fEquinoxButton.setSelection(pref.getBoolean(ICoreConstants.EQUINOX_PROPERTY, true));
68         }
69     }
70     
71     private Preferences getPreferences(IProject project) {
72         return new ProjectScope(project).getNode(PDECore.PLUGIN_ID);
73     }
74     
75     public boolean performOk() {
76         Preferences pref = getPreferences((IProject)getElement().getAdapter(IProject.class));
77         if (pref != null) {
78             if (!fExtensionButton.getSelection())
79                 pref.putBoolean(ICoreConstants.EXTENSIONS_PROPERTY, false);
80             else
81                 pref.remove(ICoreConstants.EXTENSIONS_PROPERTY);
82             
83             if (!fEquinoxButton.getSelection())
84                 pref.putBoolean(ICoreConstants.EQUINOX_PROPERTY, false);
85             else
86                 pref.remove(ICoreConstants.EQUINOX_PROPERTY);
87             
88             try {
89                 pref.flush();
90             } catch (BackingStoreException e) {
91                 PDEPlugin.logException(e);
92             }
93         }
94         return super.performOk();
95     }
96     
97 }
98
Popular Tags