### Eclipse Workspace Patch 1.0 #P org.eclipse.pde.ui Index: src/org/eclipse/pde/internal/ui/editor/cheatsheet/CSSourceViewer.java =================================================================== RCS file: src/org/eclipse/pde/internal/ui/editor/cheatsheet/CSSourceViewer.java diff -N src/org/eclipse/pde/internal/ui/editor/cheatsheet/CSSourceViewer.java --- src/org/eclipse/pde/internal/ui/editor/cheatsheet/CSSourceViewer.java 14 May 2007 22:34:51 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,262 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ - -package org.eclipse.pde.internal.ui.editor.cheatsheet; - -import org.eclipse.core.filebuffers.IDocumentSetupParticipant; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.ITextOperationTarget; -import org.eclipse.jface.text.source.SourceViewer; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.pde.internal.ui.editor.PDEFormPage; -import org.eclipse.pde.internal.ui.editor.context.XMLDocumentSetupParticpant; -import org.eclipse.pde.internal.ui.editor.text.ColorManager; -import org.eclipse.pde.internal.ui.editor.text.IColorManager; -import org.eclipse.pde.internal.ui.editor.text.XMLConfiguration; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StyledText; -import org.eclipse.swt.events.DisposeEvent; -import org.eclipse.swt.events.DisposeListener; -import org.eclipse.swt.events.FocusAdapter; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.ui.actions.ActionFactory; -import org.eclipse.ui.forms.widgets.FormToolkit; - -/** - * CSSourceViewerFactory - * - */ -public class CSSourceViewer { - - private static XMLConfiguration fSourceConfiguration = null; - - private static IColorManager fColorManager = null; - - private static int fSourceViewerCount = 0; - - private SourceViewer fViewer; - - private PDEFormPage fPage; - - private IDocument fDocument; - - /** - * @param page - */ - public CSSourceViewer(PDEFormPage page) { - // Create the underlying document - fDocument = new Document(); - fPage = page; - } - - /** - * @return - */ - public IDocument getDocument() { - return fDocument; - } - - /** - * @return - */ - public SourceViewer getViewer() { - return fViewer; - } - - /** - * @return - */ - private XMLConfiguration getConfiguration() { - if (fSourceConfiguration == null) { - // Get the color manager - fColorManager = ColorManager.getDefault(); - // Create the source configuration - fSourceConfiguration = new XMLConfiguration(fColorManager); - } - return fSourceConfiguration; - } - - /** - * Utility method for creating a field for syntax highlighting - * @param parent - * @param heightHint - * @param widthHint - */ - public void createUI(Composite parent, int heightHint, int widthHint) { - // Create the source viewer - int style = SWT.MULTI | SWT.WRAP | SWT.V_SCROLL; - fViewer = new SourceViewer(parent, null, style); - // Configure the source viewer - fViewer.configure(getConfiguration()); - // Setup the underlying document - IDocumentSetupParticipant participant = new XMLDocumentSetupParticpant(); - participant.setup(fDocument); - // Set the document on the source viewer - fViewer.setDocument(fDocument); - // Configure the underlying styled text widget - configureUIStyledText(heightHint, widthHint, fViewer.getTextWidget()); - // Create style text listeners - createUIListenersStyledText(fViewer.getTextWidget()); - } - - /** - * - */ - public void createUIListeners() { - // Ensure the viewer was created - if (fViewer == null) { - return; - } - // Create source viewer listeners - // Create selection listener - fViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - fPage.getPDEEditor().setSelection(event.getSelection()); - } - }); - // Create focus listener - fViewer.getTextWidget().addFocusListener(new FocusAdapter() { - public void focusGained(FocusEvent e) { - fPage.getPDEEditor().getContributor().updateSelectableActions(null); - } - }); - } - - /** - * @param textWidget - */ - private void createUIListenersStyledText(StyledText textWidget) { - // Track the number of source viewers created - fSourceViewerCount++; - // The color manager and source viewer configuration should be disposed - // When the last source viewer is diposed, dispose of the color manager - // and source viewer configuration - textWidget.addDisposeListener(new DisposeListener() { - public void widgetDisposed(DisposeEvent e) { - fSourceViewerCount--; - if (fSourceViewerCount == 0) { - dispose(); - } - } - }); - } - - /** - * - */ - private void dispose() { - // TODO: MP: CompCS: Profile Sleek when making static to ensure no leaks - // Dispose of the color manager - if (fColorManager != null) { - fColorManager.dispose(); - fColorManager = null; - } - // Dispose of the source configuration - if (fSourceConfiguration != null) { - fSourceConfiguration.dispose(); - fSourceConfiguration = null; - } - } - - /** - * @param heightHint - * @param widthHint - * @param styledText - */ - private void configureUIStyledText(int heightHint, - int widthHint, StyledText styledText) { - // Configure the underlying styled text widget - styledText.setMenu(fPage.getPDEEditor().getContextMenu()); - // Force borders - styledText.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); - GridData data = new GridData(GridData.FILL_HORIZONTAL); - data.heightHint = heightHint; - data.widthHint = widthHint; - styledText.setLayoutData(data); - } - - /** - * The menu set on the underlying styled text widget of the source viewer - * needs to be set to null before being diposed; otherwise, the menu will - * be disposed along with the widget. - * @param viewer - */ - public void unsetMenu() { - if (fViewer == null) { - return; - } - StyledText styledText = fViewer.getTextWidget(); - if (styledText == null) { - return; - } else if (styledText.isDisposed()) { - return; - } - styledText.setMenu(null); - } - - /** - * Utility method used to tie global actions into source viewers. - * - * @param actionId - * @param viewer - * @return - */ - public boolean doGlobalAction(String actionId) { - // Ensure the viewer was created - if (fViewer == null) { - return false; - } else if (actionId.equals(ActionFactory.CUT.getId())) { - fViewer.doOperation(ITextOperationTarget.CUT); - return true; - } else if ( - actionId.equals(ActionFactory.COPY.getId())) { - fViewer.doOperation(ITextOperationTarget.COPY); - return true; - } else if ( - actionId.equals(ActionFactory.PASTE.getId())) { - fViewer.doOperation(ITextOperationTarget.PASTE); - return true; - } else if ( - actionId.equals(ActionFactory.SELECT_ALL.getId())) { - fViewer.doOperation(ITextOperationTarget.SELECT_ALL); - return true; - } else if ( - actionId.equals(ActionFactory.DELETE.getId())) { - fViewer.doOperation(ITextOperationTarget.DELETE); - return true; - } else if ( - actionId.equals(ActionFactory.UNDO.getId())) { - fViewer.doOperation(ITextOperationTarget.UNDO); - return true; - } else if ( - actionId.equals(ActionFactory.REDO.getId())) { - fViewer.doOperation(ITextOperationTarget.REDO); - return true; - } - return false; - } - - /** - * @param viewer - * @return - */ - public boolean canPaste() { - // Ensure the viewer was created - if (fViewer == null) { - return false; - } - return fViewer.canDoOperation(ITextOperationTarget.PASTE); - } -} Index: src/org/eclipse/pde/internal/ui/editor/schema/SchemaRootElementDetails.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaRootElementDetails.java,v retrieving revision 1.19 diff -u -r1.19 SchemaRootElementDetails.java --- src/org/eclipse/pde/internal/ui/editor/schema/SchemaRootElementDetails.java 10 Jul 2007 22:51:44 -0000 1.19 +++ src/org/eclipse/pde/internal/ui/editor/schema/SchemaRootElementDetails.java 18 Jul 2007 18:47:14 -0000 @@ -37,7 +37,7 @@ private FormEntry fSuggestion; public SchemaRootElementDetails(ElementSection section) { - super(section, true); + super(section, true, true); } public void createDetails(Composite parent) { Index: src/org/eclipse/pde/internal/ui/editor/schema/SchemaCompositorDetails.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaCompositorDetails.java,v retrieving revision 1.11 diff -u -r1.11 SchemaCompositorDetails.java --- src/org/eclipse/pde/internal/ui/editor/schema/SchemaCompositorDetails.java 8 Jun 2007 16:46:51 -0000 1.11 +++ src/org/eclipse/pde/internal/ui/editor/schema/SchemaCompositorDetails.java 18 Jul 2007 18:47:14 -0000 @@ -31,7 +31,7 @@ private Label fKindLabel; public SchemaCompositorDetails(ElementSection section) { - super(section, true); + super(section, true, false); } public void createDetails(Composite parent) { Index: src/org/eclipse/pde/internal/ui/editor/schema/SchemaElementReferenceDetails.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaElementReferenceDetails.java,v retrieving revision 1.11 diff -u -r1.11 SchemaElementReferenceDetails.java --- src/org/eclipse/pde/internal/ui/editor/schema/SchemaElementReferenceDetails.java 8 Jun 2007 16:46:51 -0000 1.11 +++ src/org/eclipse/pde/internal/ui/editor/schema/SchemaElementReferenceDetails.java 18 Jul 2007 18:47:14 -0000 @@ -33,7 +33,7 @@ private Label fRefLabel; public SchemaElementReferenceDetails(ElementSection section) { - super(section, true); + super(section, true, false); } public void createDetails(Composite parent) { Index: src/org/eclipse/pde/internal/ui/editor/schema/AbstractSchemaDetails.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/AbstractSchemaDetails.java,v retrieving revision 1.19 diff -u -r1.19 AbstractSchemaDetails.java --- src/org/eclipse/pde/internal/ui/editor/schema/AbstractSchemaDetails.java 17 Jul 2007 15:46:10 -0000 1.19 +++ src/org/eclipse/pde/internal/ui/editor/schema/AbstractSchemaDetails.java 18 Jul 2007 18:47:14 -0000 @@ -9,17 +9,23 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.pde.internal.ui.editor.schema; +import org.eclipse.jface.text.DocumentEvent; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IDocumentListener; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.pde.core.IModelChangedEvent; import org.eclipse.pde.internal.core.ischema.ISchemaCompositor; import org.eclipse.pde.internal.core.ischema.ISchemaObject; +import org.eclipse.pde.internal.core.schema.SchemaObject; import org.eclipse.pde.internal.ui.PDEUIMessages; import org.eclipse.pde.internal.ui.editor.FormLayoutFactory; import org.eclipse.pde.internal.ui.editor.PDEDetails; import org.eclipse.pde.internal.ui.editor.PDEFormPage; import org.eclipse.pde.internal.ui.parts.ComboPart; +import org.eclipse.pde.internal.ui.parts.PDESourceViewer; import org.eclipse.swt.SWT; +import org.eclipse.swt.dnd.Clipboard; import org.eclipse.swt.events.ModifyEvent; import org.eclipse.swt.events.ModifyListener; import org.eclipse.swt.events.SelectionAdapter; @@ -44,23 +50,23 @@ new String[] { Boolean.toString(true), Boolean.toString(false) }; private Section fSection; - private SchemaDtdDetailsSection fDtdSection; + private SchemaDtdDetailsSection fDtdSection = null; private ElementSection fElementSection; private boolean fShowDTD; + private boolean fShowDescription; private Spinner fMinOccurSpinner; private Spinner fMaxOccurSpinner; private Button fUnboundSelect; private Label fMinLabel; private Label fMaxLabel; + private PDESourceViewer fDescriptionViewer = null; private boolean fBlockListeners = false; + private ISchemaObject fSchemaObject; - public AbstractSchemaDetails(ElementSection section) { - this(section,false); - } - - public AbstractSchemaDetails(ElementSection section, boolean showDTD) { + public AbstractSchemaDetails(ElementSection section, boolean showDTD, boolean showDescription) { fElementSection = section; fShowDTD = showDTD; + fShowDescription = showDescription; } public void modelChanged(IModelChangedEvent event) { @@ -84,7 +90,11 @@ fSection.clientVerticalSpacing = FormLayoutFactory.SECTION_HEADER_VERTICAL_SPACING; fSection.setLayout(FormLayoutFactory.createClearGridLayout(false, 1)); - GridData gd = new GridData(GridData.FILL_HORIZONTAL); + GridData gd; + if (fShowDescription) + gd = new GridData(GridData.FILL_BOTH); + else + gd = new GridData(GridData.FILL_HORIZONTAL); fSection.setLayoutData(gd); // Align the master and details section headers (misalignment caused @@ -96,6 +106,9 @@ createDetails(client); + if (fShowDescription) + createDescription(client, toolkit); + // If the DTD Approximation section was requested, instantiate it and create it's contents // on the same parent Composite if (fShowDTD) { @@ -108,9 +121,52 @@ fSection.setClient(client); markDetailsPart(fSection); + if (fShowDescription) + fDescriptionViewer.createUIListeners(); hookListeners(); } + private void createDescription(Composite container, FormToolkit toolkit) { + Label label = toolkit.createLabel(container, PDEUIMessages.AbstractSchemaDetails_descriptionLabel); + GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); + gd.horizontalSpan = 3; + label.setLayoutData(gd); + label.setForeground(toolkit.getColors().getColor(IFormColors.TITLE)); + + fDescriptionViewer = new PDESourceViewer(getPage()); + gd = new GridData(GridData.FILL_BOTH); + gd.heightHint = 75; + gd.widthHint = 60; + gd.horizontalSpan = 3; + /* + * Needed to align vertically with form entry field and allow space + * for a possible field decoration + * commented out for now since fields are already grossly misaligned (see bug 196879) + * commenting out temporarily makes the alignment better on Element details and Attribute details + * but worse on RootElement details + */ + //gd.horizontalIndent = FormLayoutFactory.CONTROL_HORIZONTAL_INDENT; + fDescriptionViewer.createUI(container, gd); + fDescriptionViewer.getDocument().addDocumentListener(new IDocumentListener() { + public void documentChanged(DocumentEvent event) { + if (blockListeners()) + return; + if (fSchemaObject != null){ + // Get the text from the event + IDocument document = event.getDocument(); + if (document == null) { + return; + } + // Get the text from the event + String text = document.get().trim(); + updateObjectDescription(text); + } + } + public void documentAboutToBeChanged(DocumentEvent event) { + } + }); + } + public abstract void createDetails(Composite parent); public abstract void updateFields(ISchemaObject obj); public abstract void hookListeners(); @@ -118,7 +174,6 @@ public boolean isEditableElement() { return fElementSection.isEditable(); } - protected void setDecription(String desc) { fSection.setDescription(desc); } @@ -138,20 +193,49 @@ markDirty(); getPage().getPDEEditor().fireSaveNeeded(getContextId(), false); } + public boolean canPaste(Clipboard clipboard) { + if (fShowDescription && fDescriptionViewer != null && + fDescriptionViewer.getViewer().getTextWidget().isFocusControl()) + return fDescriptionViewer.canPaste(); + return super.canPaste(clipboard); + } + public boolean doGlobalAction(String actionId) { + if (fShowDescription && fDescriptionViewer != null && + fDescriptionViewer.getViewer().getTextWidget().isFocusControl()) + return fDescriptionViewer.doGlobalAction(actionId); + return super.doGlobalAction(actionId); + } public void selectionChanged(IFormPart part, ISelection selection) { if (!(part instanceof ElementSection)) return; Object obj = ((IStructuredSelection)selection).getFirstElement(); - if ((fShowDTD) && - (fDtdSection != null)) { - fDtdSection.updateDTDLabel(obj); - } if (obj instanceof ISchemaObject) { setBlockListeners(true); - updateFields((ISchemaObject)obj); + ISchemaObject sObj = (ISchemaObject)obj; + fSchemaObject = sObj; + if (fShowDTD && fDtdSection != null) + fDtdSection.updateDTDLabel(obj); + if (fShowDescription && fDescriptionViewer != null) + updateDescriptionViewer(sObj); + updateFields(sObj); setBlockListeners(false); } } + public void updateDescriptionViewer(ISchemaObject obj) { + if (obj != null) { + String text = obj.getDescription(); + fDescriptionViewer.getDocument().set(text == null ? "" : text); //$NON-NLS-1$ + } + } + private void updateObjectDescription(String text) { + if (fSchemaObject instanceof SchemaObject) { + ((SchemaObject)fSchemaObject).setDescription(text); + } + } + + protected void fireSelectionChange() { + fElementSection.fireSelection(fElementSection.getTreeViewer().getSelection()); + } protected void fireMasterSelection(ISelection selection) { fElementSection.fireSelection(selection); @@ -303,4 +387,14 @@ protected void setBlockListeners(boolean blockListeners) { fBlockListeners = blockListeners; } + + public void dispose() { + // Set the context menu to null to prevent the editor context menu + // from being disposed along with the source viewer + if (fDescriptionViewer != null) { + fDescriptionViewer.unsetMenu(); + fDescriptionViewer = null; + } + super.dispose(); + } } Index: src/org/eclipse/pde/internal/ui/editor/schema/DescriptionSection.java =================================================================== RCS file: src/org/eclipse/pde/internal/ui/editor/schema/DescriptionSection.java diff -N src/org/eclipse/pde/internal/ui/editor/schema/DescriptionSection.java --- src/org/eclipse/pde/internal/ui/editor/schema/DescriptionSection.java 8 Jun 2007 16:46:51 -0000 1.38 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,210 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.pde.internal.ui.editor.schema; - -import org.eclipse.jface.action.IMenuManager; -import org.eclipse.jface.resource.JFaceResources; -import org.eclipse.jface.text.Document; -import org.eclipse.jface.text.DocumentEvent; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.IDocumentListener; -import org.eclipse.jface.text.ITextOperationTarget; -import org.eclipse.jface.text.source.SourceViewer; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.pde.internal.core.ischema.ISchemaObject; -import org.eclipse.pde.internal.core.ischema.ISchemaObjectReference; -import org.eclipse.pde.internal.core.schema.SchemaObject; -import org.eclipse.pde.internal.ui.PDEUIMessages; -import org.eclipse.pde.internal.ui.editor.FormLayoutFactory; -import org.eclipse.pde.internal.ui.editor.PDEFormPage; -import org.eclipse.pde.internal.ui.editor.PDESection; -import org.eclipse.pde.internal.ui.editor.context.XMLDocumentSetupParticpant; -import org.eclipse.pde.internal.ui.editor.text.IColorManager; -import org.eclipse.pde.internal.ui.editor.text.XMLConfiguration; -import org.eclipse.swt.SWT; -import org.eclipse.swt.dnd.Clipboard; -import org.eclipse.swt.events.FocusAdapter; -import org.eclipse.swt.events.FocusEvent; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.ui.actions.ActionFactory; -import org.eclipse.ui.forms.IFormPart; -import org.eclipse.ui.forms.IPartSelectionListener; -import org.eclipse.ui.forms.widgets.FormToolkit; -import org.eclipse.ui.forms.widgets.Section; - -public class DescriptionSection extends PDESection implements IPartSelectionListener { - private SourceViewer fSourceViewer; - private IDocument fDocument; - private ISchemaObject fElement; - private boolean fIgnoreChange; - private XMLConfiguration fSourceConfiguration; - - public DescriptionSection(PDEFormPage page, Composite parent, IColorManager colorManager) { - super(page, parent, Section.DESCRIPTION); - fSourceConfiguration = new XMLConfiguration(colorManager); - getSection().setText(PDEUIMessages.SchemaEditor_DescriptionSection_title); - getSection().setDescription(PDEUIMessages.SchemaEditor_DescriptionSection_desc); - createClient(getSection(), page.getManagedForm().getToolkit()); - } - - public void commit(boolean onSave) { - updateDescription(); - super.commit(onSave); - } - - public void createClient( - Section section, - FormToolkit toolkit) { - - Composite container = toolkit.createComposite(section); - container.setLayout(FormLayoutFactory.createSectionClientGridLayout(false, 2)); - GridData data = new GridData(GridData.FILL_HORIZONTAL); - section.setLayoutData(data); - - GridData gd; - fSourceViewer = new SourceViewer(container, null, SWT.MULTI|SWT.WRAP|SWT.V_SCROLL| SWT.H_SCROLL); - fSourceViewer.configure(fSourceConfiguration); - fDocument = new Document(); - new XMLDocumentSetupParticpant().setup(fDocument); - fSourceViewer.setDocument(fDocument); - fSourceViewer.setEditable(isEditable()); - fSourceViewer.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - updateSelection(event.getSelection()); - } - }); - - Control styledText = fSourceViewer.getTextWidget(); - styledText.setFont(JFaceResources.getFontRegistry().get(JFaceResources.TEXT_FONT)); - if (SWT.getPlatform().equals("motif") == false) //$NON-NLS-1$ - toolkit.paintBordersFor(container); - styledText.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); - Control[] children = container.getChildren(); - Control control = children[children.length - 1]; - gd = new GridData(GridData.FILL_BOTH); - gd.widthHint = 200; - gd.heightHint = 120; - control.setLayoutData(gd); - styledText.setMenu(getPage().getPDEEditor().getContextMenu()); - styledText.addFocusListener(new FocusAdapter() { - public void focusGained(FocusEvent e) { - updateSelection(fSourceViewer.getSelection()); - } - }); - section.setClient(container); - initialize(); - } - - private void updateSelection(ISelection selection) { - getPage().getPDEEditor().setSelection(selection); - } - - public boolean doGlobalAction(String actionId) { - if (actionId.equals(ActionFactory.CUT.getId())) { - fSourceViewer.doOperation(ITextOperationTarget.CUT); - return true; - } else if ( - actionId.equals(ActionFactory.COPY.getId())) { - fSourceViewer.doOperation(ITextOperationTarget.COPY); - return true; - } else if ( - actionId.equals(ActionFactory.PASTE.getId())) { - fSourceViewer.doOperation(ITextOperationTarget.PASTE); - return true; - } else if ( - actionId.equals(ActionFactory.SELECT_ALL.getId())) { - fSourceViewer.doOperation(ITextOperationTarget.SELECT_ALL); - return true; - } else if ( - actionId.equals(ActionFactory.DELETE.getId())) { - fSourceViewer.doOperation(ITextOperationTarget.DELETE); - return true; - } else if ( - actionId.equals(ActionFactory.UNDO.getId())) { - fSourceViewer.doOperation(ITextOperationTarget.UNDO); - return true; - } else if ( - actionId.equals(ActionFactory.REDO.getId())) { - fSourceViewer.doOperation(ITextOperationTarget.REDO); - return true; - } - return false; - } - - protected void fillContextMenu(IMenuManager manager) { - getPage().getPDEEditor().getContributor().contextMenuAboutToShow(manager); - } - - private void updateDescription() { - if (fElement instanceof SchemaObject) { - ((SchemaObject)fElement).setDescription(fDocument.get()); - } - } - - public void initialize() { - updateDocument(); - fDocument.addDocumentListener(new IDocumentListener() { - public void documentChanged(DocumentEvent e) { - if (!fIgnoreChange && getPage().getPDEEditor().getAggregateModel().isEditable()) { - markDirty(); - } - } - public void documentAboutToBeChanged(DocumentEvent e) { - } - }); - } - - public void selectionChanged(IFormPart part, ISelection selection) { - if (!(part instanceof ElementSection)) - return; - Object changeObject = ((IStructuredSelection)selection).getFirstElement(); - if (changeObject != fElement && isDirty()) - updateDescription(); - fElement = (ISchemaObject) changeObject; - if (fElement instanceof ISchemaObjectReference) - fElement = ((ISchemaObjectReference)fElement).getReferencedObject(); - updateDocument(); - } - - public void setFocus() { - fSourceViewer.getTextWidget().setFocus(); - } - - public void updateDocument() { - if (fElement != null) { - fIgnoreChange = true; - String text = fElement.getDescription(); - fDocument.set(text == null ? "" : text); //$NON-NLS-1$ - fIgnoreChange = false; - } - } - - public boolean canPaste(Clipboard clipboard) { - return fSourceViewer.canDoOperation(ITextOperationTarget.PASTE); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.forms.AbstractFormPart#dispose() - */ - public void dispose() { - // Dispose of the source configuration - if (fSourceConfiguration != null) { - fSourceConfiguration.dispose(); - } - super.dispose(); - } - -} Index: src/org/eclipse/pde/internal/ui/editor/schema/SchemaAttributeDetails.java =================================================================== RCS file: src/org/eclipse/pde/internal/ui/editor/schema/SchemaAttributeDetails.java diff -N src/org/eclipse/pde/internal/ui/editor/schema/SchemaAttributeDetails.java --- src/org/eclipse/pde/internal/ui/editor/schema/SchemaAttributeDetails.java 17 Jul 2007 17:06:00 -0000 1.31 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,599 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.pde.internal.ui.editor.schema; -import java.util.Vector; - -import org.eclipse.core.resources.IProject; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jdt.core.IJavaElement; -import org.eclipse.jdt.core.IJavaProject; -import org.eclipse.jdt.core.IType; -import org.eclipse.jdt.core.JavaCore; -import org.eclipse.jdt.core.search.IJavaSearchConstants; -import org.eclipse.jdt.core.search.SearchEngine; -import org.eclipse.jdt.ui.IJavaElementSearchConstants; -import org.eclipse.jdt.ui.JavaUI; -import org.eclipse.jface.viewers.ISelection; -import org.eclipse.jface.viewers.ISelectionChangedListener; -import org.eclipse.jface.viewers.IStructuredSelection; -import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jface.viewers.SelectionChangedEvent; -import org.eclipse.jface.viewers.TableViewer; -import org.eclipse.jface.window.Window; -import org.eclipse.jface.wizard.WizardDialog; -import org.eclipse.osgi.util.NLS; -import org.eclipse.pde.core.IModelChangedEvent; -import org.eclipse.pde.internal.core.ischema.IMetaAttribute; -import org.eclipse.pde.internal.core.ischema.ISchemaObject; -import org.eclipse.pde.internal.core.ischema.ISchemaRestriction; -import org.eclipse.pde.internal.core.ischema.ISchemaSimpleType; -import org.eclipse.pde.internal.core.schema.ChoiceRestriction; -import org.eclipse.pde.internal.core.schema.SchemaAttribute; -import org.eclipse.pde.internal.core.schema.SchemaEnumeration; -import org.eclipse.pde.internal.core.schema.SchemaSimpleType; -import org.eclipse.pde.internal.ui.PDEPlugin; -import org.eclipse.pde.internal.ui.PDEUIMessages; -import org.eclipse.pde.internal.ui.editor.FormEntryAdapter; -import org.eclipse.pde.internal.ui.editor.contentassist.TypeFieldAssistDisposer; -import org.eclipse.pde.internal.ui.elements.DefaultTableProvider; -import org.eclipse.pde.internal.ui.parts.ComboPart; -import org.eclipse.pde.internal.ui.parts.FormEntry; -import org.eclipse.pde.internal.ui.util.PDEJavaHelperUI; -import org.eclipse.pde.internal.ui.util.SWTUtil; -import org.eclipse.swt.SWT; -import org.eclipse.swt.custom.StackLayout; -import org.eclipse.swt.events.SelectionAdapter; -import org.eclipse.swt.events.SelectionEvent; -import org.eclipse.swt.graphics.Color; -import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; -import org.eclipse.swt.widgets.Button; -import org.eclipse.swt.widgets.Composite; -import org.eclipse.swt.widgets.Control; -import org.eclipse.swt.widgets.Label; -import org.eclipse.swt.widgets.Table; -import org.eclipse.ui.IActionBars; -import org.eclipse.ui.PartInitException; -import org.eclipse.ui.PlatformUI; -import org.eclipse.ui.dialogs.SelectionDialog; -import org.eclipse.ui.forms.IFormColors; -import org.eclipse.ui.forms.events.HyperlinkEvent; -import org.eclipse.ui.forms.widgets.FormToolkit; - -public class SchemaAttributeDetails extends AbstractSchemaDetails { - - private static final String JAVA_TYPE = "java"; //$NON-NLS-1$ - private static final String RESOURCE_TYPE = "resource"; //$NON-NLS-1$ - private static final int BOOL_IND = 0; - private static final int STR_IND = 1; - private static final int JAVA_IND = 2; - private static final int RES_IND = 3; - private static final String[] TYPES = new String[4]; - static { - TYPES[BOOL_IND]= BOOLEAN_TYPE; - TYPES[STR_IND] = STRING_TYPE; - TYPES[JAVA_IND] = JAVA_TYPE; - TYPES[RES_IND] = RESOURCE_TYPE; - } - private static final String[] USE = - new String[] {"optional", "required", "default"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - - private SchemaAttribute fAttribute; - private FormEntry fValue; - private FormEntry fName; - private Button fDepTrue; - private Button fDepFalse; - private Button fTransTrue; - private Button fTransFalse; - private ComboPart fType; - private ComboPart fUse; - private TableViewer fRestrictionsTable; - private FormEntry fClassEntry; - private FormEntry fInterfaceEntry; - private Button fAddRestriction; - private Button fRemoveRestriction; - private Composite fBooleanTypeComp; - private Composite fStringTypeComp; - private Composite fJavaTypeComp; - private Composite fResourceTypeComp; - private Composite fNotebook; - private StackLayout fNotebookLayout; - private TypeFieldAssistDisposer fClassEntryFieldAssistDisposer; - private TypeFieldAssistDisposer fInterfaceEntryFieldAssistDisposer; - - public SchemaAttributeDetails(ElementSection section) { - super(section, false); - } - - class SchemaAttributeContentProvider extends DefaultTableProvider { - public Object[] getElements(Object inputElement) { - ISchemaSimpleType type = fAttribute.getType(); - ISchemaRestriction restriction = type.getRestriction(); - if (restriction != null) - return restriction.getChildren(); - return new Object[0]; - } - } - - public void createDetails(Composite parent) { - FormToolkit toolkit = getManagedForm().getToolkit(); - Color foreground = toolkit.getColors().getColor(IFormColors.TITLE); - - fName = new FormEntry(parent, toolkit, PDEUIMessages.SchemaDetails_name, SWT.NONE); - - Label label = toolkit.createLabel(parent, PDEUIMessages.SchemaDetails_deprecated); - label.setForeground(foreground); - Button[] buttons = createTrueFalseButtons(parent, toolkit, 2); - fDepTrue = buttons[0]; - fDepFalse = buttons[1]; - - label = toolkit.createLabel(parent, PDEUIMessages.SchemaAttributeDetails_use); - label.setForeground(foreground); - fUse = createComboPart(parent, toolkit, USE, 2); - - fValue = new FormEntry(parent, toolkit, PDEUIMessages.SchemaAttributeDetails_defaultValue, null, false, 6); - - label = toolkit.createLabel(parent, PDEUIMessages.SchemaAttributeDetails_type); - label.setForeground(foreground); - fType = createComboPart(parent, toolkit, TYPES, 2); - - fNotebook = toolkit.createComposite(parent); - GridData gd = new GridData(GridData.FILL_BOTH); - gd.horizontalSpan = 3; - fNotebook.setLayoutData(gd); - fNotebook.setLayout(new GridLayout()); - fNotebookLayout = new StackLayout(); - fNotebook.setLayout(fNotebookLayout); - - fBooleanTypeComp = createEmptyComposite(fNotebook, toolkit); - fStringTypeComp = createStringTypeComp(fNotebook, toolkit, foreground); - fJavaTypeComp = createJavaTypeComp(fNotebook, toolkit, foreground); - fResourceTypeComp = createEmptyComposite(fNotebook, toolkit); - - toolkit.paintBordersFor(parent); - toolkit.paintBordersFor(fNotebook); - toolkit.paintBordersFor(fJavaTypeComp); - toolkit.paintBordersFor(fStringTypeComp); - setText(PDEUIMessages.SchemaAttributeDetails_title); - } - - private Composite createEmptyComposite(Composite parent, FormToolkit toolkit) { - Composite comp = toolkit.createComposite(parent); - comp.setLayoutData(new GridData(GridData.FILL_BOTH)); - GridLayout layout = new GridLayout(3, false); - layout.marginHeight = 2; - layout.marginWidth = 0; - comp.setLayout(layout); - return comp; - } - - private Composite createJavaTypeComp(Composite parent, FormToolkit toolkit, Color foreground) { - Composite comp = createEmptyComposite(parent, toolkit); - fClassEntry = new FormEntry(comp, toolkit, PDEUIMessages.SchemaAttributeDetails_extends, PDEUIMessages.SchemaAttributeDetails_browseButton, isEditable(), 13); - fClassEntryFieldAssistDisposer = PDEJavaHelperUI.addTypeFieldAssistToText(fClassEntry.getText(), - getPage().getPDEEditor().getCommonProject(), - IJavaSearchConstants.CLASS); - fInterfaceEntry = new FormEntry(comp, toolkit, PDEUIMessages.SchemaAttributeDetails_implements, PDEUIMessages.SchemaAttributeDetails_browseButton, isEditable(), 13); - fInterfaceEntryFieldAssistDisposer = PDEJavaHelperUI.addTypeFieldAssistToText(fInterfaceEntry.getText(), - getPage().getPDEEditor().getCommonProject(), - IJavaSearchConstants.INTERFACE); - return comp; - } - - private Composite createStringTypeComp(Composite parent, FormToolkit toolkit, Color foreground) { - Composite comp = createEmptyComposite(parent, toolkit); - Label label = toolkit.createLabel(comp, PDEUIMessages.SchemaDetails_translatable); - label.setForeground(foreground); - GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); - gd.horizontalIndent = 11; - gd.verticalIndent = 2; - label.setLayoutData(gd); - Button[] buttons = createTrueFalseButtons(comp, toolkit, 2); - fTransTrue = buttons[0]; - fTransFalse = buttons[1]; - - label = toolkit.createLabel(comp, PDEUIMessages.SchemaAttributeDetails_restrictions); - label.setForeground(foreground); - gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); - gd.horizontalIndent = 11; - gd.verticalIndent = 2; - label.setLayoutData(gd); - - Composite tableComp = toolkit.createComposite(comp); - GridLayout layout = new GridLayout(); layout.marginHeight = layout.marginWidth = 0; - tableComp.setLayout(layout); - tableComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - - Table table = toolkit.createTable(tableComp, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); - gd = new GridData(GridData.FILL_HORIZONTAL); - gd.heightHint = 40; - table.setLayoutData(gd); - fRestrictionsTable = new TableViewer(table); - fRestrictionsTable.setContentProvider(new SchemaAttributeContentProvider()); - fRestrictionsTable.setLabelProvider(new LabelProvider()); - - Composite resButtonComp = toolkit.createComposite(comp); - layout = new GridLayout(); layout.marginHeight = layout.marginWidth = 0; - resButtonComp.setLayout(layout); - resButtonComp.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); - fAddRestriction = toolkit.createButton(resButtonComp, PDEUIMessages.SchemaAttributeDetails_addRestButton, SWT.NONE); - fRemoveRestriction = toolkit.createButton(resButtonComp, PDEUIMessages.SchemaAttributeDetails_removeRestButton, SWT.NONE); - fAddRestriction.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - fRemoveRestriction.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); - return comp; - } - - public void updateFields(ISchemaObject object) { - if (!(object instanceof SchemaAttribute)) - return; - fAttribute = (SchemaAttribute)object; - setDecription(NLS.bind(PDEUIMessages.SchemaAttributeDetails_description, fAttribute.getName())); - fRestrictionsTable.setInput(new Object()); - fName.setValue(fAttribute.getName(), true); //$NON-NLS-1$ - fDepTrue.setSelection(fAttribute.isDeprecated()); - fDepFalse.setSelection(!fAttribute.isDeprecated()); - - fTransTrue.setSelection(fAttribute.isTranslatable()); - fTransFalse.setSelection(!fAttribute.isTranslatable()); - - boolean isStringType = fAttribute.getType().getName().equals(STRING_TYPE); - int kind = fAttribute.getKind(); - fType.select(isStringType ? 1 + kind : 0); - - fUse.select(fAttribute.getUse()); - Object value = fAttribute.getValue(); - fValue.setValue(value != null ? value.toString() : "", true); //$NON-NLS-1$ - - updateJavaFields(); - - boolean editable = isEditableElement(); - updateTabSelection(fType.getSelectionIndex()); - fTransTrue.setEnabled(editable); - fTransFalse.setEnabled(editable); - fRestrictionsTable.getControl().setEnabled(editable); - fAddRestriction.setEnabled(editable); - fRemoveRestriction.setEnabled( - !fRestrictionsTable.getSelection().isEmpty() && editable); - if (fAttribute.getUse() != 2) { - fValue.getLabel().setEnabled(false); - fValue.getText().setEditable(false); - } else { - fValue.setEditable(editable); - } - fName.setEditable(editable); - fDepTrue.setEnabled(editable); - fDepFalse.setEnabled(editable); - fType.setEnabled(editable); - fUse.setEnabled(editable); - fClassEntry.setEditable(editable); - fInterfaceEntry.setEditable(editable); - } - - /** - * - */ - private void updateJavaFields() { - String basedOn = fAttribute.getBasedOn(); - if ((basedOn != null) && - (basedOn.length() > 0)) { - int index = basedOn.indexOf(":"); //$NON-NLS-1$ - if (index == -1) { - String className = - basedOn.substring(basedOn.lastIndexOf(".") + 1); //$NON-NLS-1$ - if ((className.length() > 1) && - (className.charAt(0) == 'I')) { - fClassEntry.setValue("", true); //$NON-NLS-1$ - fInterfaceEntry.setValue(basedOn, true); - } else { - fClassEntry.setValue(basedOn, true); - fInterfaceEntry.setValue("", true); //$NON-NLS-1$ - } - } else { - fClassEntry.setValue(basedOn.substring(0, index), true); - fInterfaceEntry.setValue(basedOn.substring(index + 1), true); - } - } else { - fClassEntry.setValue("", true); //$NON-NLS-1$ - fInterfaceEntry.setValue("", true); //$NON-NLS-1$ - } - } - - public void hookListeners() { - IActionBars actionBars = getPage().getPDEEditor().getEditorSite().getActionBars(); - fValue.setFormEntryListener(new FormEntryAdapter(this) { - public void textValueChanged(FormEntry entry) { - if (blockListeners()) - return; - fAttribute.setValue(fValue.getValue()); - } - }); - fName.setFormEntryListener(new FormEntryAdapter(this) { - public void textValueChanged(FormEntry entry) { - if (blockListeners()) - return; - if (fName.getValue().length() != 0) { - fAttribute.setName(fName.getValue()); - setDecription(NLS.bind(PDEUIMessages.SchemaAttributeDetails_description, fAttribute.getName())); - } else { - fName.setValue(fAttribute.getName(), true); - } - } - }); - fDepTrue.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (blockListeners()) - return; - fAttribute.setDeprecatedProperty(fDepTrue.getSelection()); - } - }); - fTransTrue.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (blockListeners()) - return; - fAttribute.setTranslatableProperty(fTransTrue.getSelection()); - } - }); - fType.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (blockListeners()) - return; - String typeString = fType.getSelection(); - if (!typeString.equals(BOOLEAN_TYPE)) - typeString = STRING_TYPE; - - fAttribute.setType(new SchemaSimpleType(fAttribute.getSchema(), typeString)); - - int kind = fType.getSelectionIndex() - 1; // adjust for "boolean" in combo - fAttribute.setKind(kind > 0 ? kind : 0); // kind could be -1 - - ISchemaSimpleType type = fAttribute.getType(); - if (type instanceof SchemaSimpleType - && kind != IMetaAttribute.STRING - && ((SchemaSimpleType) type).getRestriction() != null) { - ((SchemaSimpleType) type).setRestriction(null); - } - updateTabSelection(fType.getSelectionIndex()); - } - }); - fUse.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (blockListeners()) - return; - int use = fUse.getSelectionIndex(); - fAttribute.setUse(use); - fValue.getLabel().setEnabled(use == 2); - fValue.getText().setEditable(use == 2); - if (use == 2 && fValue.getValue().length() == 0) { - fValue.setValue(PDEUIMessages.SchemaAttributeDetails_defaultDefaultValue); - fValue.getText().setSelection(0, fValue.getValue().length()); - fValue.getText().setFocus(); - } else if (use != 2) - fValue.setValue(""); //$NON-NLS-1$ - - } - }); - fClassEntry.setFormEntryListener(new FormEntryAdapter(this, actionBars) { - public void textValueChanged(FormEntry entry) { - if (blockListeners()) - return; - setBasedOn(); - } - public void linkActivated(HyperlinkEvent e) { - if (blockListeners()) - return; - String value = fClassEntry.getValue(); - value = handleLinkActivated(value, false); - if (value != null) - fClassEntry.setValue(value); - } - public void browseButtonSelected(FormEntry entry) { - if (blockListeners()) - return; - doOpenSelectionDialog( - IJavaElementSearchConstants.CONSIDER_CLASSES, fClassEntry); - } - }); - fInterfaceEntry.setFormEntryListener(new FormEntryAdapter(this, actionBars) { - public void textValueChanged(FormEntry entry) { - if (blockListeners()) - return; - setBasedOn(); - } - public void linkActivated(HyperlinkEvent e) { - if (blockListeners()) - return; - String value = fInterfaceEntry.getValue(); - value = handleLinkActivated(value, true); - if (value != null) - fInterfaceEntry.setValue(value); - } - public void browseButtonSelected(FormEntry entry) { - if (blockListeners()) - return; - doOpenSelectionDialog( - IJavaElementSearchConstants.CONSIDER_INTERFACES, fInterfaceEntry); - } - }); - fAddRestriction.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (blockListeners()) - return; - NewRestrictionDialog dialog = new NewRestrictionDialog(getPage().getSite().getShell()); - if (dialog.open() != Window.OK) return; - String text = dialog.getNewRestriction(); - if (text != null && text.length() > 0) { - ISchemaSimpleType type = fAttribute.getType(); - ChoiceRestriction res = (ChoiceRestriction)type.getRestriction(); - Vector vres = new Vector(); - if (res != null) { - Object[] currRes = res.getChildren(); - for (int i = 0; i < currRes.length; i++) { - vres.add(currRes[i]); - } - } - vres.add(new SchemaEnumeration(fAttribute.getSchema(), text)); - if (res == null) - res = new ChoiceRestriction(fAttribute.getSchema()); - res.setChildren(vres); - if (type instanceof SchemaSimpleType) - ((SchemaSimpleType)type).setRestriction(res); - fRestrictionsTable.refresh(); - } - } - }); - fRemoveRestriction.addSelectionListener(new SelectionAdapter() { - public void widgetSelected(SelectionEvent e) { - if (blockListeners()) - return; - ISelection selection = fRestrictionsTable.getSelection(); - if (selection.isEmpty()) return; - if (!(selection instanceof IStructuredSelection)) return; - IStructuredSelection sselection = (IStructuredSelection)selection; - Object[] aselection = sselection.toArray(); - ISchemaSimpleType type = fAttribute.getType(); - ChoiceRestriction res = (ChoiceRestriction)type.getRestriction(); - Vector vres = new Vector(); - if (res != null) { - Object[] currRes = res.getChildren(); - for (int i = 0; i < currRes.length; i++) { - boolean stays = true; - for (int j = 0; j < aselection.length; j++) { - if (currRes[i].equals(aselection[j])) - stays = false; - } - if (stays) vres.add(currRes[i]); - } - res.setChildren(vres); - if (type instanceof SchemaSimpleType) { - if (vres.size() == 0) - ((SchemaSimpleType)type).setRestriction(null); - else - ((SchemaSimpleType)type).setRestriction(res); - } - fRestrictionsTable.refresh(); - } - } - }); - fRestrictionsTable.addSelectionChangedListener(new ISelectionChangedListener() { - public void selectionChanged(SelectionChangedEvent event) { - if (blockListeners()) - return; - fRemoveRestriction.setEnabled(fAttribute.getSchema().isEditable() - && !event.getSelection().isEmpty()); - } - }); - } - - private String handleLinkActivated(String value, boolean isInter) { - IProject project = getPage().getPDEEditor().getCommonProject(); - try { - if (project != null && project.hasNature(JavaCore.NATURE_ID)) { - IJavaProject javaProject = JavaCore.create(project); - IJavaElement element = javaProject.findType(value.replace('$', '.')); - if (element != null) - JavaUI.openInEditor(element); - else { - NewClassCreationWizard wizard = new NewClassCreationWizard(project, isInter, value); - WizardDialog dialog = new WizardDialog(PDEPlugin.getActiveWorkbenchShell(), wizard); - dialog.create(); - SWTUtil.setDialogSize(dialog, 400, 500); - if (dialog.open() == Window.OK) { - return wizard.getQualifiedName(); - } - } - } - } catch (PartInitException e1) { - } catch (CoreException e1) { - } - return null; - } - - private void setBasedOn() { - String classEntry = fClassEntry.getValue().replaceAll(":", ""); //$NON-NLS-1$ //$NON-NLS-2$ - String interfaceEntry = fInterfaceEntry.getValue().replaceAll(":", ""); //$NON-NLS-1$ //$NON-NLS-2$ - StringBuffer sb = new StringBuffer(); - if (classEntry.length() > 0) - sb.append(classEntry); - if (classEntry.length() > 0 || interfaceEntry.length() > 0) - sb.append(":"); //$NON-NLS-1$ - if (interfaceEntry.length() > 0) - sb.append(interfaceEntry); - fAttribute.setBasedOn(sb.length() > 0 ? sb.toString() : null); - } - - private void doOpenSelectionDialog(int scopeType, FormEntry entry) { - try { - String filter = entry.getValue(); - filter = filter.substring(filter.lastIndexOf(".") + 1); //$NON-NLS-1$ - SelectionDialog dialog = JavaUI.createTypeDialog( - PDEPlugin.getActiveWorkbenchShell(), - PlatformUI.getWorkbench().getProgressService(), - SearchEngine.createWorkspaceScope(), scopeType, false, filter); //$NON-NLS-1$ - dialog.setTitle(PDEUIMessages.GeneralInfoSection_selectionTitle); - if (dialog.open() == Window.OK) { - IType type = (IType) dialog.getResult()[0]; - entry.setValue(type.getFullyQualifiedName('$')); - entry.commit(); - } - } catch (CoreException e) { - } - } - - private void updateTabSelection(int kind) { - Control oldPage = fNotebookLayout.topControl; - switch (kind) { - case 0: - fNotebookLayout.topControl = fBooleanTypeComp; - break; - case 1: - fNotebookLayout.topControl = fStringTypeComp; - break; - case 2: - fNotebookLayout.topControl = fJavaTypeComp; - break; - case 3: - fNotebookLayout.topControl = fResourceTypeComp; - break; - } - if (oldPage != fNotebookLayout.topControl) - fNotebook.layout(); - } - - public void modelChanged(IModelChangedEvent event) { - Object[] changedObjs = event.getChangedObjects(); - if(event.getChangeType() == IModelChangedEvent.INSERT && changedObjs.length > 0) { - if(changedObjs[0] instanceof SchemaAttribute) { - fName.getText().setFocus(); - } - } - super.modelChanged(event); - } - - /* (non-Javadoc) - * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean) - */ - public void commit(boolean onSave) { - super.commit(onSave); - // Only required for form entries - fName.commit(); - fClassEntry.commit(); - fInterfaceEntry.commit(); - fValue.commit(); - } - - public void dispose() { - super.dispose(); - if (fClassEntryFieldAssistDisposer != null) - fClassEntryFieldAssistDisposer.dispose(); - if (fInterfaceEntryFieldAssistDisposer != null) - fInterfaceEntryFieldAssistDisposer.dispose(); - } -} Index: src/org/eclipse/pde/internal/ui/editor/schema/SchemaElementDetails.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaElementDetails.java,v retrieving revision 1.23 diff -u -r1.23 SchemaElementDetails.java --- src/org/eclipse/pde/internal/ui/editor/schema/SchemaElementDetails.java 16 Jul 2007 15:16:13 -0000 1.23 +++ src/org/eclipse/pde/internal/ui/editor/schema/SchemaElementDetails.java 18 Jul 2007 18:47:14 -0000 @@ -48,7 +48,7 @@ private Button fTransFalse; public SchemaElementDetails(ElementSection section) { - super(section, true); + super(section, true, true); } public void createDetails(Composite parent) { Index: src/org/eclipse/pde/internal/ui/editor/schema/SchemaFormPage.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/schema/SchemaFormPage.java,v retrieving revision 1.21 diff -u -r1.21 SchemaFormPage.java --- src/org/eclipse/pde/internal/ui/editor/schema/SchemaFormPage.java 8 Jun 2007 16:46:51 -0000 1.21 +++ src/org/eclipse/pde/internal/ui/editor/schema/SchemaFormPage.java 18 Jul 2007 18:47:14 -0000 @@ -9,9 +9,12 @@ * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.pde.internal.ui.editor.schema; +import java.util.Arrays; + import org.eclipse.jface.action.ControlContribution; import org.eclipse.pde.core.IModelChangedEvent; import org.eclipse.pde.core.IModelChangedListener; +import org.eclipse.pde.internal.core.ischema.IMetaAttribute; import org.eclipse.pde.internal.core.ischema.ISchema; import org.eclipse.pde.internal.core.ischema.ISchemaAttribute; import org.eclipse.pde.internal.core.ischema.ISchemaCompositor; @@ -26,8 +29,6 @@ import org.eclipse.pde.internal.ui.editor.PDEFormPage; import org.eclipse.pde.internal.ui.editor.PDEMasterDetailsBlock; import org.eclipse.pde.internal.ui.editor.PDESection; -import org.eclipse.pde.internal.ui.editor.text.ColorManager; -import org.eclipse.pde.internal.ui.editor.text.IColorManager; import org.eclipse.pde.internal.ui.search.ShowDescriptionAction; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Composite; @@ -46,7 +47,6 @@ public static final String PAGE_ID = "form"; //$NON-NLS-1$ private ElementSection fSection; private SchemaBlock fBlock; - private IColorManager fColorManager; private DetailsPart fDetailsPart; private ImageHyperlink fImageHyperlinkPreviewRefDoc; private ShowDescriptionAction fPreviewAction; @@ -67,7 +67,9 @@ detailsPart.registerPage(ISchemaRootElement.class, new SchemaRootElementDetails(fSection)); detailsPart.registerPage(ISchemaElement.class, new SchemaElementDetails(fSection)); detailsPart.registerPage(ISchemaCompositor.class, new SchemaCompositorDetails(fSection)); - detailsPart.registerPage(ISchemaAttribute.class, new SchemaAttributeDetails(fSection)); + detailsPart.registerPage(SchemaStringAttributeDetails.class, new SchemaStringAttributeDetails(fSection)); + detailsPart.registerPage(SchemaJavaAttributeDetails.class, new SchemaJavaAttributeDetails(fSection)); + detailsPart.registerPage(SchemaOtherAttributeDetails.class, new SchemaOtherAttributeDetails(fSection)); detailsPart.setPageProvider(this); } public Object getPageKey(Object object) { @@ -79,8 +81,20 @@ return ISchemaElement.class; else if (object instanceof ISchemaCompositor) return ISchemaCompositor.class; - else if (object instanceof ISchemaAttribute) - return ISchemaAttribute.class; + else if (object instanceof ISchemaAttribute) { + ISchemaAttribute att = (ISchemaAttribute) object; + int kind = att.getKind(); + switch (kind) { + case IMetaAttribute.JAVA : + return SchemaJavaAttributeDetails.class; + case IMetaAttribute.STRING : + int typeIndex = Arrays.binarySearch(AbstractSchemaAttributeDetails.TYPES, + att.getType().getName()); + if (typeIndex == AbstractSchemaAttributeDetails.STR_IND) + return SchemaStringAttributeDetails.class; + } + return SchemaOtherAttributeDetails.class; + } else return null; } @@ -93,7 +107,6 @@ public SchemaFormPage(PDEFormEditor editor) { super(editor, PAGE_ID, PDEUIMessages.SchemaEditor_FormPage_title); fBlock = new SchemaBlock(); - fColorManager = ColorManager.getDefault(); } /* (non-Javadoc) @@ -114,8 +127,6 @@ super.createFormContent(managedForm); fBlock.createContent(managedForm); - DescriptionSection descSection = new DescriptionSection(this, form.getBody(), fColorManager); - managedForm.addPart(descSection); PlatformUI.getWorkbench().getHelpSystem().setHelp(form.getBody(), IHelpContextIds.SCHEMA_EDITOR_MAIN); initialize(); } @@ -209,7 +220,6 @@ public void dispose() { ISchema schema = (ISchema) getModel(); if (schema != null) schema.removeModelChangedListener(this); - fColorManager.dispose(); super.dispose(); } Index: src/org/eclipse/pde/internal/ui/pderesources.properties =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/pderesources.properties,v retrieving revision 1.890 diff -u -r1.890 pderesources.properties --- src/org/eclipse/pde/internal/ui/pderesources.properties 17 Jul 2007 18:41:33 -0000 1.890 +++ src/org/eclipse/pde/internal/ui/pderesources.properties 18 Jul 2007 18:47:14 -0000 @@ -345,8 +345,6 @@ ###### Schema Editor ################################## SchemaEditorContributor_previewAction = Preview &Reference Document -SchemaEditor_DescriptionSection_title = Description -SchemaEditor_DescriptionSection_desc = Add short description of elements and attributes for documentation purposes. Use HTML tags where appropriate. SchemaEditor_previewLink = Preview Reference Document SchemaAttributeDetails_addRestButton=Add... SchemaRootElementDetails_replacement=Replacement: @@ -768,6 +766,7 @@ AbstractSchemaDetails_maxOccurLabel=Max Occurrences: AbstractLauncherToolbar_noSelection=No {0} are selected. AbstractSchemaDetails_unboundedButton=Unbounded +AbstractSchemaDetails_descriptionLabel=Description: BuildAction_Validate = Validating... BuildAction_Generate = Generating the build script... Index: src/org/eclipse/pde/internal/ui/PDEUIMessages.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/PDEUIMessages.java,v retrieving revision 1.299 diff -u -r1.299 PDEUIMessages.java --- src/org/eclipse/pde/internal/ui/PDEUIMessages.java 17 Jul 2007 15:46:10 -0000 1.299 +++ src/org/eclipse/pde/internal/ui/PDEUIMessages.java 18 Jul 2007 18:47:14 -0000 @@ -19,6 +19,8 @@ public static String AbstractLauncherToolbar_noSelection; + public static String AbstractSchemaDetails_descriptionLabel; + public static String AbstractTargetPage_setTarget; public static String AddLibraryDialog_nospaces; @@ -964,9 +966,6 @@ // Schema Editor ################################## public static String SchemaEditorContributor_previewAction; public static String SchemaEditor_previewLink; - - public static String SchemaEditor_DescriptionSection_title; - public static String SchemaEditor_DescriptionSection_desc; public static String SchemaEditor_DocSection_desc; public static String SchemaEditor_topic_overview; Index: src/org/eclipse/pde/internal/ui/editor/cheatsheet/comp/details/CompCSEnclosingTextDetails.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/cheatsheet/comp/details/CompCSEnclosingTextDetails.java,v retrieving revision 1.14 diff -u -r1.14 CompCSEnclosingTextDetails.java --- src/org/eclipse/pde/internal/ui/editor/cheatsheet/comp/details/CompCSEnclosingTextDetails.java 8 Jun 2007 16:47:59 -0000 1.14 +++ src/org/eclipse/pde/internal/ui/editor/cheatsheet/comp/details/CompCSEnclosingTextDetails.java 18 Jul 2007 18:47:14 -0000 @@ -21,9 +21,9 @@ import org.eclipse.pde.internal.ui.PDEPluginImages; import org.eclipse.pde.internal.ui.PDEUIMessages; import org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractSubDetails; -import org.eclipse.pde.internal.ui.editor.cheatsheet.CSSourceViewer; import org.eclipse.pde.internal.ui.editor.cheatsheet.ICSMaster; import org.eclipse.pde.internal.ui.editor.cheatsheet.comp.CompCSInputContext; +import org.eclipse.pde.internal.ui.parts.PDESourceViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.CTabFolder; import org.eclipse.swt.custom.CTabItem; @@ -52,9 +52,9 @@ private Section fEnclosingTextSection; - private CSSourceViewer fIntroductionViewer; + private PDESourceViewer fIntroductionViewer; - private CSSourceViewer fConclusionViewer; + private PDESourceViewer fConclusionViewer; private CTabFolder fTabFolder; @@ -241,7 +241,7 @@ GridData data = new GridData(GridData.FILL_HORIZONTAL); label.setLayoutData(data); // Create the source viewer - fIntroductionViewer = new CSSourceViewer(getPage()); + fIntroductionViewer = new PDESourceViewer(getPage()); fIntroductionViewer.createUI(fIntroductionComposite, 60, 60); // Note: Must paint border for parent composite; otherwise, the border // goes missing on the text widget when using the Windows XP Classic @@ -256,7 +256,7 @@ // Determine which tab is selected int index = fTabFolder.getSelectionIndex(); // Do the global action on the source viewer on that tab - CSSourceViewer viewer = null; + PDESourceViewer viewer = null; if (index == F_INTRODUCTION_TAB) { viewer = fIntroductionViewer; @@ -282,7 +282,7 @@ GridData data = new GridData(GridData.FILL_HORIZONTAL); label.setLayoutData(data); // Create the source viewer - fConclusionViewer = new CSSourceViewer(getPage()); + fConclusionViewer = new PDESourceViewer(getPage()); fConclusionViewer.createUI(fConclusionComposite, 60, 60); // Note: Must paint border for parent composite; otherwise, the border // goes missing on the text widget when using the Windows XP Classic @@ -453,7 +453,7 @@ // Determine which tab is selected int index = fTabFolder.getSelectionIndex(); // Check if the source viewer on that tab can paste - CSSourceViewer viewer = null; + PDESourceViewer viewer = null; if (index == F_INTRODUCTION_TAB) { viewer = fIntroductionViewer; Index: src/org/eclipse/pde/internal/ui/editor/cheatsheet/simple/details/SimpleCSItemDetails.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/cheatsheet/simple/details/SimpleCSItemDetails.java,v retrieving revision 1.29 diff -u -r1.29 SimpleCSItemDetails.java --- src/org/eclipse/pde/internal/ui/editor/cheatsheet/simple/details/SimpleCSItemDetails.java 8 Jun 2007 16:47:59 -0000 1.29 +++ src/org/eclipse/pde/internal/ui/editor/cheatsheet/simple/details/SimpleCSItemDetails.java 18 Jul 2007 18:47:14 -0000 @@ -22,9 +22,9 @@ import org.eclipse.pde.internal.ui.editor.FormEntryAdapter; import org.eclipse.pde.internal.ui.editor.FormLayoutFactory; import org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails; -import org.eclipse.pde.internal.ui.editor.cheatsheet.CSSourceViewer; import org.eclipse.pde.internal.ui.editor.cheatsheet.ICSMaster; import org.eclipse.pde.internal.ui.editor.cheatsheet.simple.SimpleCSInputContext; +import org.eclipse.pde.internal.ui.parts.PDESourceViewer; import org.eclipse.pde.internal.ui.parts.FormEntry; import org.eclipse.swt.SWT; import org.eclipse.swt.dnd.Clipboard; @@ -53,7 +53,7 @@ private Button fSkip; - private CSSourceViewer fContentViewer; + private PDESourceViewer fContentViewer; private Section fMainSection; @@ -171,7 +171,7 @@ data = new GridData(style); label.setLayoutData(data); // Create the source viewer - fContentViewer = new CSSourceViewer(getPage()); + fContentViewer = new PDESourceViewer(getPage()); fContentViewer.createUI(parent, 90, 60); // Needed to align vertically with form entry field and allow space // for a possible field decoration Index: src/org/eclipse/pde/internal/ui/editor/cheatsheet/simple/details/SimpleCSIntroDetails.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.pde.ui/src/org/eclipse/pde/internal/ui/editor/cheatsheet/simple/details/SimpleCSIntroDetails.java,v retrieving revision 1.17 diff -u -r1.17 SimpleCSIntroDetails.java --- src/org/eclipse/pde/internal/ui/editor/cheatsheet/simple/details/SimpleCSIntroDetails.java 8 Jun 2007 16:48:00 -0000 1.17 +++ src/org/eclipse/pde/internal/ui/editor/cheatsheet/simple/details/SimpleCSIntroDetails.java 18 Jul 2007 18:47:14 -0000 @@ -19,9 +19,9 @@ import org.eclipse.pde.internal.ui.PDEUIMessages; import org.eclipse.pde.internal.ui.editor.FormLayoutFactory; import org.eclipse.pde.internal.ui.editor.cheatsheet.CSAbstractDetails; -import org.eclipse.pde.internal.ui.editor.cheatsheet.CSSourceViewer; import org.eclipse.pde.internal.ui.editor.cheatsheet.ICSMaster; import org.eclipse.pde.internal.ui.editor.cheatsheet.simple.SimpleCSInputContext; +import org.eclipse.pde.internal.ui.parts.PDESourceViewer; import org.eclipse.swt.SWT; import org.eclipse.swt.dnd.Clipboard; import org.eclipse.swt.graphics.Color; @@ -42,7 +42,7 @@ private ISimpleCSIntro fIntro; - private CSSourceViewer fContentViewer; + private PDESourceViewer fContentViewer; private Section fMainSection; @@ -155,7 +155,7 @@ data = new GridData(style); label.setLayoutData(data); // Create the source viewer - fContentViewer = new CSSourceViewer(getPage()); + fContentViewer = new PDESourceViewer(getPage()); fContentViewer.createUI(parent, 90, 60); // Needed to align vertically with form entry field and allow space // for a possible field decoration Index: src/org/eclipse/pde/internal/ui/editor/schema/SchemaJavaAttributeDetails.java =================================================================== RCS file: src/org/eclipse/pde/internal/ui/editor/schema/SchemaJavaAttributeDetails.java diff -N src/org/eclipse/pde/internal/ui/editor/schema/SchemaJavaAttributeDetails.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/pde/internal/ui/editor/schema/SchemaJavaAttributeDetails.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,194 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.pde.internal.ui.editor.schema; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jdt.core.IJavaElement; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.IType; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jdt.core.search.SearchEngine; +import org.eclipse.jdt.ui.IJavaElementSearchConstants; +import org.eclipse.jdt.ui.JavaUI; +import org.eclipse.jface.window.Window; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.pde.internal.core.ischema.ISchemaObject; +import org.eclipse.pde.internal.core.schema.SchemaAttribute; +import org.eclipse.pde.internal.ui.PDEPlugin; +import org.eclipse.pde.internal.ui.PDEUIMessages; +import org.eclipse.pde.internal.ui.editor.FormEntryAdapter; +import org.eclipse.pde.internal.ui.parts.FormEntry; +import org.eclipse.pde.internal.ui.util.SWTUtil; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.IActionBars; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.dialogs.SelectionDialog; +import org.eclipse.ui.forms.events.HyperlinkEvent; +import org.eclipse.ui.forms.widgets.FormToolkit; + +public class SchemaJavaAttributeDetails extends AbstractSchemaAttributeDetails { + private FormEntry fClassEntry; + private FormEntry fInterfaceEntry; + + public SchemaJavaAttributeDetails(ElementSection section) { + super(section); + } + + protected void createTypeDetails(Composite parent, FormToolkit toolkit) { + fClassEntry = new FormEntry(parent, toolkit, PDEUIMessages.SchemaAttributeDetails_extends, PDEUIMessages.SchemaAttributeDetails_browseButton, isEditable(), 13); + fInterfaceEntry = new FormEntry(parent, toolkit, PDEUIMessages.SchemaAttributeDetails_implements, PDEUIMessages.SchemaAttributeDetails_browseButton, isEditable(), 13); + } + + public void updateFields(ISchemaObject object) { + if (!(object instanceof SchemaAttribute)) + return; + super.updateFields(object); + + String basedOn = getAttribute().getBasedOn(); + if ((basedOn != null) && + (basedOn.length() > 0)) { + int index = basedOn.indexOf(":"); //$NON-NLS-1$ + if (index == -1) { + String className = + basedOn.substring(basedOn.lastIndexOf(".") + 1); //$NON-NLS-1$ + if ((className.length() > 1) && + (className.charAt(0) == 'I')) { + fClassEntry.setValue("", true); //$NON-NLS-1$ + fInterfaceEntry.setValue(basedOn, true); + } else { + fClassEntry.setValue(basedOn, true); + fInterfaceEntry.setValue("", true); //$NON-NLS-1$ + } + } else { + fClassEntry.setValue(basedOn.substring(0, index), true); + fInterfaceEntry.setValue(basedOn.substring(index + 1), true); + } + } else { + fClassEntry.setValue("", true); //$NON-NLS-1$ + fInterfaceEntry.setValue("", true); //$NON-NLS-1$ + } + + boolean editable = isEditableElement(); + fClassEntry.setEditable(editable); + fInterfaceEntry.setEditable(editable); + } + + public void hookListeners() { + super.hookListeners(); + IActionBars actionBars = getPage().getPDEEditor().getEditorSite().getActionBars(); + fClassEntry.setFormEntryListener(new FormEntryAdapter(this, actionBars) { + public void textValueChanged(FormEntry entry) { + if (blockListeners()) + return; + setBasedOn(); + } + public void linkActivated(HyperlinkEvent e) { + if (blockListeners()) + return; + String value = fClassEntry.getValue(); + value = handleLinkActivated(value, false); + if (value != null) + fClassEntry.setValue(value); + } + public void browseButtonSelected(FormEntry entry) { + if (blockListeners()) + return; + doOpenSelectionDialog( + IJavaElementSearchConstants.CONSIDER_CLASSES, fClassEntry); + } + }); + fInterfaceEntry.setFormEntryListener(new FormEntryAdapter(this, actionBars) { + public void textValueChanged(FormEntry entry) { + if (blockListeners()) + return; + setBasedOn(); + } + public void linkActivated(HyperlinkEvent e) { + if (blockListeners()) + return; + String value = fInterfaceEntry.getValue(); + value = handleLinkActivated(value, true); + if (value != null) + fInterfaceEntry.setValue(value); + } + public void browseButtonSelected(FormEntry entry) { + if (blockListeners()) + return; + doOpenSelectionDialog( + IJavaElementSearchConstants.CONSIDER_INTERFACES, fInterfaceEntry); + } + }); + } + + private String handleLinkActivated(String value, boolean isInter) { + IProject project = getPage().getPDEEditor().getCommonProject(); + try { + if (project != null && project.hasNature(JavaCore.NATURE_ID)) { + IJavaProject javaProject = JavaCore.create(project); + IJavaElement element = javaProject.findType(value.replace('$', '.')); + if (element != null) + JavaUI.openInEditor(element); + else { + NewClassCreationWizard wizard = new NewClassCreationWizard(project, isInter, value); + WizardDialog dialog = new WizardDialog(PDEPlugin.getActiveWorkbenchShell(), wizard); + dialog.create(); + SWTUtil.setDialogSize(dialog, 400, 500); + if (dialog.open() == Window.OK) { + return wizard.getQualifiedName(); + } + } + } + } catch (PartInitException e1) { + } catch (CoreException e1) { + } + return null; + } + + private void setBasedOn() { + String classEntry = fClassEntry.getValue().replaceAll(":", ""); //$NON-NLS-1$ //$NON-NLS-2$ + String interfaceEntry = fInterfaceEntry.getValue().replaceAll(":", ""); //$NON-NLS-1$ //$NON-NLS-2$ + StringBuffer sb = new StringBuffer(); + if (classEntry.length() > 0) + sb.append(classEntry); + if (classEntry.length() > 0 || interfaceEntry.length() > 0) + sb.append(":"); //$NON-NLS-1$ + if (interfaceEntry.length() > 0) + sb.append(interfaceEntry); + getAttribute().setBasedOn(sb.length() > 0 ? sb.toString() : null); + } + + private void doOpenSelectionDialog(int scopeType, FormEntry entry) { + try { + String filter = entry.getValue(); + filter = filter.substring(filter.lastIndexOf(".") + 1); //$NON-NLS-1$ + SelectionDialog dialog = JavaUI.createTypeDialog( + PDEPlugin.getActiveWorkbenchShell(), + PlatformUI.getWorkbench().getProgressService(), + SearchEngine.createWorkspaceScope(), scopeType, false, filter); //$NON-NLS-1$ + dialog.setTitle(PDEUIMessages.GeneralInfoSection_selectionTitle); + if (dialog.open() == Window.OK) { + IType type = (IType) dialog.getResult()[0]; + entry.setValue(type.getFullyQualifiedName('$')); + entry.commit(); + } + } catch (CoreException e) { + } + } + + public void commit(boolean onSave) { + super.commit(onSave); + // Only required for form entries + fClassEntry.commit(); + fInterfaceEntry.commit(); + } +} Index: src/org/eclipse/pde/internal/ui/editor/schema/SchemaStringAttributeDetails.java =================================================================== RCS file: src/org/eclipse/pde/internal/ui/editor/schema/SchemaStringAttributeDetails.java diff -N src/org/eclipse/pde/internal/ui/editor/schema/SchemaStringAttributeDetails.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/pde/internal/ui/editor/schema/SchemaStringAttributeDetails.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,192 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.pde.internal.ui.editor.schema; + +import java.util.Vector; + +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.LabelProvider; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.window.Window; +import org.eclipse.pde.internal.core.ischema.ISchemaObject; +import org.eclipse.pde.internal.core.ischema.ISchemaSimpleType; +import org.eclipse.pde.internal.core.schema.ChoiceRestriction; +import org.eclipse.pde.internal.core.schema.SchemaAttribute; +import org.eclipse.pde.internal.core.schema.SchemaEnumeration; +import org.eclipse.pde.internal.core.schema.SchemaSimpleType; +import org.eclipse.pde.internal.ui.PDEUIMessages; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Table; +import org.eclipse.ui.forms.IFormColors; +import org.eclipse.ui.forms.widgets.FormToolkit; + +public class SchemaStringAttributeDetails extends AbstractSchemaAttributeDetails { + private Button fTransTrue; + private Button fTransFalse; + private TableViewer fRestrictionsTable; + private Button fAddRestriction; + private Button fRemoveRestriction; + + public SchemaStringAttributeDetails(ElementSection section) { + super(section); + } + + protected void createTypeDetails(Composite parent, FormToolkit toolkit) { + Color foreground = toolkit.getColors().getColor(IFormColors.TITLE); + + Label label = toolkit.createLabel(parent, PDEUIMessages.SchemaDetails_translatable); + label.setForeground(foreground); + GridData gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); + gd.horizontalIndent = 11; + gd.verticalIndent = 2; + label.setLayoutData(gd); + Button[] buttons = createTrueFalseButtons(parent, toolkit, 2); + fTransTrue = buttons[0]; + fTransFalse = buttons[1]; + + label = toolkit.createLabel(parent, PDEUIMessages.SchemaAttributeDetails_restrictions); + label.setForeground(foreground); + gd = new GridData(GridData.VERTICAL_ALIGN_BEGINNING); + gd.horizontalIndent = 11; + gd.verticalIndent = 2; + label.setLayoutData(gd); + + Composite tableComp = toolkit.createComposite(parent); + GridLayout layout = new GridLayout(); layout.marginHeight = layout.marginWidth = 0; + tableComp.setLayout(layout); + tableComp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + + Table table = toolkit.createTable(tableComp, SWT.BORDER | SWT.MULTI | SWT.V_SCROLL); + gd = new GridData(GridData.FILL_HORIZONTAL); + gd.heightHint = 40; + table.setLayoutData(gd); + fRestrictionsTable = new TableViewer(table); + fRestrictionsTable.setContentProvider(new SchemaAttributeContentProvider()); + fRestrictionsTable.setLabelProvider(new LabelProvider()); + + Composite resButtonComp = toolkit.createComposite(parent); + layout = new GridLayout(); layout.marginHeight = layout.marginWidth = 0; + resButtonComp.setLayout(layout); + resButtonComp.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING)); + fAddRestriction = toolkit.createButton(resButtonComp, PDEUIMessages.SchemaAttributeDetails_addRestButton, SWT.NONE); + fRemoveRestriction = toolkit.createButton(resButtonComp, PDEUIMessages.SchemaAttributeDetails_removeRestButton, SWT.NONE); + fAddRestriction.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + fRemoveRestriction.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + } + + public void updateFields(ISchemaObject object) { + if (!(object instanceof SchemaAttribute)) + return; + super.updateFields(object); + + fTransTrue.setSelection(getAttribute().isTranslatable()); + fTransFalse.setSelection(!getAttribute().isTranslatable()); + fRestrictionsTable.setInput(new Object()); + + boolean editable = isEditableElement(); + fTransTrue.setEnabled(editable); + fTransFalse.setEnabled(editable); + fRestrictionsTable.getControl().setEnabled(editable); + fAddRestriction.setEnabled(editable); + fRemoveRestriction.setEnabled( + !fRestrictionsTable.getSelection().isEmpty() && editable); + } + + public void hookListeners() { + super.hookListeners(); + fTransTrue.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + if (blockListeners()) + return; + getAttribute().setTranslatableProperty(fTransTrue.getSelection()); + } + }); + fAddRestriction.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + if (blockListeners()) + return; + NewRestrictionDialog dialog = new NewRestrictionDialog(getPage().getSite().getShell()); + if (dialog.open() != Window.OK) return; + String text = dialog.getNewRestriction(); + if (text != null && text.length() > 0) { + ISchemaSimpleType type = getAttribute().getType(); + ChoiceRestriction res = (ChoiceRestriction)type.getRestriction(); + Vector vres = new Vector(); + if (res != null) { + Object[] currRes = res.getChildren(); + for (int i = 0; i < currRes.length; i++) { + vres.add(currRes[i]); + } + } + vres.add(new SchemaEnumeration(getAttribute().getSchema(), text)); + if (res == null) + res = new ChoiceRestriction(getAttribute().getSchema()); + res.setChildren(vres); + if (type instanceof SchemaSimpleType) + ((SchemaSimpleType)type).setRestriction(res); + fRestrictionsTable.refresh(); + } + } + }); + fRemoveRestriction.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + if (blockListeners()) + return; + ISelection selection = fRestrictionsTable.getSelection(); + if (selection.isEmpty()) return; + if (!(selection instanceof IStructuredSelection)) return; + IStructuredSelection sselection = (IStructuredSelection)selection; + Object[] aselection = sselection.toArray(); + ISchemaSimpleType type = getAttribute().getType(); + ChoiceRestriction res = (ChoiceRestriction)type.getRestriction(); + Vector vres = new Vector(); + if (res != null) { + Object[] currRes = res.getChildren(); + for (int i = 0; i < currRes.length; i++) { + boolean stays = true; + for (int j = 0; j < aselection.length; j++) { + if (currRes[i].equals(aselection[j])) + stays = false; + } + if (stays) vres.add(currRes[i]); + } + res.setChildren(vres); + if (type instanceof SchemaSimpleType) { + if (vres.size() == 0) + ((SchemaSimpleType)type).setRestriction(null); + else + ((SchemaSimpleType)type).setRestriction(res); + } + fRestrictionsTable.refresh(); + } + } + }); + fRestrictionsTable.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + if (blockListeners()) + return; + fRemoveRestriction.setEnabled(getAttribute().getSchema().isEditable() + && !event.getSelection().isEmpty()); + } + }); + } +} Index: src/org/eclipse/pde/internal/ui/editor/schema/SchemaOtherAttributeDetails.java =================================================================== RCS file: src/org/eclipse/pde/internal/ui/editor/schema/SchemaOtherAttributeDetails.java diff -N src/org/eclipse/pde/internal/ui/editor/schema/SchemaOtherAttributeDetails.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/pde/internal/ui/editor/schema/SchemaOtherAttributeDetails.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,25 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.pde.internal.ui.editor.schema; + +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.forms.widgets.FormToolkit; + +public class SchemaOtherAttributeDetails extends AbstractSchemaAttributeDetails { + + public SchemaOtherAttributeDetails(ElementSection section) { + super(section); + } + + protected void createTypeDetails(Composite parent, FormToolkit toolkit) { + } + +} Index: src/org/eclipse/pde/internal/ui/editor/schema/AbstractSchemaAttributeDetails.java =================================================================== RCS file: src/org/eclipse/pde/internal/ui/editor/schema/AbstractSchemaAttributeDetails.java diff -N src/org/eclipse/pde/internal/ui/editor/schema/AbstractSchemaAttributeDetails.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/pde/internal/ui/editor/schema/AbstractSchemaAttributeDetails.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,232 @@ +/******************************************************************************* + * Copyright (c) 2000, 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.pde.internal.ui.editor.schema; +import org.eclipse.osgi.util.NLS; +import org.eclipse.pde.core.IModelChangedEvent; +import org.eclipse.pde.internal.core.ischema.IMetaAttribute; +import org.eclipse.pde.internal.core.ischema.ISchemaObject; +import org.eclipse.pde.internal.core.ischema.ISchemaRestriction; +import org.eclipse.pde.internal.core.ischema.ISchemaSimpleType; +import org.eclipse.pde.internal.core.schema.SchemaAttribute; +import org.eclipse.pde.internal.core.schema.SchemaSimpleType; +import org.eclipse.pde.internal.ui.PDEUIMessages; +import org.eclipse.pde.internal.ui.editor.FormEntryAdapter; +import org.eclipse.pde.internal.ui.elements.DefaultTableProvider; +import org.eclipse.pde.internal.ui.parts.ComboPart; +import org.eclipse.pde.internal.ui.parts.FormEntry; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.forms.IFormColors; +import org.eclipse.ui.forms.widgets.FormToolkit; + +public abstract class AbstractSchemaAttributeDetails extends AbstractSchemaDetails { + + private static final String JAVA_TYPE = "java"; //$NON-NLS-1$ + private static final String RESOURCE_TYPE = "resource"; //$NON-NLS-1$ + protected static final int BOOL_IND = 0; + protected static final int STR_IND = 1; + protected static final int JAVA_IND = 2; + protected static final int RES_IND = 3; + protected static final String[] TYPES = new String[4]; + static { + TYPES[BOOL_IND]= BOOLEAN_TYPE; + TYPES[STR_IND] = STRING_TYPE; + TYPES[JAVA_IND] = JAVA_TYPE; + TYPES[RES_IND] = RESOURCE_TYPE; + } + private static final String[] USE = + new String[] {"optional", "required", "default"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + private SchemaAttribute fAttribute; + private FormEntry fValue; + private FormEntry fName; + private Button fDepTrue; + private Button fDepFalse; + private ComboPart fType; + private ComboPart fUse; + + public AbstractSchemaAttributeDetails(ElementSection section) { + super(section, false, true); + } + + class SchemaAttributeContentProvider extends DefaultTableProvider { + public Object[] getElements(Object inputElement) { + ISchemaSimpleType type = fAttribute.getType(); + ISchemaRestriction restriction = type.getRestriction(); + if (restriction != null) + return restriction.getChildren(); + return new Object[0]; + } + } + + public void createDetails(Composite parent) { + FormToolkit toolkit = getManagedForm().getToolkit(); + Color foreground = toolkit.getColors().getColor(IFormColors.TITLE); + + fName = new FormEntry(parent, toolkit, PDEUIMessages.SchemaDetails_name, SWT.NONE); + + Label label = toolkit.createLabel(parent, PDEUIMessages.SchemaDetails_deprecated); + label.setForeground(foreground); + Button[] buttons = createTrueFalseButtons(parent, toolkit, 2); + fDepTrue = buttons[0]; + fDepFalse = buttons[1]; + + label = toolkit.createLabel(parent, PDEUIMessages.SchemaAttributeDetails_type); + label.setForeground(foreground); + fType = createComboPart(parent, toolkit, TYPES, 2); + + createTypeDetails(parent, toolkit); + + label = toolkit.createLabel(parent, PDEUIMessages.SchemaAttributeDetails_use); + label.setForeground(foreground); + fUse = createComboPart(parent, toolkit, USE, 2); + + fValue = new FormEntry(parent, toolkit, PDEUIMessages.SchemaAttributeDetails_defaultValue, null, false, 6); + +// fBooleanTypeComp = createEmptyComposite(fNotebook, toolkit); +// fStringTypeComp = createStringTypeComp(fNotebook, toolkit, foreground); +// fJavaTypeComp = createJavaTypeComp(fNotebook, toolkit, foreground); +// fResourceTypeComp = createEmptyComposite(fNotebook, toolkit); + + toolkit.paintBordersFor(parent); + setText(PDEUIMessages.SchemaAttributeDetails_title); + } + + protected abstract void createTypeDetails(Composite parent, FormToolkit toolkit); + + public void updateFields(ISchemaObject object) { + if (!(object instanceof SchemaAttribute)) + return; + fAttribute = (SchemaAttribute)object; + setDecription(NLS.bind(PDEUIMessages.SchemaAttributeDetails_description, fAttribute.getName())); + fName.setValue(fAttribute.getName(), true); //$NON-NLS-1$ + fDepTrue.setSelection(fAttribute.isDeprecated()); + fDepFalse.setSelection(!fAttribute.isDeprecated()); + + boolean isStringType = fAttribute.getType().getName().equals(STRING_TYPE); + int kind = fAttribute.getKind(); + fType.select(isStringType ? 1 + kind : 0); + + fUse.select(fAttribute.getUse()); + Object value = fAttribute.getValue(); + fValue.setValue(value != null ? value.toString() : "", true); //$NON-NLS-1$ + + boolean editable = isEditableElement(); + if (fAttribute.getUse() != 2) { + fValue.getLabel().setEnabled(false); + fValue.getText().setEditable(false); + } else { + fValue.setEditable(editable); + } + fName.setEditable(editable); + fDepTrue.setEnabled(editable); + fDepFalse.setEnabled(editable); + fType.setEnabled(editable); + fUse.setEnabled(editable); + } + + public void hookListeners() { + fValue.setFormEntryListener(new FormEntryAdapter(this) { + public void textValueChanged(FormEntry entry) { + if (blockListeners()) + return; + fAttribute.setValue(fValue.getValue()); + } + }); + fName.setFormEntryListener(new FormEntryAdapter(this) { + public void textValueChanged(FormEntry entry) { + if (blockListeners()) + return; + if (fName.getValue().length() != 0) { + fAttribute.setName(fName.getValue()); + setDecription(NLS.bind(PDEUIMessages.SchemaAttributeDetails_description, fAttribute.getName())); + } else { + fName.setValue(fAttribute.getName(), true); + } + } + }); + fDepTrue.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + if (blockListeners()) + return; + fAttribute.setDeprecatedProperty(fDepTrue.getSelection()); + } + }); + fType.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + if (blockListeners()) + return; + String typeString = fType.getSelection(); + if (!typeString.equals(BOOLEAN_TYPE)) + typeString = STRING_TYPE; + + fAttribute.setType(new SchemaSimpleType(fAttribute.getSchema(), typeString)); + + int kind = fType.getSelectionIndex() - 1; // adjust for "boolean" in combo + fAttribute.setKind(kind > 0 ? kind : 0); // kind could be -1 + + ISchemaSimpleType type = fAttribute.getType(); + if (type instanceof SchemaSimpleType + && kind != IMetaAttribute.STRING + && ((SchemaSimpleType) type).getRestriction() != null) { + ((SchemaSimpleType) type).setRestriction(null); + } + fireSelectionChange(); + } + }); + fUse.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent e) { + if (blockListeners()) + return; + int use = fUse.getSelectionIndex(); + fAttribute.setUse(use); + fValue.getLabel().setEnabled(use == 2); + fValue.getText().setEditable(use == 2); + if (use == 2 && fValue.getValue().length() == 0) { + fValue.setValue(PDEUIMessages.SchemaAttributeDetails_defaultDefaultValue); + fValue.getText().setSelection(0, fValue.getValue().length()); + fValue.getText().setFocus(); + } else if (use != 2) + fValue.setValue(""); //$NON-NLS-1$ + + } + }); + } + + public void modelChanged(IModelChangedEvent event) { + Object[] changedObjs = event.getChangedObjects(); + if(event.getChangeType() == IModelChangedEvent.INSERT && changedObjs.length > 0) { + if(changedObjs[0] instanceof SchemaAttribute) { + fName.getText().setFocus(); + } + } + super.modelChanged(event); + } + + /* (non-Javadoc) + * @see org.eclipse.ui.forms.AbstractFormPart#commit(boolean) + */ + public void commit(boolean onSave) { + super.commit(onSave); + // Only required for form entries + fName.commit(); + fValue.commit(); + } + + protected SchemaAttribute getAttribute() { + return fAttribute; + } +} Index: src/org/eclipse/pde/internal/ui/parts/PDESourceViewer.java =================================================================== RCS file: src/org/eclipse/pde/internal/ui/parts/PDESourceViewer.java diff -N src/org/eclipse/pde/internal/ui/parts/PDESourceViewer.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ src/org/eclipse/pde/internal/ui/parts/PDESourceViewer.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,265 @@ +/******************************************************************************* + * Copyright (c) 2007 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.pde.internal.ui.parts; + +import org.eclipse.core.filebuffers.IDocumentSetupParticipant; +import org.eclipse.jface.text.Document; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.ITextOperationTarget; +import org.eclipse.jface.text.source.SourceViewer; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.pde.internal.ui.editor.PDEFormPage; +import org.eclipse.pde.internal.ui.editor.context.XMLDocumentSetupParticpant; +import org.eclipse.pde.internal.ui.editor.text.ColorManager; +import org.eclipse.pde.internal.ui.editor.text.IColorManager; +import org.eclipse.pde.internal.ui.editor.text.XMLConfiguration; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.FocusAdapter; +import org.eclipse.swt.events.FocusEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.ui.actions.ActionFactory; +import org.eclipse.ui.forms.widgets.FormToolkit; + +/** + * CSSourceViewerFactory + * + */ +public class PDESourceViewer { + + private static XMLConfiguration fSourceConfiguration = null; + + private static IColorManager fColorManager = null; + + private static int fSourceViewerCount = 0; + + private SourceViewer fViewer; + + private PDEFormPage fPage; + + private IDocument fDocument; + + /** + * @param page + */ + public PDESourceViewer(PDEFormPage page) { + // Create the underlying document + fDocument = new Document(); + fPage = page; + } + + /** + * @return + */ + public IDocument getDocument() { + return fDocument; + } + + /** + * @return + */ + public SourceViewer getViewer() { + return fViewer; + } + + /** + * @return + */ + private XMLConfiguration getConfiguration() { + if (fSourceConfiguration == null) { + // Get the color manager + fColorManager = ColorManager.getDefault(); + // Create the source configuration + fSourceConfiguration = new XMLConfiguration(fColorManager); + } + return fSourceConfiguration; + } + + /** + * Utility method for creating a field for syntax highlighting + * @param parent + * @param heightHint + * @param widthHint + */ + public void createUI(Composite parent, int heightHint, int widthHint) { + GridData data = new GridData(GridData.FILL_HORIZONTAL); + data.heightHint = heightHint; + data.widthHint = widthHint; + createUI(parent, data); + } + + public void createUI(Composite parent, GridData data) { + // Create the source viewer + int style = SWT.MULTI | SWT.WRAP | SWT.V_SCROLL; + fViewer = new SourceViewer(parent, null, style); + // Configure the source viewer + fViewer.configure(getConfiguration()); + // Setup the underlying document + IDocumentSetupParticipant participant = new XMLDocumentSetupParticpant(); + participant.setup(fDocument); + // Set the document on the source viewer + fViewer.setDocument(fDocument); + // Configure the underlying styled text widget + configureUIStyledText(data, fViewer.getTextWidget()); + // Create style text listeners + createUIListenersStyledText(fViewer.getTextWidget()); + } + + /** + * + */ + public void createUIListeners() { + // Ensure the viewer was created + if (fViewer == null) { + return; + } + // Create source viewer listeners + // Create selection listener + fViewer.addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + fPage.getPDEEditor().setSelection(event.getSelection()); + } + }); + // Create focus listener + fViewer.getTextWidget().addFocusListener(new FocusAdapter() { + public void focusGained(FocusEvent e) { + fPage.getPDEEditor().getContributor().updateSelectableActions(null); + } + }); + } + + /** + * @param textWidget + */ + private void createUIListenersStyledText(StyledText textWidget) { + // Track the number of source viewers created + fSourceViewerCount++; + // The color manager and source viewer configuration should be disposed + // When the last source viewer is diposed, dispose of the color manager + // and source viewer configuration + textWidget.addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent e) { + fSourceViewerCount--; + if (fSourceViewerCount == 0) { + dispose(); + } + } + }); + } + + /** + * + */ + private void dispose() { + // TODO: MP: CompCS: Profile Sleek when making static to ensure no leaks + // Dispose of the color manager + if (fColorManager != null) { + fColorManager.dispose(); + fColorManager = null; + } + // Dispose of the source configuration + if (fSourceConfiguration != null) { + fSourceConfiguration.dispose(); + fSourceConfiguration = null; + } + } + + /** + * @param heightHint + * @param widthHint + * @param styledText + */ + private void configureUIStyledText(GridData data, StyledText styledText) { + // Configure the underlying styled text widget + styledText.setMenu(fPage.getPDEEditor().getContextMenu()); + // Force borders + styledText.setData(FormToolkit.KEY_DRAW_BORDER, FormToolkit.TEXT_BORDER); + styledText.setLayoutData(data); + } + + /** + * The menu set on the underlying styled text widget of the source viewer + * needs to be set to null before being diposed; otherwise, the menu will + * be disposed along with the widget. + * @param viewer + */ + public void unsetMenu() { + if (fViewer == null) { + return; + } + StyledText styledText = fViewer.getTextWidget(); + if (styledText == null) { + return; + } else if (styledText.isDisposed()) { + return; + } + styledText.setMenu(null); + } + + /** + * Utility method used to tie global actions into source viewers. + * + * @param actionId + * @param viewer + * @return + */ + public boolean doGlobalAction(String actionId) { + // Ensure the viewer was created + if (fViewer == null) { + return false; + } else if (actionId.equals(ActionFactory.CUT.getId())) { + fViewer.doOperation(ITextOperationTarget.CUT); + return true; + } else if ( + actionId.equals(ActionFactory.COPY.getId())) { + fViewer.doOperation(ITextOperationTarget.COPY); + return true; + } else if ( + actionId.equals(ActionFactory.PASTE.getId())) { + fViewer.doOperation(ITextOperationTarget.PASTE); + return true; + } else if ( + actionId.equals(ActionFactory.SELECT_ALL.getId())) { + fViewer.doOperation(ITextOperationTarget.SELECT_ALL); + return true; + } else if ( + actionId.equals(ActionFactory.DELETE.getId())) { + fViewer.doOperation(ITextOperationTarget.DELETE); + return true; + } else if ( + actionId.equals(ActionFactory.UNDO.getId())) { + fViewer.doOperation(ITextOperationTarget.UNDO); + return false; + } else if ( + actionId.equals(ActionFactory.REDO.getId())) { + fViewer.doOperation(ITextOperationTarget.REDO); + return false; + } + return false; + } + + /** + * @param viewer + * @return + */ + public boolean canPaste() { + // Ensure the viewer was created + if (fViewer == null) { + return false; + } + return fViewer.canDoOperation(ITextOperationTarget.PASTE); + } +}