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.core.IModelChangedEvent;
014: import org.eclipse.pde.internal.core.ischema.ISchema;
015: import org.eclipse.pde.internal.core.ischema.ISchemaComplexType;
016: import org.eclipse.pde.internal.core.ischema.ISchemaElement;
017: import org.eclipse.pde.internal.core.ischema.ISchemaObject;
018: import org.eclipse.pde.internal.core.schema.Schema;
019: import org.eclipse.pde.internal.core.schema.SchemaElement;
020: import org.eclipse.pde.internal.core.schema.SchemaElementReference;
021: import org.eclipse.pde.internal.ui.PDEUIMessages;
022: import org.eclipse.pde.internal.ui.editor.FormEntryAdapter;
023: import org.eclipse.pde.internal.ui.parts.FormEntry;
024: import org.eclipse.swt.SWT;
025: import org.eclipse.swt.events.SelectionAdapter;
026: import org.eclipse.swt.events.SelectionEvent;
027: import org.eclipse.swt.graphics.Color;
028: import org.eclipse.swt.layout.GridData;
029: import org.eclipse.swt.widgets.Button;
030: import org.eclipse.swt.widgets.Composite;
031: import org.eclipse.swt.widgets.Label;
032: import org.eclipse.ui.forms.IFormColors;
033: import org.eclipse.ui.forms.widgets.FormToolkit;
034:
035: public class SchemaElementDetails extends AbstractSchemaDetails {
036:
037: private SchemaElement fElement;
038: private FormEntry fName;
039: private Button fDepTrue;
040: private Button fDepFalse;
041: private Button fTransTrue;
042: private Button fTransFalse;
043:
044: public SchemaElementDetails(ElementSection section) {
045: super (section, true, true);
046: }
047:
048: public void createDetails(Composite parent) {
049: FormToolkit toolkit = getManagedForm().getToolkit();
050: Color foreground = toolkit.getColors().getColor(
051: IFormColors.TITLE);
052:
053: fName = new FormEntry(parent, toolkit,
054: PDEUIMessages.SchemaDetails_name, SWT.NONE);
055: // Ensures label columns on every detail page are same width
056: ((GridData) fName.getLabel().getLayoutData()).widthHint = minLabelWeight;
057:
058: Label label = toolkit.createLabel(parent,
059: PDEUIMessages.SchemaDetails_deprecated);
060: label.setForeground(foreground);
061: Button[] buttons = createTrueFalseButtons(parent, toolkit, 2);
062: fDepTrue = buttons[0];
063: fDepFalse = buttons[1];
064:
065: label = toolkit.createLabel(parent,
066: PDEUIMessages.SchemaDetails_translatable);
067: label.setForeground(foreground);
068: buttons = createTrueFalseButtons(parent, toolkit, 2);
069: fTransTrue = buttons[0];
070: fTransFalse = buttons[1];
071:
072: setText(PDEUIMessages.SchemaElementDetails_title);
073: }
074:
075: public void updateFields(ISchemaObject object) {
076: if (object instanceof SchemaElementReference)
077: object = ((SchemaElementReference) object)
078: .getReferencedObject();
079: fElement = (SchemaElement) object;
080: if (fElement == null)
081: return;
082: setDecription(NLS.bind(
083: PDEUIMessages.SchemaElementDetails_description,
084: fElement.getName()));
085: fName.setValue(fElement.getName(), true);
086:
087: fDepTrue.setSelection(fElement.isDeprecated());
088: fDepFalse.setSelection(!fElement.isDeprecated());
089:
090: boolean isTranslatable = true;
091: if ((fElement.getType() instanceof ISchemaComplexType && ((ISchemaComplexType) fElement
092: .getType()).getCompositor() != null)
093: || fElement.getAttributeCount() != 0)
094: isTranslatable = false;
095:
096: fTransTrue.setSelection(fElement.hasTranslatableContent());
097: fTransFalse.setSelection(!fElement.hasTranslatableContent());
098:
099: boolean editable = isEditableElement();
100: fName.setEditable(editable);
101:
102: fDepTrue.setEnabled(editable);
103: fDepFalse.setEnabled(editable);
104: fTransTrue.setEnabled(editable && isTranslatable);
105: fTransFalse.setEnabled(editable && isTranslatable);
106: }
107:
108: public void hookListeners() {
109: fName.setFormEntryListener(new FormEntryAdapter(this ) {
110: public void textValueChanged(FormEntry entry) {
111: if (blockListeners())
112: return;
113: boolean revert = false;
114: if (fName.getValue().length() == 0)
115: revert = true;
116: else {
117: ISchemaElement[] elements = fElement.getSchema()
118: .getElements();
119: for (int i = 0; i < elements.length; i++) {
120: if (elements[i] != fElement
121: && elements[i].getName()
122: .equalsIgnoreCase(
123: fName.getValue())) {
124: revert = true;
125: break;
126: }
127: }
128: }
129: if (revert)
130: fName.setValue(fElement.getName(), true);
131: else {
132: fElement.setName(fName.getValue());
133: ((Schema) fElement.getSchema())
134: .updateReferencesFor(fElement,
135: ISchema.REFRESH_RENAME);
136: setDecription(NLS
137: .bind(
138: PDEUIMessages.SchemaElementDetails_description,
139: fElement.getName()));
140: }
141: }
142: });
143: fDepTrue.addSelectionListener(new SelectionAdapter() {
144: public void widgetSelected(SelectionEvent e) {
145: if (blockListeners())
146: return;
147: fElement.setDeprecatedProperty(fDepTrue.getSelection());
148: }
149: });
150: fTransTrue.addSelectionListener(new SelectionAdapter() {
151: public void widgetSelected(SelectionEvent e) {
152: if (blockListeners())
153: return;
154: fElement.setTranslatableProperty(fTransTrue
155: .getSelection());
156: }
157: });
158: }
159:
160: public void modelChanged(IModelChangedEvent event) {
161: Object[] changedObjs = event.getChangedObjects();
162: if (event.getChangeType() == IModelChangedEvent.INSERT
163: && changedObjs.length > 0) {
164: if (changedObjs[0] instanceof SchemaElement) {
165: fName.getText().setFocus();
166: }
167: }
168: super .modelChanged(event);
169: }
170:
171: /* (non-Javadoc)
172: * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
173: */
174: public void commit(boolean onSave) {
175: super .commit(onSave);
176: // Only required for form entries
177: fName.commit();
178: }
179: }
|