this.locale = locale;
}
this.oldValues = new HashMap<String, GWTJahiaNodeProperty>();
this.newValues = new HashMap<String, GWTJahiaNodeProperty>();
tab.setLayout(new BorderLayout());
final GWTJahiaNode node = engine.getNode();
tagLoader = new BaseTreeLoader<GWTJahiaNode>(new RpcProxy<List<GWTJahiaNode>>() {
@Override
protected void load(Object o, final AsyncCallback<List<GWTJahiaNode>> listAsyncCallback) {
if (node != null) {
final JahiaContentManagementServiceAsync async = JahiaContentManagementService.App.getInstance();
if (newValues.containsKey(TagsTabItem.this.locale)) {
final GWTJahiaNodeProperty gwtJahiaNodeProperty = newValues.get(TagsTabItem.this.locale);
final List<GWTJahiaNodePropertyValue> propertyValues = gwtJahiaNodeProperty.getValues();
List<GWTJahiaNode> nodes = new ArrayList<GWTJahiaNode>(propertyValues.size());
for (GWTJahiaNodePropertyValue propertyValue : propertyValues) {
nodes.add(propertyValue.getNode());
}
listAsyncCallback.onSuccess(nodes);
} else {
GWTJahiaNodeProperty oldProperty = engine.getProperties().get("j:tags");
GWTJahiaNodeProperty newProperty = new GWTJahiaNodeProperty();
newProperty.setMultiple(true);
newProperty.setValues(new ArrayList<GWTJahiaNodePropertyValue>());
newProperty.setName("j:tags");
if (oldProperty != null) {
final List<GWTJahiaNodePropertyValue> propertyValues = oldProperty.getValues();
List<GWTJahiaNode> nodes = new ArrayList<GWTJahiaNode>(propertyValues.size());
for (GWTJahiaNodePropertyValue propertyValue : propertyValues) {
nodes.add(propertyValue.getNode());
}
newProperty.getValues().addAll(oldProperty.getValues());
listAsyncCallback.onSuccess(nodes);
} else {
listAsyncCallback.onSuccess(new ArrayList<GWTJahiaNode>());
}
oldValues.put(TagsTabItem.this.locale, oldProperty);
newValues.put(TagsTabItem.this.locale, newProperty);
}
}
}
});
tagStore = new TreeStore<GWTJahiaNode>(tagLoader);
tagStore.setStoreSorter(new StoreSorter<GWTJahiaNode>(new Comparator<Object>() {
public int compare(Object o1, Object o2) {
if (o1 instanceof String && o2 instanceof String) {
String s1 = (String) o1;
String s2 = (String) o2;
return Collator.getInstance().localeCompare(s1, s2);
} else if (o1 instanceof Comparable && o2 instanceof Comparable) {
return ((Comparable) o1).compareTo(o2);
}
return 0;
}
}));
ColumnConfig columnConfig;
columnConfig = new ColumnConfig("name", Messages.get("label.name"), 500);
columnConfig.setFixed(true);
columnConfig.setRenderer(new TreeGridCellRenderer<GWTJahiaNode>());
ColumnConfig action = new ColumnConfig("action", Messages.get("label.action"), 100);
action.setAlignment(Style.HorizontalAlignment.RIGHT);
action.setRenderer(new GridCellRenderer() {
public Object render(ModelData modelData, String s, ColumnData columnData, int i, int i1,
ListStore listStore, Grid grid) {
Button button = new Button(Messages.get("label.remove"), new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent buttonEvent) {
final GWTJahiaNode node1 = (GWTJahiaNode) buttonEvent.getButton().getData("associatedNode");
tagStore.remove(node1);
newValues.get(TagsTabItem.this.locale).getValues().remove(new GWTJahiaNodePropertyValue(node1,
GWTJahiaNodePropertyType.WEAKREFERENCE));
}
});