Skip to content
This repository has been archived by the owner on Jul 13, 2022. It is now read-only.

Commit

Permalink
[PT-#151672260] Beans tree provider adjusted
Browse files Browse the repository at this point in the history
  • Loading branch information
BoykoAlex committed Oct 4, 2017
1 parent 633381f commit d71f300
Show file tree
Hide file tree
Showing 19 changed files with 210 additions and 114 deletions.
Expand Up @@ -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
Expand Up @@ -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;

Expand All @@ -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)));
}


Expand Down
Expand Up @@ -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<String, String> attributes;

Expand Down
@@ -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();

}
Expand Up @@ -47,13 +47,7 @@ public Map<String, String> 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() {
Expand Down
@@ -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;
}

}
Expand Up @@ -14,16 +14,14 @@
* @author Leo Dos Santos
* @author Alex Boyko
*/
public class LiveBeansContext extends LiveBeansGroup {
public class LiveBeansContext extends LiveBeansGroup<LiveBean> {

public static final String ATTR_CONTEXT = "context";

public static final String ATTR_PARENT = "parent";

public static final String ATTR_BEANS = "beans";

private String displayName;

private LiveBeansContext parent;

public LiveBeansContext(String label) {
Expand All @@ -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() {
Expand Down
Expand Up @@ -18,24 +18,28 @@
* @author Leo Dos Santos
* @author Alex Boyko
*/
public class LiveBeansGroup extends AbstractLiveBeansModelElement {
public class LiveBeansGroup<T extends AbstractLiveBeansModelElement> extends AbstractLiveBeansModelElement {

private final String label;

private final List<LiveBean> beans;
private final List<T> elements;

public LiveBeansGroup(String label) {
this(label, new ArrayList<T>());
}

public LiveBeansGroup(String label, List<T> elements) {
super();
this.label = label;
beans = new ArrayList<LiveBean>();
this.elements = elements;
}

public void addBean(LiveBean bean) {
beans.add(bean);
public void addElement(T bean) {
elements.add(bean);
}

public List<LiveBean> getBeans() {
return beans;
public List<T> getElements() {
return elements;
}

public String getDisplayName() {
Expand All @@ -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);
}



}
Expand Up @@ -31,7 +31,7 @@ public class LiveBeansJsonParser {

private Map<String, LiveBeansContext> contextMap;

private Map<String, LiveBeansGroup> resourceMap;
private Map<String, LiveBeansResource> resourceMap;

public LiveBeansJsonParser(TypeLookup typeLookup, String jsonInput) {
this.jsonInput = jsonInput;
Expand All @@ -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);
}
}
Expand All @@ -56,7 +56,7 @@ private void groupByResource() {
public LiveBeansModel parse() throws JSONException {
beansMap = new LinkedHashMap<String, LiveBean>();
contextMap = new LinkedHashMap<String, LiveBeansContext>();
resourceMap = new LinkedHashMap<String, LiveBeansGroup>();
resourceMap = new LinkedHashMap<String, LiveBeansResource>();

// JSON structure is an array of context descriptions, each containing
// an array of beans
Expand Down Expand Up @@ -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);
}
}
Expand Down
Expand Up @@ -25,28 +25,28 @@ public class LiveBeansModel implements Comparable<LiveBeansModel> {

private final List<LiveBean> beans;

private final List<LiveBeansGroup> contexts;
private final List<LiveBeansContext> contexts;

private final List<LiveBeansGroup> resources;
private final List<LiveBeansResource> resources;

private final TypeLookup typeLookup;

public LiveBeansModel(TypeLookup typeLookup) {
this.beans = new ArrayList<LiveBean>();
this.contexts = new ArrayList<LiveBeansGroup>();
this.resources = new ArrayList<LiveBeansGroup>();
this.contexts = new ArrayList<LiveBeansContext>();
this.resources = new ArrayList<LiveBeansResource>();
this.typeLookup = typeLookup;
}

public void addBeans(Collection<LiveBean> beansToAdd) {
beans.addAll(beansToAdd);
}

public void addContexts(Collection<? extends LiveBeansGroup> contextsToAdd) {
public void addContexts(Collection<? extends LiveBeansContext> contextsToAdd) {
contexts.addAll(contextsToAdd);
}

public void addResources(Collection<? extends LiveBeansGroup> resourcesToAdd) {
public void addResources(Collection<? extends LiveBeansResource> resourcesToAdd) {
resources.addAll(resourcesToAdd);
}

Expand All @@ -65,11 +65,11 @@ public List<LiveBean> getBeans() {
return beans;
}

public List<LiveBeansGroup> getBeansByContext() {
public List<LiveBeansContext> getBeansByContext() {
return contexts;
}

public List<LiveBeansGroup> getBeansByResource() {
public List<LiveBeansResource> getBeansByResource() {
return resources;
}

Expand Down
Expand Up @@ -14,9 +14,7 @@
* @author Leo Dos Santos
* @author Alex Boyko
*/
public class LiveBeansResource extends LiveBeansGroup {

private String displayName;
public class LiveBeansResource extends LiveBeansGroup<LiveBean> {

public LiveBeansResource(String label) {
super(label);
Expand All @@ -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;
}

}

0 comments on commit d71f300

Please sign in to comment.