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.schema;
011:
012: import org.eclipse.pde.internal.core.ischema.ISchema;
013: import org.eclipse.pde.internal.core.schema.Schema;
014: import org.eclipse.pde.internal.ui.PDEUIMessages;
015: import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
016: import org.eclipse.pde.internal.ui.editor.FormLayoutFactory;
017: import org.eclipse.pde.internal.ui.editor.PDESection;
018: import org.eclipse.pde.internal.ui.parts.FormEntry;
019: import org.eclipse.swt.dnd.Clipboard;
020: import org.eclipse.swt.layout.GridData;
021: import org.eclipse.swt.widgets.Composite;
022: import org.eclipse.ui.forms.widgets.FormToolkit;
023: import org.eclipse.ui.forms.widgets.Section;
024:
025: public class SchemaSpecSection extends PDESection {
026:
027: private FormEntry fPluginText;
028: private FormEntry fPointText;
029: private FormEntry fNameText;
030:
031: public SchemaSpecSection(SchemaOverviewPage page, Composite parent) {
032: super (page, parent, Section.DESCRIPTION);
033: getSection().setText(
034: PDEUIMessages.SchemaEditor_SpecSection_title);
035: getSection().setDescription(
036: PDEUIMessages.SchemaEditor_SpecSection_desc);
037: createClient(getSection(), page.getManagedForm().getToolkit());
038: }
039:
040: public void commit(boolean onSave) {
041: fPluginText.commit();
042: fPointText.commit();
043: fNameText.commit();
044: super .commit(onSave);
045: }
046:
047: public void cancelEdit() {
048: fPluginText.cancelEdit();
049: fPointText.cancelEdit();
050: fNameText.cancelEdit();
051: super .cancelEdit();
052: }
053:
054: public void createClient(Section section, FormToolkit toolkit) {
055: Composite container = toolkit.createComposite(section);
056: container.setLayout(FormLayoutFactory
057: .createSectionClientGridLayout(false, 2));
058: GridData data = new GridData(GridData.FILL_BOTH);
059: section.setLayoutData(data);
060:
061: final Schema schema = (Schema) getPage().getModel();
062: fPluginText = new FormEntry(container, toolkit,
063: PDEUIMessages.SchemaEditor_SpecSection_plugin, null,
064: false);
065: fPluginText.setFormEntryListener(new FormEntryAdapter(this ) {
066: public void textValueChanged(FormEntry text) {
067: schema.setPluginId(text.getValue());
068: }
069: });
070: fPointText = new FormEntry(container, toolkit,
071: PDEUIMessages.SchemaEditor_SpecSection_point, null,
072: false);
073: fPointText.setFormEntryListener(new FormEntryAdapter(this ) {
074: public void textValueChanged(FormEntry text) {
075: schema.setPointId(text.getValue());
076: }
077: });
078: fNameText = new FormEntry(container, toolkit,
079: PDEUIMessages.SchemaEditor_SpecSection_name, null,
080: false);
081: fNameText.setFormEntryListener(new FormEntryAdapter(this ) {
082: public void textValueChanged(FormEntry text) {
083: schema.setName(text.getValue());
084: getPage().getManagedForm().getForm().setText(
085: schema.getName());
086: }
087: });
088:
089: toolkit.paintBordersFor(container);
090: section.setClient(container);
091: initialize();
092: }
093:
094: public void dispose() {
095: ISchema schema = (ISchema) getPage().getModel();
096: if (schema != null)
097: schema.removeModelChangedListener(this );
098: super .dispose();
099: }
100:
101: public void initialize() {
102: ISchema schema = (ISchema) getPage().getModel();
103: refresh();
104: fPluginText.setEditable(isEditable());
105: fPointText.setEditable(isEditable());
106: fNameText.setEditable(isEditable());
107: schema.addModelChangedListener(this );
108: }
109:
110: /* (non-Javadoc)
111: * @see org.eclipse.ui.forms.SectionPart#setFocus()
112: */
113: public void setFocus() {
114: if (fPluginText != null) {
115: fPluginText.getText().setFocus();
116: }
117: }
118:
119: public void refresh() {
120: ISchema schema = (ISchema) getPage().getModel();
121: fPluginText.setValue(schema.getPluginId(), true);
122: fPointText.setValue(schema.getPointId(), true);
123: fNameText.setValue(schema.getName(), true);
124: getPage().getManagedForm().getForm().setText(schema.getName());
125: super .refresh();
126: }
127:
128: public boolean canPaste(Clipboard clipboard) {
129: return isEditable();
130: }
131: }
|