diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/META-INF/MANIFEST.MF b/plugins/org.springframework.ide.eclipse.beans.ui.live/META-INF/MANIFEST.MF index dfe57b2fbf..10bb61e379 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.live/META-INF/MANIFEST.MF +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/META-INF/MANIFEST.MF @@ -16,7 +16,8 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.jface, org.eclipse.ui.workbench, org.eclipse.jdt.core, - org.springsource.ide.eclipse.commons.ui + org.springsource.ide.eclipse.commons.ui, + org.eclipse.jdt.ui Bundle-ActivationPolicy: lazy Bundle-Vendor: Spring IDE Developers Bundle-Activator: org.springframework.ide.eclipse.beans.ui.live.LiveBeansUiPlugin diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/icons/full/obj16/collection_obj.gif b/plugins/org.springframework.ide.eclipse.beans.ui.live/icons/collection_obj.gif similarity index 100% rename from plugins/org.springframework.ide.eclipse.beans.ui.livegraph/icons/full/obj16/collection_obj.gif rename to plugins/org.springframework.ide.eclipse.beans.ui.live/icons/collection_obj.gif diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/LiveBeansUiPlugin.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/LiveBeansUiPlugin.java index 5254fcfe20..ae31371b62 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/LiveBeansUiPlugin.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/LiveBeansUiPlugin.java @@ -32,6 +32,7 @@ public class LiveBeansUiPlugin extends AbstractUIPlugin { public static final String IMG_OBJS_BEAN = NAME_PREFIX + "bean_obj.gif"; public static final String IMG_OBJS_BEAN_REF = NAME_PREFIX + "beanref_obj.gif"; public static final String IMG_OBJS_CONFIG = NAME_PREFIX + "config_obj.gif"; + public static final String IMG_OBJS_COLLECTION = NAME_PREFIX + "collection_obj.gif"; private static LiveBeansUiPlugin plugin; @@ -58,6 +59,7 @@ protected void initializeImageRegistry(ImageRegistry reg) { reg.put(IMG_OBJS_BEAN, imageDescriptorFromPlugin(PLUGIN_ID, ICON_PATH_PREFIX + IMG_OBJS_BEAN.substring(NAME_PREFIX_LENGTH))); reg.put(IMG_OBJS_BEAN_REF, imageDescriptorFromPlugin(PLUGIN_ID, ICON_PATH_PREFIX + IMG_OBJS_BEAN_REF.substring(NAME_PREFIX_LENGTH))); reg.put(IMG_OBJS_CONFIG, imageDescriptorFromPlugin(PLUGIN_ID, ICON_PATH_PREFIX + IMG_OBJS_CONFIG.substring(NAME_PREFIX_LENGTH))); + reg.put(IMG_OBJS_COLLECTION, imageDescriptorFromPlugin(PLUGIN_ID, ICON_PATH_PREFIX + IMG_OBJS_COLLECTION.substring(NAME_PREFIX_LENGTH))); } diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/AbstractLiveBeansModelElement.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/AbstractLiveBeansModelElement.java index 6d816381d6..06bfd042df 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/AbstractLiveBeansModelElement.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/AbstractLiveBeansModelElement.java @@ -20,7 +20,7 @@ * @author Leo Dos Santos * @author Alex Boyko */ -public abstract class AbstractLiveBeansModelElement implements IAdaptable { +public abstract class AbstractLiveBeansModelElement implements IAdaptable, DisplayName { protected final Map attributes; diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/DisplayName.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/DisplayName.java new file mode 100644 index 0000000000..8fb8dc5f63 --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/DisplayName.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2017 Pivotal, Inc. + * 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: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.eclipse.beans.ui.live.model; + +/** + * Mark UI elements which are able to provide their label + * + * @author Alex Boyko + * + */ +public interface DisplayName { + + String getDisplayName(); + +} diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeanRelation.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeanRelation.java index f56468a824..e7d520a164 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeanRelation.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeanRelation.java @@ -47,13 +47,7 @@ public Map getAttributes() { } public String getDisplayName() { - String label = bean.getDisplayName(); - if (isDependency) { - return "Depends on: " + label; - } - else { - return "Injected into: " + label; - } + return bean.getDisplayName(); } public boolean isDependency() { diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeanType.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeanType.java new file mode 100644 index 0000000000..3f435865e6 --- /dev/null +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeanType.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2017 Pivotal, Inc. + * 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: + * Pivotal, Inc. - initial API and implementation + *******************************************************************************/ +package org.springframework.ide.eclipse.beans.ui.live.model; + +/** + * Wrapper to mark bean type in the UI + * + * @author Alex Boyko + * + */ +public class LiveBeanType implements DisplayName { + + private LiveBean bean; + + public LiveBeanType(LiveBean bean) { + this.bean = bean; + } + + public String getDisplayName() { + String type = bean.getBeanType(); + int idx = type.indexOf("$$"); + if (idx >= 0) { + return type.substring(0, idx); + } + return type; + } + +} diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansContext.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansContext.java index b68ff9a726..03b9ab836a 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansContext.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansContext.java @@ -14,7 +14,7 @@ * @author Leo Dos Santos * @author Alex Boyko */ -public class LiveBeansContext extends LiveBeansGroup { +public class LiveBeansContext extends LiveBeansGroup { public static final String ATTR_CONTEXT = "context"; @@ -22,8 +22,6 @@ public class LiveBeansContext extends LiveBeansGroup { public static final String ATTR_BEANS = "beans"; - private String displayName; - private LiveBeansContext parent; public LiveBeansContext(String label) { @@ -33,18 +31,7 @@ public LiveBeansContext(String label) { @Override public String getDisplayName() { - // compute the display name the first time it's needed - if (displayName == null) { - String label = getLabel(); - int indexStart = label.lastIndexOf(":"); - if (indexStart > -1 && indexStart < label.length()) { - displayName = label.substring(indexStart + 1, label.length()); - } - if (displayName == null) { - displayName = label; - } - } - return displayName; + return getLabel(); } public LiveBeansContext getParent() { diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansGroup.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansGroup.java index 5b2a8b8dcf..a808178d42 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansGroup.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansGroup.java @@ -18,24 +18,28 @@ * @author Leo Dos Santos * @author Alex Boyko */ -public class LiveBeansGroup extends AbstractLiveBeansModelElement { +public class LiveBeansGroup extends AbstractLiveBeansModelElement { private final String label; - private final List beans; + private final List elements; public LiveBeansGroup(String label) { + this(label, new ArrayList()); + } + + public LiveBeansGroup(String label, List elements) { super(); this.label = label; - beans = new ArrayList(); + this.elements = elements; } - public void addBean(LiveBean bean) { - beans.add(bean); + public void addElement(T bean) { + elements.add(bean); } - public List getBeans() { - return beans; + public List getElements() { + return elements; } public String getDisplayName() { @@ -49,14 +53,12 @@ public String getLabel() { @Override public boolean equals(Object obj) { if (obj instanceof LiveBeansGroup) { - LiveBeansGroup other = (LiveBeansGroup) obj; + LiveBeansGroup other = (LiveBeansGroup) obj; return Objects.equals(label, other.label) && Objects.equals(attributes, other.attributes) - && Objects.equals(beans, other.beans); + && Objects.equals(elements, other.elements); } return super.equals(obj); } - - } diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansJsonParser.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansJsonParser.java index 3469030802..015e21cc09 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansJsonParser.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansJsonParser.java @@ -31,7 +31,7 @@ public class LiveBeansJsonParser { private Map contextMap; - private Map resourceMap; + private Map resourceMap; public LiveBeansJsonParser(TypeLookup typeLookup, String jsonInput) { this.jsonInput = jsonInput; @@ -42,12 +42,12 @@ private void groupByResource() { for (LiveBean bean : beansMap.values()) { String resource = bean.getResource(); if (resourceMap.containsKey(resource)) { - LiveBeansGroup group = resourceMap.get(resource); - group.addBean(bean); + LiveBeansResource group = resourceMap.get(resource); + group.addElement(bean); } else { - LiveBeansGroup group = new LiveBeansResource(resource); - group.addBean(bean); + LiveBeansResource group = new LiveBeansResource(resource); + group.addElement(bean); resourceMap.put(resource, group); } } @@ -56,7 +56,7 @@ private void groupByResource() { public LiveBeansModel parse() throws JSONException { beansMap = new LinkedHashMap(); contextMap = new LinkedHashMap(); - resourceMap = new LinkedHashMap(); + resourceMap = new LinkedHashMap(); // JSON structure is an array of context descriptions, each containing // an array of beans @@ -91,7 +91,7 @@ private void parseBeans(LiveBeansContext context, JSONArray beansArray) throws J if (typeLookup.getApplicationName() != null) { bean.addAttribute(LiveBean.ATTR_APPLICATION, typeLookup.getApplicationName()); } - context.addBean(bean); + context.addElement(bean); beansMap.put(bean.getId(), bean); } } diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansModel.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansModel.java index 0d8720e393..2aa064f8ab 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansModel.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansModel.java @@ -25,16 +25,16 @@ public class LiveBeansModel implements Comparable { private final List beans; - private final List contexts; + private final List contexts; - private final List resources; + private final List resources; private final TypeLookup typeLookup; public LiveBeansModel(TypeLookup typeLookup) { this.beans = new ArrayList(); - this.contexts = new ArrayList(); - this.resources = new ArrayList(); + this.contexts = new ArrayList(); + this.resources = new ArrayList(); this.typeLookup = typeLookup; } @@ -42,11 +42,11 @@ public void addBeans(Collection beansToAdd) { beans.addAll(beansToAdd); } - public void addContexts(Collection contextsToAdd) { + public void addContexts(Collection contextsToAdd) { contexts.addAll(contextsToAdd); } - public void addResources(Collection resourcesToAdd) { + public void addResources(Collection resourcesToAdd) { resources.addAll(resourcesToAdd); } @@ -65,11 +65,11 @@ public List getBeans() { return beans; } - public List getBeansByContext() { + public List getBeansByContext() { return contexts; } - public List getBeansByResource() { + public List getBeansByResource() { return resources; } diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansResource.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansResource.java index 47845c3f12..228707f40a 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansResource.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/model/LiveBeansResource.java @@ -14,9 +14,7 @@ * @author Leo Dos Santos * @author Alex Boyko */ -public class LiveBeansResource extends LiveBeansGroup { - - private String displayName; +public class LiveBeansResource extends LiveBeansGroup { public LiveBeansResource(String label) { super(label); @@ -26,26 +24,42 @@ public LiveBeansResource(String label) { @Override public String getDisplayName() { // compute the display name the first time it's needed - if (displayName == null) { - String label = getLabel(); - if (label.equalsIgnoreCase("null")) { - displayName = "Container Generated"; - } - else { - // Expecting the label to contain some form of - // "[file/path/to/resource.ext]" so we're going to parse out the - // last segment of the file path. - int indexStart = label.lastIndexOf("/"); - int indexEnd = label.lastIndexOf("]"); - if (indexStart > -1 && indexEnd > -1 && indexStart < indexEnd) { - displayName = label.substring(indexStart + 1, indexEnd); - } + String label = getLabel(); + if (label.equalsIgnoreCase("null")) { + return "Container Generated"; + } else { + // Expecting the label to contain some form of + // "[file/path/to/resource.ext]" so we're going to parse out the + // last segment of the file path. + int indexStart = label.indexOf("["); + int indexEnd = label.lastIndexOf("]"); + if (indexStart > -1 && indexEnd > -1 && indexStart < indexEnd) { + return label.substring(indexStart + 1, indexEnd); + } else { + return label; } - if (displayName == null) { - displayName = label; + } + } + + public String getFileName() { + String label = getLabel(); + int indexStart = label.lastIndexOf("/"); + int indexEnd = label.lastIndexOf("]"); + if (indexStart > -1 && indexEnd > -1 && indexStart < indexEnd) { + return label.substring(indexStart + 1, indexEnd); + } + return null; + } + + public String getFileExtension() { + String filename = getFileName(); + if (filename != null) { + int idx = filename.lastIndexOf('.'); + if (idx >= 0 && idx < filename.length() - 1) { + return filename.substring(idx + 1); } } - return displayName; + return null; } } diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/AbstractLiveBeansTreeContentProvider.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/AbstractLiveBeansTreeContentProvider.java index 901bc74fa4..99446beafe 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/AbstractLiveBeansTreeContentProvider.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/AbstractLiveBeansTreeContentProvider.java @@ -10,13 +10,15 @@ *******************************************************************************/ package org.springframework.ide.eclipse.beans.ui.live.tree; -import java.util.LinkedHashSet; -import java.util.Set; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; import org.eclipse.jface.viewers.ITreeContentProvider; import org.eclipse.jface.viewers.Viewer; import org.springframework.ide.eclipse.beans.ui.live.model.LiveBean; import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeanRelation; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeanType; import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansGroup; /** @@ -33,24 +35,33 @@ public void dispose() { public Object[] getChildren(Object parentElement) { if (parentElement instanceof LiveBeansGroup) { - LiveBeansGroup group = (LiveBeansGroup) parentElement; - return group.getBeans().toArray(); + LiveBeansGroup group = (LiveBeansGroup) parentElement; + return group.getElements().toArray(); } else if (parentElement instanceof LiveBean) { - Set children = new LinkedHashSet(); - LiveBean bean = (LiveBean) parentElement; - Set dependencies = bean.getDependencies(); - for (LiveBean child : dependencies) { - children.add(new LiveBeanRelation(child, true)); - } - Set injectInto = bean.getInjectedInto(); - for (LiveBean child : injectInto) { - children.add(new LiveBeanRelation(child)); - } - return children.toArray(); + LiveBean bean = (LiveBean) parentElement; + return getBeanChildren(bean).toArray(); } return null; } + + protected List getBeanChildren(LiveBean bean) { + List children = new ArrayList<>(); + + children.add(new LiveBeanType(bean)); + + children.add(new LiveBeansGroup<>("Dependencies", bean.getDependencies() + .stream() + .map(b -> new LiveBeanRelation(b, true)) + .collect(Collectors.toList()))); + + children.add(new LiveBeansGroup<>("Injected Into", bean.getInjectedInto() + .stream() + .map(b -> new LiveBeanRelation(b)) + .collect(Collectors.toList()))); + + return children; + } public Object getParent(Object element) { // TODO Auto-generated method stub @@ -58,13 +69,11 @@ public Object getParent(Object element) { } public boolean hasChildren(Object element) { - if (element instanceof LiveBeansGroup) { + if (element instanceof LiveBeansGroup) { + return !((LiveBeansGroup)element).getElements().isEmpty(); + } else if (element instanceof LiveBean) { return true; } - else if (element instanceof LiveBean) { - LiveBean bean = (LiveBean) element; - return !bean.getDependencies().isEmpty() || !bean.getInjectedInto().isEmpty(); - } return false; } diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/ContextGroupedBeansContentProvider.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/ContextGroupedBeansContentProvider.java index 3ece60a9bd..9fced4136d 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/ContextGroupedBeansContentProvider.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/ContextGroupedBeansContentProvider.java @@ -10,7 +10,11 @@ *******************************************************************************/ package org.springframework.ide.eclipse.beans.ui.live.tree; +import java.util.List; + +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBean; import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansModel; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansResource; /** * Beans grouped by contexts @@ -33,4 +37,14 @@ public Object[] getElements(Object inputElement) { return new Object[0]; } + @Override + protected List getBeanChildren(LiveBean bean) { + List children = super.getBeanChildren(bean); + String resource = bean.getResource(); + if (resource != null && !resource.isEmpty()) { + children.add(1, new LiveBeansResource(resource)); + } + return children; + } + } diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/LiveBeansTreeLabelProvider.java b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/LiveBeansTreeLabelProvider.java index 5c747dba81..cb447d719f 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/LiveBeansTreeLabelProvider.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.live/src/org/springframework/ide/eclipse/beans/ui/live/tree/LiveBeansTreeLabelProvider.java @@ -10,12 +10,17 @@ *******************************************************************************/ package org.springframework.ide.eclipse.beans.ui.live.tree; +import org.eclipse.jdt.ui.ISharedImages; +import org.eclipse.jdt.ui.JavaUI; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.swt.graphics.Image; import org.springframework.ide.eclipse.beans.ui.live.LiveBeansUiPlugin; +import org.springframework.ide.eclipse.beans.ui.live.model.DisplayName; import org.springframework.ide.eclipse.beans.ui.live.model.LiveBean; import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeanRelation; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeanType; import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansGroup; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansResource; /** * A label provider for the Live Beans tree display @@ -42,11 +47,18 @@ public class LiveBeansTreeLabelProvider extends LabelProvider { public Image getImage(Object element) { if (element instanceof LiveBean) { return LiveBeansUiPlugin.getDefault().getImageRegistry().get(LiveBeansUiPlugin.IMG_OBJS_BEAN); - } - else if (element instanceof LiveBeansGroup) { - return LiveBeansUiPlugin.getDefault().getImageRegistry().get(LiveBeansUiPlugin.IMG_OBJS_CONFIG); - } - else if (element instanceof LiveBeanRelation) { + } else if (element instanceof LiveBeansResource) { + String fileExtension = ((LiveBeansResource)element).getFileExtension(); + if ("class".equalsIgnoreCase(fileExtension)) { + return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_CFILE); + } else { + return LiveBeansUiPlugin.getDefault().getImageRegistry().get(LiveBeansUiPlugin.IMG_OBJS_CONFIG); + } + } else if (element instanceof LiveBeansGroup) { + return LiveBeansUiPlugin.getDefault().getImageRegistry().get(LiveBeansUiPlugin.IMG_OBJS_COLLECTION); + } else if (element instanceof LiveBeanType) { + return JavaUI.getSharedImages().getImage(ISharedImages.IMG_OBJS_CLASS); + } else if (element instanceof LiveBeanRelation) { // TODO: incoming/outgoing arrow images??? return LiveBeansUiPlugin.getDefault().getImageRegistry().get(LiveBeansUiPlugin.IMG_OBJS_BEAN_REF); } @@ -55,14 +67,8 @@ else if (element instanceof LiveBeanRelation) { @Override public String getText(Object element) { - if (element instanceof LiveBean) { - return ((LiveBean) element).getDisplayName(); - } - else if (element instanceof LiveBeansGroup) { - return ((LiveBeansGroup) element).getDisplayName(); - } - else if (element instanceof LiveBeanRelation) { - return ((LiveBeanRelation) element).getDisplayName(); + if (element instanceof DisplayName) { + return ((DisplayName) element).getDisplayName(); } return super.getText(element); } diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/LiveGraphUIImages.java b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/LiveGraphUIImages.java index 6f9c159ba7..ba0e4196cf 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/LiveGraphUIImages.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/LiveGraphUIImages.java @@ -43,13 +43,11 @@ public class LiveGraphUIImages { /* * Available cached Images in the Spring Beans UI plugin image registry. */ - public static final String IMG_OBJS_COLLECTION = NAME_PREFIX + "collection_obj.gif"; public static final String IMG_OBJS_REFRESH = NAME_PREFIX + "refresh_obj.gif"; // Use IPath and toOSString to build the names to ensure they have the slashes correct private final static String OBJECT = "obj16/"; //basic colors - size 16x16 - public static final ImageDescriptor DESC_OBJS_COLLECTION = createManaged(OBJECT, IMG_OBJS_COLLECTION); public static final ImageDescriptor REFRESH = createManaged(OBJECT, IMG_OBJS_REFRESH); /* diff --git a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/ToggleViewModeAction.java b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/ToggleViewModeAction.java index dac7d26a26..4a5f405160 100644 --- a/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/ToggleViewModeAction.java +++ b/plugins/org.springframework.ide.eclipse.beans.ui.livegraph/src/org/springframework/ide/eclipse/beans/ui/livegraph/actions/ToggleViewModeAction.java @@ -12,7 +12,6 @@ import org.eclipse.jface.action.Action; import org.springframework.ide.eclipse.beans.ui.live.LiveBeansUiPlugin; -import org.springframework.ide.eclipse.beans.ui.livegraph.LiveGraphUIImages; import org.springframework.ide.eclipse.beans.ui.livegraph.views.LiveBeansGraphView; /** @@ -32,7 +31,7 @@ public ToggleViewModeAction(LiveBeansGraphView view, int mode) { } else if (mode == LiveBeansGraphView.DISPLAY_MODE_TREE) { setText("Tree View"); - setImageDescriptor(LiveGraphUIImages.DESC_OBJS_COLLECTION); + setImageDescriptor(LiveBeansUiPlugin.getDefault().getImageRegistry().getDescriptor(LiveBeansUiPlugin.IMG_OBJS_COLLECTION)); } this.view = view; this.mode = mode; diff --git a/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/ActuatorDataTest.java b/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/ActuatorDataTest.java index 0f0ccaa444..85788e796b 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/ActuatorDataTest.java +++ b/plugins/org.springframework.ide.eclipse.boot.dash.test/src/org/springframework/ide/eclipse/boot/dash/test/actuator/ActuatorDataTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Pivotal, Inc. + * Copyright (c) 2017 Pivotal, Inc. * 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 @@ -15,7 +15,7 @@ import org.junit.Test; import org.springframework.ide.eclipse.beans.ui.live.model.LiveBean; -import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansGroup; +import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansContext; import org.springframework.ide.eclipse.beans.ui.live.model.LiveBeansModel; import org.springframework.ide.eclipse.beans.ui.live.model.TypeLookup; import org.springframework.ide.eclipse.boot.dash.model.actuator.ActuatorClient; @@ -75,12 +75,12 @@ protected String getBeansData() throws Exception { TestActuatorClient client = new TestActuatorClient(null).beansJson(ActuatorClientTest.getContents("beans-sample.json")); LiveBeansModel liveBeans = client.getBeans(); assertEquals(1, liveBeans.getBeansByContext().size()); - LiveBeansGroup context = liveBeans.getBeansByContext().get(0); - assertEquals(2, context.getBeans().size()); + LiveBeansContext context = liveBeans.getBeansByContext().get(0); + assertEquals(2, context.getElements().size()); assertEquals(2, liveBeans.getBeans().size()); assertEquals(2, liveBeans.getBeansByResource().size()); - assertEquals(context.getBeans(), liveBeans.getBeans()); + assertEquals(context.getElements(), liveBeans.getBeans()); LiveBean bean1 = liveBeans.getBeans().get(0); assertEquals( diff --git a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/properties/BeansPropertiesSection.java b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/properties/BeansPropertiesSection.java index b6e936d0f2..a1e911f307 100644 --- a/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/properties/BeansPropertiesSection.java +++ b/plugins/org.springframework.ide.eclipse.boot.dash/src/org/springframework/ide/eclipse/boot/dash/views/properties/BeansPropertiesSection.java @@ -25,8 +25,8 @@ import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.views.properties.tabbed.ITabbedPropertyConstants; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; +import org.springframework.ide.eclipse.beans.ui.live.tree.ContextGroupedBeansContentProvider; import org.springframework.ide.eclipse.beans.ui.live.tree.LiveBeansTreeLabelProvider; -import org.springframework.ide.eclipse.beans.ui.live.tree.ResourceGroupedBeansContentProvider; import org.springframework.ide.eclipse.boot.dash.model.BootDashElement; /** @@ -82,8 +82,13 @@ protected Point computeSize(Composite composite, int wHint, int hHint, boolean f labelText = getWidgetFactory().createLabel(composite, "", SWT.WRAP); //$NON-NLS-1$ treeViewer = new TreeViewer(composite/*, SWT.NO_SCROLL*/); - treeViewer.setContentProvider(new BeansContentProvider(ResourceGroupedBeansContentProvider.INSTANCE)); + // BootDashElement should be input rather than the LiveBeansModel. Due to + // polling the model often to show changes in the model it's best to refresh the + // tree viewer rather then set the whole input that would remove the selection + // and collapse expanded nodes + treeViewer.setContentProvider(new BeansContentProvider(ContextGroupedBeansContentProvider.INSTANCE)); treeViewer.setLabelProvider(LiveBeansTreeLabelProvider.INSTANCE); + treeViewer.setAutoExpandLevel(2); treeViewer.getTree().addTreeListener (new TreeListener () { @Override @@ -115,7 +120,13 @@ public void refresh() { } else { labelText.setText(""); } + // No tree widgets means that BootDashElement probably wasn't "running" or had no beans + boolean firstTimeTreePopulated = treeViewer.getTree().getItems().length == 0; treeViewer.refresh(); + if (firstTimeTreePopulated) { + // If tree is populated for the first time then auto expand to level 2 manually because new input is not set in this case + treeViewer.expandToLevel(2); + } reflow(page); }