001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.ui.editor.feature;
011:
012: import org.eclipse.core.runtime.CoreException;
013: import org.eclipse.pde.core.IModelChangedEvent;
014: import org.eclipse.pde.internal.core.ifeature.IFeature;
015: import org.eclipse.pde.internal.core.ifeature.IFeatureModel;
016: import org.eclipse.pde.internal.ui.PDEPlugin;
017: import org.eclipse.pde.internal.ui.PDEUIMessages;
018: import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
019: import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
020: import org.eclipse.pde.internal.ui.editor.PDESection;
021: import org.eclipse.pde.internal.ui.parts.FormEntry;
022: import org.eclipse.swt.SWT;
023: import org.eclipse.swt.dnd.Clipboard;
024: import org.eclipse.swt.dnd.RTFTransfer;
025: import org.eclipse.swt.dnd.TextTransfer;
026: import org.eclipse.swt.dnd.Transfer;
027: import org.eclipse.swt.dnd.TransferData;
028: import org.eclipse.swt.events.SelectionAdapter;
029: import org.eclipse.swt.events.SelectionEvent;
030: import org.eclipse.swt.layout.GridData;
031: import org.eclipse.swt.widgets.Button;
032: import org.eclipse.swt.widgets.Composite;
033: import org.eclipse.swt.widgets.Label;
034: import org.eclipse.ui.forms.widgets.FormToolkit;
035: import org.eclipse.ui.forms.widgets.Section;
036:
037: public class InstallSection extends PDESection {
038: private Button fExclusiveButton;
039:
040: private FormEntry fColocationText;
041:
042: private boolean fBlockNotification;
043:
044: public InstallSection(FeatureAdvancedPage page, Composite parent) {
045: super (page, parent, Section.DESCRIPTION);
046: getSection().setText(
047: PDEUIMessages.FeatureEditor_InstallSection_title);
048: getSection().setDescription(
049: PDEUIMessages.FeatureEditor_InstallSection_desc);
050: createClient(getSection(), page.getManagedForm().getToolkit());
051: }
052:
053: public boolean canPaste(Clipboard clipboard) {
054: TransferData[] types = clipboard.getAvailableTypes();
055: Transfer[] transfers = new Transfer[] {
056: TextTransfer.getInstance(), RTFTransfer.getInstance() };
057: for (int i = 0; i < types.length; i++) {
058: for (int j = 0; j < transfers.length; j++) {
059: if (transfers[j].isSupportedType(types[i]))
060: return true;
061: }
062: }
063: return false;
064: }
065:
066: public void commit(boolean onSave) {
067: fColocationText.commit();
068: super .commit(onSave);
069: }
070:
071: public void createClient(Section section, FormToolkit toolkit) {
072:
073: section.setLayout(FormLayoutFactory.createClearGridLayout(
074: false, 1));
075: GridData data = new GridData(GridData.FILL_HORIZONTAL);
076: section.setLayoutData(data);
077:
078: Composite container = toolkit.createComposite(section);
079: container.setLayout(FormLayoutFactory
080: .createSectionClientGridLayout(false, 2));
081: container.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
082:
083: IFeatureModel model = (IFeatureModel) getPage().getModel();
084: final IFeature feature = model.getFeature();
085:
086: fExclusiveButton = toolkit.createButton(container,
087: PDEUIMessages.FeatureEditor_InstallSection_exclusive,
088: SWT.CHECK);
089: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
090: gd.horizontalSpan = 2;
091: fExclusiveButton.setLayoutData(gd);
092: fExclusiveButton.addSelectionListener(new SelectionAdapter() {
093: public void widgetSelected(SelectionEvent e) {
094: try {
095: if (!fBlockNotification)
096: feature.setExclusive(fExclusiveButton
097: .getSelection());
098: } catch (CoreException ex) {
099: PDEPlugin.logException(ex);
100: }
101: }
102: });
103:
104: Label colocationDescLabel = toolkit
105: .createLabel(
106: container,
107: PDEUIMessages.FeatureEditor_InstallSection_colocation_desc,
108: SWT.WRAP);
109: gd = new GridData(GridData.FILL);
110: gd.horizontalSpan = 2;
111: gd.widthHint = 250;
112: colocationDescLabel.setLayoutData(gd);
113:
114: fColocationText = new FormEntry(container, toolkit,
115: PDEUIMessages.FeatureEditor_InstallSection_colocation,
116: null, false);
117: fColocationText
118: .setFormEntryListener(new FormEntryAdapter(this ) {
119: public void textValueChanged(FormEntry text) {
120: IFeatureModel model = (IFeatureModel) getPage()
121: .getModel();
122: IFeature feature = model.getFeature();
123: try {
124: feature
125: .setColocationAffinity(fColocationText
126: .getValue());
127: } catch (CoreException e) {
128: PDEPlugin.logException(e);
129: }
130: }
131: });
132:
133: toolkit.paintBordersFor(container);
134: section.setClient(container);
135: initialize();
136: }
137:
138: public void dispose() {
139: IFeatureModel model = (IFeatureModel) getPage().getModel();
140: if (model != null)
141: model.removeModelChangedListener(this );
142: super .dispose();
143: }
144:
145: public void initialize() {
146: IFeatureModel model = (IFeatureModel) getPage().getModel();
147: refresh();
148: if (model.isEditable() == false) {
149: fColocationText.getText().setEditable(false);
150: fExclusiveButton.setEnabled(false);
151: }
152: model.addModelChangedListener(this );
153: }
154:
155: public void modelChanged(IModelChangedEvent e) {
156: if (e.getChangeType() == IModelChangedEvent.WORLD_CHANGED) {
157: markStale();
158: }
159: }
160:
161: public void setFocus() {
162: if (fExclusiveButton != null)
163: fExclusiveButton.setFocus();
164: }
165:
166: public void refresh() {
167: IFeatureModel model = (IFeatureModel) getPage().getModel();
168: IFeature feature = model.getFeature();
169: fColocationText.setValue(
170: feature.getColocationAffinity() != null ? feature
171: .getColocationAffinity() : "", true); //$NON-NLS-1$
172: fBlockNotification = true;
173: fExclusiveButton.setSelection(feature.isExclusive());
174: fBlockNotification = false;
175: super .refresh();
176: }
177:
178: public void cancelEdit() {
179: fColocationText.cancelEdit();
180: super.cancelEdit();
181: }
182: }
|