diff options
author | cbateman | 2008-04-23 17:48:37 +0000 |
---|---|---|
committer | cbateman | 2008-04-23 17:48:37 +0000 |
commit | 8019a3bc1927bb564d554ac1a986a2c43e1d528f (patch) | |
tree | b6f7c8f3be8b060f1d6452c7c518ad2fe50f9490 | |
parent | f6b76d91c05049dff510cf04aef79e1a03e7e9e2 (diff) | |
download | webtools.jsf-8019a3bc1927bb564d554ac1a986a2c43e1d528f.tar.gz webtools.jsf-8019a3bc1927bb564d554ac1a986a2c43e1d528f.tar.xz webtools.jsf-8019a3bc1927bb564d554ac1a986a2c43e1d528f.zip |
https://bugs.eclipse.org/bugs/show_bug.cgi?id=224998
7 files changed, 314 insertions, 96 deletions
diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/common/Messages.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/common/Messages.java new file mode 100644 index 000000000..dd5ed4ab9 --- /dev/null +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/common/Messages.java @@ -0,0 +1,38 @@ +package org.eclipse.jst.jsf.ui.internal.common; + +import org.eclipse.osgi.util.NLS; + +/** + * @author cbateman + * + */ +public class Messages extends NLS +{ + private static final String BUNDLE_NAME = "org.eclipse.jst.jsf.ui.internal.common.messages"; //$NON-NLS-1$ + /** + * see messages.properties + */ + public static String ViewObjectPresenter_ComponentClass; + /** + * see messages.properties + */ + public static String ViewObjectPresenter_ComponentFamily; + /** + * see messages.properties + */ + public static String ViewObjectPresenter_ComponentType; + /** + * see messages.properties + */ + public static String ViewObjectPresenter_RenderType; + static + { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() + { + // no instantiation + } +} diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/common/ViewObjectPresenter.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/common/ViewObjectPresenter.java new file mode 100644 index 000000000..a8b40557d --- /dev/null +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/common/ViewObjectPresenter.java @@ -0,0 +1,237 @@ +package org.eclipse.jst.jsf.ui.internal.common; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.jst.jsf.common.runtime.internal.model.IDesigntimeAdapter; +import org.eclipse.jst.jsf.common.runtime.internal.model.component.ComponentInfo; +import org.eclipse.jst.jsf.common.runtime.internal.model.component.ComponentTypeInfo; + +/** + * Generates UI form text strings for certain view objects. + * + * @author cbateman + * + */ +public final class ViewObjectPresenter +{ + /** + * @param typeInfo + * @return a presentation string containing all the summary information for + * a typeInfo. Excludes interfaces and superclasses. + */ + public static String present(final ComponentTypeInfo typeInfo) + { + final String formatText = "<form>%s</form>"; //$NON-NLS-1$ + final String componentType = typeInfo.getComponentType(); + final String componentFamily = typeInfo.getComponentFamily(); + final String renderType = typeInfo.getRenderFamily(); + final String componentClass = typeInfo.getClassName(); + final List<TitleValuePair> values = new ArrayList<TitleValuePair>(); + + values.add(new TitleValuePair(Messages.ViewObjectPresenter_ComponentType, + componentType == null ? "" //$NON-NLS-2$ + : componentType)); + values.add(new TitleValuePair(Messages.ViewObjectPresenter_ComponentClass, + componentClass == null ? "" //$NON-NLS-2$ + : componentClass)); + values.add(new TitleValuePair(Messages.ViewObjectPresenter_ComponentFamily, + componentFamily == null ? "" //$NON-NLS-2$ + : componentFamily)); + values.add(new TitleValuePair(Messages.ViewObjectPresenter_RenderType, + renderType == null ? "" : renderType)); //$NON-NLS-2$ + return String.format(formatText, ViewObjectPresenter.createLines(values)); + } + + /** + * @param compInfo + * @param typeInfo + * @return a presentation string containing all the interfaces in compInfo + * including adapters. + */ + public static String presentCompInterfaces(final ComponentTypeInfo typeInfo, final ComponentInfo compInfo) + { + final Set<String> interfaces = new HashSet<String>(); + + interfaces.addAll(Arrays.asList(typeInfo.getInterfaces())); + + if (compInfo != null) + { + for (final Map.Entry entry : (Set<Map.Entry>) compInfo.getAllAdapters() + .entrySet()) + { + final Object infObject = entry.getValue(); + if (infObject instanceof IDesigntimeAdapter) + { + interfaces.addAll(Arrays.asList(((IDesigntimeAdapter)infObject).getInterfaces())); + } + } + } + final List<String> sortedInterfaceNames = new ArrayList<String>( + interfaces); + Collections.sort(sortedInterfaceNames); + + String text = ""; + for (final String name : sortedInterfaceNames) + { + text += ViewObjectPresenter.createLine(null, name); + } + return String.format("<form>%s</form>", text); + } + + /** + * @param values + * @return a grouping of createLine style lines using the key/value pairs in + * values for the title and value. + */ + public static String createLines(final List<TitleValuePair> values) + { + String lines = ""; //$NON-NLS-1$ + for (final TitleValuePair valueEntry : values) + { + final String title = valueEntry.getTitle(); + final String value = valueEntry.getValue(); + + lines += createLine(title, value); + } + return lines; + } + + /** + * @param title + * may be null + * @param value + * @return a single paragraphed line containing value with title preceding + * in bold if not null + */ + public static String createLine(final String title, final String value) + { + if (title == null) + { + return String.format("<p>%s</p>", value); //$NON-NLS-1$ + } + return String.format("<p><b>%s</b>: %s</p>", title, value); //$NON-NLS-1$ + } + + /** + * A title/value pair. Title may be null. Comparable canonically based title + * (ascending). + * + * @author cbateman + * + */ + public final static class TitleValuePair implements + Comparable<TitleValuePair> + { + private final String _title; + private final String _value; + + /** + * @param title + * @param value + */ + public TitleValuePair(String title, String value) + { + super(); + if (value == null) + { + throw new IllegalArgumentException("Value must not be null"); + } + + _title = title; + _value = value; + } + + /** + * @return the title + */ + protected final String getTitle() + { + return _title; + } + + /** + * @return the value + */ + protected final String getValue() + { + return _value; + } + + public int compareTo(TitleValuePair other) + { + if (this == other) + { + return 0; + } + + if (other == null) + { + return 1; + } + + if (_title == null) + { + return other.getTitle() == null ? 0 : 1; + } + else if (other.getTitle() == null) + { + // _title is not null + return 1; + } + + return _title.compareTo(other.getTitle()); + } + + @Override + public boolean equals(Object obj) + { + if (this == obj) + { + return true; + } + + if (obj instanceof TitleValuePair) + { + + final TitleValuePair other = (TitleValuePair) obj; + final String otherValue = other.getValue(); + + if (!otherValue.equals(_value)) + { + return false; + } + + final String otherTitle = other.getTitle(); + if (_title == null) + { + return otherTitle == null; + } + else if (otherTitle == null) + { + return _title == null; + } + return _title.equals(otherTitle); + } + return false; + } + + @Override + public int hashCode() + { + return getTitle().hashCode(); + } + + + } + + private ViewObjectPresenter() + { + // no instantiation + } +} diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/common/messages.properties b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/common/messages.properties new file mode 100644 index 000000000..a8a4e9e1f --- /dev/null +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/common/messages.properties @@ -0,0 +1,4 @@ +ViewObjectPresenter_ComponentClass=Component Class +ViewObjectPresenter_ComponentFamily=Component Family +ViewObjectPresenter_ComponentType=Component Type +ViewObjectPresenter_RenderType=Render Type diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/component/ComponentInstanceDetailsForm.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/component/ComponentInstanceDetailsForm.java index 03914c062..3d6e1f6e7 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/component/ComponentInstanceDetailsForm.java +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/component/ComponentInstanceDetailsForm.java @@ -1,17 +1,14 @@ package org.eclipse.jst.jsf.ui.internal.component; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; import org.eclipse.jdt.core.Signature; import org.eclipse.jface.viewers.LabelProvider; -import org.eclipse.jst.jsf.common.runtime.internal.model.IDesigntimeAdapter; import org.eclipse.jst.jsf.common.runtime.internal.model.component.ComponentInfo; import org.eclipse.jst.jsf.common.runtime.internal.model.component.ComponentTypeInfo; import org.eclipse.jst.jsf.common.runtime.internal.model.component.ComponentInfo.ComponentBeanProperty; @@ -20,6 +17,8 @@ import org.eclipse.jst.jsf.common.runtime.internal.model.decorator.ConverterDeco import org.eclipse.jst.jsf.common.runtime.internal.model.decorator.FacetDecorator; import org.eclipse.jst.jsf.common.runtime.internal.model.decorator.ValidatorDecorator; import org.eclipse.jst.jsf.common.ui.internal.form.AbstractXMLSectionsDetailsForm; +import org.eclipse.jst.jsf.ui.internal.common.ViewObjectPresenter; +import org.eclipse.jst.jsf.ui.internal.common.ViewObjectPresenter.TitleValuePair; import org.eclipse.swt.widgets.Composite; /** @@ -70,70 +69,31 @@ import org.eclipse.swt.widgets.Composite; final String className = compInfo.getComponentTypeInfo().getClassName(); final String id = compInfo.getId(); final ComponentInfo parent = compInfo.getParent(); - final Map<String, String> values = new HashMap<String, String>(); - values.put("Name", className != null ? Signature - .getSimpleName(className) : ""); - values.put("Id", id); + final List<TitleValuePair> values = new ArrayList<TitleValuePair>(); + values.add(new TitleValuePair("Name", className != null ? Signature + .getSimpleName(className) : "")); + values.add(new TitleValuePair("Id", id)); values - .put("Parent Id", parent != null ? parent.getId() - : "<i>none</i>"); + .add(new TitleValuePair("Parent Id", (parent != null && parent.getId() != null) + ? parent.getId() + : "<i>none</i>")); _componentSection.setText(String - .format(formatText, createLines(values)), true, false); + .format(formatText, ViewObjectPresenter.createLines(values)), true, false); _componentSection.refresh(); } private void updateComponentTypeSection(final ComponentTypeInfo typeInfo) { - final String formatText = "<form>%s</form>"; - final String componentType = typeInfo.getComponentType(); - final String componentFamily = typeInfo.getComponentFamily(); - final String renderType = typeInfo.getRenderFamily(); - final String componentClass = typeInfo.getClassName(); - final Map<String, String> values = new HashMap<String, String>(); - - values - .put("Component Type", componentType == null ? "" - : componentType); - values.put("Component Family", componentFamily == null ? "" - : componentFamily); - values.put("Render Type", renderType == null ? "" : renderType); - values.put("Component Class", componentClass == null ? "" - : componentClass); - - _componentTypeSection.setText(String.format(formatText, - createLines(values)), true, false); + _componentTypeSection.setText(ViewObjectPresenter.present(typeInfo), true, false); _componentTypeSection.refresh(); } private void updateComponentInterfacesSection(final ComponentInfo compInfo, final ComponentTypeInfo typeInfo) { - final Set<String> interfaces = new HashSet<String>(); - - interfaces.addAll(Arrays.asList(typeInfo.getInterfaces())); - - for (final Map.Entry entry : (Set<Map.Entry>) compInfo.getAllAdapters() - .entrySet()) - { - final Object infObject = entry.getValue(); - if (infObject instanceof IDesigntimeAdapter) - { - interfaces.addAll(Arrays.asList(((IDesigntimeAdapter)infObject).getInterfaces())); - } - } - final List<String> sortedInterfaceNames = new ArrayList<String>( - interfaces); - Collections.sort(sortedInterfaceNames); - - String text = ""; - for (final String name : sortedInterfaceNames) - { - text += createLine(null, name); - } - - _componentInterfacesSection.setText(String.format("<form>%s</form>", - text), true, false); + _componentInterfacesSection.setText( + ViewObjectPresenter.presentCompInterfaces(typeInfo,compInfo), true, false); _componentInterfacesSection.refresh(); } @@ -147,7 +107,7 @@ import org.eclipse.swt.widgets.Composite; if (labelText != null) { - text += createLine(null, labelText); + text += ViewObjectPresenter.createLine(null, labelText); } } Collections.sort(decoratorLines); @@ -172,7 +132,7 @@ import org.eclipse.swt.widgets.Composite; Object value = propValue.getValue(); if (value != null) { - decoratorLines.add(createLine(propName, + decoratorLines.add(ViewObjectPresenter.createLine(propName, value.toString())); } } @@ -218,27 +178,7 @@ import org.eclipse.swt.widgets.Composite; return Collections.singleton(_componentSection); } - private String createLines(final Map<String, String> values) - { - String lines = ""; - for (final Map.Entry<String, String> valueEntry : values.entrySet()) - { - final String title = valueEntry.getKey(); - final String value = valueEntry.getValue(); - - lines += createLine(title, value); - } - return lines; - } - private String createLine(final String title, final String value) - { - if (title == null) - { - return String.format("<p>%s</p>", value); - } - return String.format("<p><b>%s</b>: %s</p>", title, value); - } private static class MyLabelProvider extends LabelProvider { diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/tagregistry/ComponentDetailSubForm.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/tagregistry/ComponentDetailSubForm.java index 7b8b86e15..73c12a8a7 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/tagregistry/ComponentDetailSubForm.java +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/tagregistry/ComponentDetailSubForm.java @@ -8,6 +8,7 @@ import java.util.Set; import org.eclipse.jst.jsf.common.runtime.internal.model.component.ComponentTypeInfo; import org.eclipse.jst.jsf.common.runtime.internal.view.model.common.IComponentTagElement; import org.eclipse.jst.jsf.common.ui.internal.form.AbstractXMLSectionsDetailsForm; +import org.eclipse.jst.jsf.ui.internal.common.ViewObjectPresenter; import org.eclipse.swt.widgets.Composite; /** @@ -19,7 +20,9 @@ import org.eclipse.swt.widgets.Composite; public class ComponentDetailSubForm extends AbstractXMLSectionsDetailsForm { private final static String COMPONENT_TYPE_SECTION_KEY = "componentSection"; + private static final String INTERFACES_SECTION_KEY = "interfacesSection"; private XMLTextSection _componentTypeSection; + private XMLTextSection _interfacesSection; @Override protected Map<? extends Object, XMLTextSection> createXMLTextSections(Composite parent) @@ -27,6 +30,9 @@ public class ComponentDetailSubForm extends AbstractXMLSectionsDetailsForm final Map<String, XMLTextSection> sections = new HashMap<String, XMLTextSection>(); _componentTypeSection = new XMLTextSection(getToolkit(), parent, "Component Type Information"); sections.put(COMPONENT_TYPE_SECTION_KEY, _componentTypeSection); + + _interfacesSection = new XMLTextSection(getToolkit(), parent, "Interface Information"); + sections.put(INTERFACES_SECTION_KEY, _interfacesSection); return sections; } @@ -48,16 +54,8 @@ public class ComponentDetailSubForm extends AbstractXMLSectionsDetailsForm final ComponentTypeInfo typeInfo = curTagElement.getComponent(); if (typeInfo != null) { - final String formatText = "<form><p><b>Component Type:</b> %s</p> <p><b>Component Family:</b> %s</p> <p><b>Render Type:</b> %s</p><p><b>Component Class:</b> %s</p></form>"; - final String componentType = typeInfo.getComponentType(); - final String componentFamily = typeInfo.getComponentFamily(); - final String renderType = typeInfo.getRenderFamily(); - final String componentClass = typeInfo.getClassName(); - _componentTypeSection.setText(String.format(formatText, - componentType == null ? "" : componentType, - componentFamily == null ? "" : componentFamily, - renderType == null ? "" : renderType, - componentClass == null ? "" : componentClass), true, false); + _componentTypeSection.setText(ViewObjectPresenter.present(typeInfo), true, false); + _interfacesSection.setText(ViewObjectPresenter.presentCompInterfaces(typeInfo, null), true, false); _componentTypeSection.refresh(); } } diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/tagregistry/TagRegistryMasterForm.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/tagregistry/TagRegistryMasterForm.java index c030ed3a7..df3361e1b 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/tagregistry/TagRegistryMasterForm.java +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/tagregistry/TagRegistryMasterForm.java @@ -7,6 +7,7 @@ import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.jdt.ui.JavaUI; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.viewers.ComboViewer; import org.eclipse.jface.viewers.ISelection; @@ -270,11 +271,16 @@ public class TagRegistryMasterForm extends AbstractMasterForm @Override public void run() { - final boolean flushCaches = MessageDialog - .openQuestion( - _viewer.getControl().getShell(), - "Flush cached data?", - "Flushing cached data may cause some operations slow until cached information is regenerated"); + MessageDialog dialog = new MessageDialog(_viewer.getControl().getShell(), "Also flush cached data?", null, // accept + // the + // default + // window + // icon + "Flushing cached data may cause some operations to slow until cached information is regenerated. If you answer no, the view will refresh but NOT flush cached data" + , MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, + IDialogConstants.NO_LABEL }, 1); // no is the + // default + final boolean flushCaches = (dialog.open() == 0); final Object selectedObj = getSelected(_viewer.getSelection()); if (selectedObj instanceof TagRegistryInstance) @@ -296,6 +302,7 @@ public class TagRegistryMasterForm extends AbstractMasterForm registry.refresh(nullRunnable, flushCaches); } } + } private Object getSelected(ISelection selection) diff --git a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/tagregistry/TagRegistryView.java b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/tagregistry/TagRegistryView.java index f80f6224e..c7a9ec4de 100644 --- a/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/tagregistry/TagRegistryView.java +++ b/jsf/plugins/org.eclipse.jst.jsf.ui/src/org/eclipse/jst/jsf/ui/internal/tagregistry/TagRegistryView.java @@ -3,7 +3,6 @@ package org.eclipse.jst.jsf.ui.internal.tagregistry; import org.eclipse.jst.jsf.ui.internal.JSFUiPlugin; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.IViewSite; import org.eclipse.ui.PartInitException; @@ -54,15 +53,10 @@ public class TagRegistryView extends ViewPart @Override public void createPartControl(final Composite parent) { - final GridLayout gridLayout= new GridLayout(1,true); - parent.setLayout(gridLayout); _toolkit = new FormToolkit(parent.getDisplay()); - //_form = createScrolledForm(parent);//_toolkit.createScrolledForm(parent); _form = _toolkit.createForm(parent); _form.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true,true)); - //_form.getBody().setLayout(new GridLayout(2,true)); - //final ManagedForm managedForm = new ManagedForm(_toolkit, _form); _masterDetailBlock = new TagRegistryMasterDetailBlock(); _masterDetailBlock.createContent(_toolkit,_form); |