KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > feature > InstallSection


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.editor.feature;
12
13 import org.eclipse.core.runtime.CoreException;
14 import org.eclipse.pde.core.IModelChangedEvent;
15 import org.eclipse.pde.internal.core.ifeature.IFeature;
16 import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
17 import org.eclipse.pde.internal.ui.PDEPlugin;
18 import org.eclipse.pde.internal.ui.PDEUIMessages;
19 import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
20 import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
21 import org.eclipse.pde.internal.ui.editor.PDESection;
22 import org.eclipse.pde.internal.ui.parts.FormEntry;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.dnd.Clipboard;
25 import org.eclipse.swt.dnd.RTFTransfer;
26 import org.eclipse.swt.dnd.TextTransfer;
27 import org.eclipse.swt.dnd.Transfer;
28 import org.eclipse.swt.dnd.TransferData;
29 import org.eclipse.swt.events.SelectionAdapter;
30 import org.eclipse.swt.events.SelectionEvent;
31 import org.eclipse.swt.layout.GridData;
32 import org.eclipse.swt.widgets.Button;
33 import org.eclipse.swt.widgets.Composite;
34 import org.eclipse.swt.widgets.Label;
35 import org.eclipse.ui.forms.widgets.FormToolkit;
36 import org.eclipse.ui.forms.widgets.Section;
37
38 public class InstallSection extends PDESection {
39     private Button fExclusiveButton;
40
41     private FormEntry fColocationText;
42
43     private boolean fBlockNotification;
44
45     public InstallSection(FeatureAdvancedPage page, Composite parent) {
46         super(page, parent, Section.DESCRIPTION);
47         getSection().setText(PDEUIMessages.FeatureEditor_InstallSection_title);
48         getSection().setDescription(PDEUIMessages.FeatureEditor_InstallSection_desc);
49         createClient(getSection(), page.getManagedForm().getToolkit());
50     }
51
52     public boolean canPaste(Clipboard clipboard) {
53         TransferData[] types = clipboard.getAvailableTypes();
54         Transfer[] transfers = new Transfer[] { TextTransfer.getInstance(),
55                 RTFTransfer.getInstance() };
56         for (int i = 0; i < types.length; i++) {
57             for (int j = 0; j < transfers.length; j++) {
58                 if (transfers[j].isSupportedType(types[i]))
59                     return true;
60             }
61         }
62         return false;
63     }
64
65     public void commit(boolean onSave) {
66         fColocationText.commit();
67         super.commit(onSave);
68     }
69
70     public void createClient(Section section, FormToolkit toolkit) {
71         
72         section.setLayout(FormLayoutFactory.createClearGridLayout(false, 1));
73         GridData data = new GridData(GridData.FILL_HORIZONTAL);
74         section.setLayoutData(data);
75         
76         Composite container = toolkit.createComposite(section);
77         container.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 2));
78         container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
79
80         IFeatureModel model = (IFeatureModel) getPage().getModel();
81         final IFeature feature = model.getFeature();
82
83         fExclusiveButton = toolkit.createButton(container, PDEUIMessages.FeatureEditor_InstallSection_exclusive, SWT.CHECK);
84         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
85         gd.horizontalSpan = 2;
86         fExclusiveButton.setLayoutData(gd);
87         fExclusiveButton.addSelectionListener(new SelectionAdapter() {
88             public void widgetSelected(SelectionEvent e) {
89                 try {
90                     if (!fBlockNotification)
91                         feature.setExclusive(fExclusiveButton.getSelection());
92                 } catch (CoreException ex) {
93                     PDEPlugin.logException(ex);
94                 }
95             }
96         });
97
98         Label colocationDescLabel = toolkit.createLabel(container,
99                 PDEUIMessages.FeatureEditor_InstallSection_colocation_desc, SWT.WRAP);
100         gd = new GridData(GridData.FILL);
101         gd.horizontalSpan = 2;
102         gd.widthHint = 250;
103         colocationDescLabel.setLayoutData(gd);
104
105         fColocationText = new FormEntry(container, toolkit, PDEUIMessages.FeatureEditor_InstallSection_colocation, null, false);
106         fColocationText.setFormEntryListener(new FormEntryAdapter(this) {
107             public void textValueChanged(FormEntry text) {
108                 IFeatureModel model = (IFeatureModel) getPage().getModel();
109                 IFeature feature = model.getFeature();
110                 try {
111                     feature.setColocationAffinity(fColocationText.getValue());
112                 } catch (CoreException e) {
113                     PDEPlugin.logException(e);
114                 }
115             }
116         });
117
118         toolkit.paintBordersFor(container);
119         section.setClient(container);
120         initialize();
121     }
122
123     public void dispose() {
124         IFeatureModel model = (IFeatureModel) getPage().getModel();
125         if (model != null)
126             model.removeModelChangedListener(this);
127         super.dispose();
128     }
129
130     public void initialize() {
131         IFeatureModel model = (IFeatureModel) getPage().getModel();
132         refresh();
133         if (model.isEditable() == false) {
134             fColocationText.getText().setEditable(false);
135             fExclusiveButton.setEnabled(false);
136         }
137         model.addModelChangedListener(this);
138     }
139
140     public void modelChanged(IModelChangedEvent e) {
141         if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
142             markStale();
143         }
144     }
145
146     public void setFocus() {
147         if (fExclusiveButton != null)
148             fExclusiveButton.setFocus();
149     }
150
151     public void refresh() {
152         IFeatureModel model = (IFeatureModel) getPage().getModel();
153         IFeature feature = model.getFeature();
154         fColocationText.setValue(
155                 feature.getColocationAffinity() != null ? feature
156                         .getColocationAffinity() : "", true); //$NON-NLS-1$
157
fBlockNotification = true;
158         fExclusiveButton.setSelection(feature.isExclusive());
159         fBlockNotification = false;
160         super.refresh();
161     }
162
163     public void cancelEdit() {
164         fColocationText.cancelEdit();
165         super.cancelEdit();
166     }
167 }
168
Popular Tags