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.ISchemaCompositor;
014: import org.eclipse.pde.internal.core.ischema.ISchemaObject;
015: import org.eclipse.pde.internal.core.schema.SchemaCompositor;
016: import org.eclipse.pde.internal.ui.PDEUIMessages;
017: import org.eclipse.pde.internal.ui.parts.ComboPart;
018: import org.eclipse.swt.SWT;
019: import org.eclipse.swt.events.SelectionAdapter;
020: import org.eclipse.swt.events.SelectionEvent;
021: import org.eclipse.swt.layout.GridData;
022: import org.eclipse.swt.widgets.Composite;
023: import org.eclipse.swt.widgets.Label;
024: import org.eclipse.ui.forms.IFormColors;
025: import org.eclipse.ui.forms.widgets.FormToolkit;
026:
027: public class SchemaCompositorDetails extends AbstractSchemaDetails {
028:
029: private SchemaCompositor fCompositor;
030: private ComboPart fKind;
031: private Label fKindLabel;
032:
033: public SchemaCompositorDetails(ElementSection section) {
034: super (section, true, false);
035: }
036:
037: public void createDetails(Composite parent) {
038: FormToolkit toolkit = getManagedForm().getToolkit();
039:
040: createMinOccurComp(parent, toolkit);
041: createMaxOccurComp(parent, toolkit);
042:
043: fKindLabel = toolkit.createLabel(parent,
044: PDEUIMessages.SchemaCompositorDetails_type);
045: fKindLabel.setForeground(toolkit.getColors().getColor(
046: IFormColors.TITLE));
047: fKind = new ComboPart();
048: fKind.createControl(parent, toolkit, SWT.READ_ONLY);
049: GridData gd = new GridData(GridData.FILL_HORIZONTAL);
050: gd.horizontalSpan = 2;
051: fKind.getControl().setLayoutData(gd);
052: fKind
053: .setItems(new String[] {
054: ISchemaCompositor.kindTable[ISchemaCompositor.CHOICE],
055: ISchemaCompositor.kindTable[ISchemaCompositor.SEQUENCE] });
056: fKind.getControl().setEnabled(isEditable());
057:
058: setText(PDEUIMessages.SchemaCompositorDetails_title);
059: }
060:
061: public void updateFields(ISchemaObject object) {
062: if (!(object instanceof SchemaCompositor))
063: return;
064: fCompositor = (SchemaCompositor) object;
065: setDecription(NLS.bind(
066: PDEUIMessages.SchemaCompositorDetails_description,
067: fCompositor.getName()));
068: updateMinOccur(fCompositor.getMinOccurs());
069: updateMaxOccur(fCompositor.getMaxOccurs());
070: fKind.select(fCompositor.getKind() - 1);
071:
072: boolean editable = isEditableElement();
073: fKindLabel.setEnabled(editable);
074: fKind.setEnabled(editable);
075: enableMinMax(editable);
076: }
077:
078: public void hookListeners() {
079: hookMinOccur(new SelectionAdapter() {
080: public void widgetSelected(SelectionEvent e) {
081: if (blockListeners())
082: return;
083: fCompositor.setMinOccurs(getMinOccur());
084: }
085: });
086: hookMaxOccur(new SelectionAdapter() {
087: public void widgetSelected(SelectionEvent e) {
088: if (blockListeners())
089: return;
090: fCompositor.setMaxOccurs(getMaxOccur());
091: }
092: });
093: fKind.addSelectionListener(new SelectionAdapter() {
094: public void widgetSelected(SelectionEvent e) {
095: if (blockListeners())
096: return;
097: fCompositor.setKind(fKind.getSelectionIndex() + 1);
098: setDecription(NLS
099: .bind(
100: PDEUIMessages.SchemaCompositorDetails_description,
101: fCompositor.getName()));
102: }
103: });
104: }
105:
106: /* (non-Javadoc)
107: * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean)
108: */
109: public void commit(boolean onSave) {
110: super .commit(onSave);
111: // Only required for form entries
112: // NO-OP
113: }
114: }
|