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.osgi.util.NLS;
013: import org.eclipse.pde.internal.core.ischema.ISchemaElement;
014: import org.eclipse.pde.internal.core.ischema.ISchemaObject;
015: import org.eclipse.pde.internal.core.schema.SchemaElementReference;
016: import org.eclipse.pde.internal.core.schema.SchemaRootElement;
017: import org.eclipse.pde.internal.ui.PDEUIMessages;
018: import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
019: import org.eclipse.pde.internal.ui.parts.FormEntry;
020: import org.eclipse.swt.SWT;
021: import org.eclipse.swt.events.SelectionAdapter;
022: import org.eclipse.swt.events.SelectionEvent;
023: import org.eclipse.swt.graphics.Color;
024: import org.eclipse.swt.layout.GridData;
025: import org.eclipse.swt.widgets.Button;
026: import org.eclipse.swt.widgets.Composite;
027: import org.eclipse.swt.widgets.Label;
028: import org.eclipse.ui.forms.IFormColors;
029: import org.eclipse.ui.forms.widgets.FormToolkit;
030:
031: public class SchemaRootElementDetails extends AbstractSchemaDetails {
032:
033: private SchemaRootElement fElement;
034: private FormEntry fName;
035: private Button fDepTrue;
036: private Button fDepFalse;
037: private FormEntry fSuggestion;
038:
039: public SchemaRootElementDetails(ElementSection section) {
040: super (section, true, true);
041: }
042:
043: public void createDetails(Composite parent) {
044: FormToolkit toolkit = getManagedForm().getToolkit();
045: Color foreground = toolkit.getColors().getColor(
046: IFormColors.TITLE);
047:
048: fName = new FormEntry(parent, toolkit,
049: PDEUIMessages.SchemaDetails_name, SWT.READ_ONLY);
050: // Ensures label columns on every detail page are same width
051: ((GridData) fName.getLabel().getLayoutData()).widthHint = minLabelWeight;
052:
053: Label label = toolkit.createLabel(parent,
054: PDEUIMessages.SchemaDetails_deprecated);
055: label.setForeground(foreground);
056: Button[] buttons = createTrueFalseButtons(parent, toolkit, 2);
057: fDepTrue = buttons[0];
058: fDepFalse = buttons[1];
059:
060: fSuggestion = new FormEntry(parent, toolkit,
061: PDEUIMessages.SchemaRootElementDetails_replacement,
062: null, false, 6);
063:
064: setText(PDEUIMessages.SchemaElementDetails_rootTitle);
065: }
066:
067: public void updateFields(ISchemaObject element) {
068: if (!(element instanceof ISchemaElement))
069: return;
070: if (element instanceof SchemaElementReference)
071: element = ((SchemaElementReference) element)
072: .getReferencedObject();
073: fElement = (SchemaRootElement) element;
074: if (fElement == null)
075: return;
076:
077: setDecription(NLS.bind(
078: PDEUIMessages.SchemaElementDetails_description,
079: fElement.getName()));
080: fName.setValue(fElement.getName(), true);
081: fDepTrue.setSelection(fElement.isDeprecated());
082: fDepFalse.setSelection(!fElement.isDeprecated());
083: fSuggestion.setValue(fElement.getDeprecatedSuggestion(), true);
084:
085: fDepTrue.setEnabled(isEditable());
086: fDepFalse.setEnabled(isEditable());
087:
088: if (!fElement.isDeprecated()) {
089: fSuggestion.getLabel().setEnabled(false);
090: fSuggestion.getText().setEditable(false);
091: } else {
092: fSuggestion.setEditable(isEditable());
093: }
094: }
095:
096: public void hookListeners() {
097: fDepTrue.addSelectionListener(new SelectionAdapter() {
098: public void widgetSelected(SelectionEvent e) {
099: if (blockListeners())
100: return;
101: boolean deprecated = fDepTrue.getSelection();
102: fElement.setDeprecatedProperty(deprecated);
103: fSuggestion.getLabel().setEnabled(deprecated);
104: fSuggestion.getText().setEditable(deprecated);
105: }
106: });
107: fSuggestion.setFormEntryListener(new FormEntryAdapter(this ) {
108: public void textValueChanged(FormEntry entry) {
109: if (blockListeners())
110: return;
111: fElement
112: .setDeprecatedSuggestion(fSuggestion.getValue());
113: }
114: });
115: }
116:
117: /* (non-Javadoc)
118: * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
119: */
120: public void commit(boolean onSave) {
121: super .commit(onSave);
122: // Only required for form entries
123: fSuggestion.commit();
124: }
125:
126: }
|