use of com.extjs.gxt.ui.client.widget.treegrid.TreeGrid in project jahia by Jahia.
the class NewViewActionItem method newView.
@SuppressWarnings("unchecked")
private void newView(final Linker linker, boolean isLoading) {
final GWTJahiaNode selectedNode = linker.getSelectionContext().getSingleSelection();
if (selectedNode.getNodeTypes().contains("jnt:moduleVersionFolder")) {
// Open popup to select nodeType
ArrayList<String> paths = new ArrayList<String>();
paths.add(JahiaGWTParameters.getSiteNode().getPath());
for (String s : (List<String>) JahiaGWTParameters.getSiteNode().getProperties().get("j:resolvedDependencies")) {
for (GWTJahiaNode n : JahiaGWTParameters.getSitesMap().values()) {
if (n.getName().equals(s)) {
paths.add(n.getPath());
}
}
}
if (!isLoading) {
linker.loading(Messages.get("label.loading", "Loading"));
}
JahiaContentManagementService.App.getInstance().getContentTypesAsTree(Arrays.asList("nt:base"), null, true, new BaseAsyncCallback<List<GWTJahiaNodeType>>() {
@Override
public void onSuccess(List<GWTJahiaNodeType> result) {
linker.loaded();
final com.extjs.gxt.ui.client.widget.Window popup = new com.extjs.gxt.ui.client.widget.Window();
popup.addStyleName("new-view-modal");
popup.setHeadingHtml(Messages.get("label.addView", "Add view"));
popup.setHeight(400);
popup.setWidth(350);
popup.setModal(true);
popup.setLayout(new FillLayout());
ContentTypeTree contentTypeTree = new ContentTypeTree();
contentTypeTree.fillStore(result);
TreeGrid<?> treeGrid = contentTypeTree.getTreeGrid();
treeGrid.sinkEvents(Event.ONDBLCLICK + Event.ONCLICK);
treeGrid.addListener(Events.OnDoubleClick, new Listener<TreeGridEvent<GWTJahiaNodeType>>() {
public void handleEvent(TreeGridEvent<GWTJahiaNodeType> baseEvent) {
GWTJahiaNodeType gwtJahiaNodeType = baseEvent.getModel();
if (gwtJahiaNodeType != null && linker != null) {
GWTJahiaNodeType engineNodeType = TEMPLATE.equals(gwtJahiaNodeType.getName()) ? fileNodeTypes.get(TEMPLATE_FILE) : fileNodeTypes.get(VIEW_FILE);
createEngine(engineNodeType, selectedNode, gwtJahiaNodeType.getName());
popup.hide();
}
}
});
popup.add(contentTypeTree);
popup.show();
}
@Override
public void onFailure(Throwable caught) {
linker.loaded();
super.onFailure(caught);
}
});
} else {
if (isLoading) {
linker.loaded();
}
GWTJahiaNodeType fileNodeType = TEMPLATE.equals(findNodeType(selectedNode)) ? fileNodeTypes.get(TEMPLATE_FILE) : fileNodeTypes.get(VIEW_FILE);
createEngine(fileNodeType, selectedNode, findNodeType(selectedNode));
}
}
use of com.extjs.gxt.ui.client.widget.treegrid.TreeGrid in project jahia by Jahia.
the class WorkflowHistoryPanel method init.
private void init() {
setBorders(false);
removeAll();
final JahiaContentManagementServiceAsync service = JahiaContentManagementService.App.getInstance();
// data proxy
RpcProxy<List<GWTJahiaWorkflowHistoryItem>> proxy = new RpcProxy<List<GWTJahiaWorkflowHistoryItem>>() {
@Override
protected void load(Object loadConfig, AsyncCallback<List<GWTJahiaWorkflowHistoryItem>> callback) {
if (loadConfig == null) {
if (dashboard) {
service.getWorkflowHistoryForUser(callback);
} else {
service.getWorkflowHistoryProcesses(nodeId, locale, callback);
}
} else if (loadConfig instanceof GWTJahiaWorkflowHistoryProcess) {
final GWTJahiaWorkflowHistoryProcess process = (GWTJahiaWorkflowHistoryProcess) loadConfig;
service.getWorkflowHistoryTasks(process.getProvider(), process.getProcessId(), callback);
} else {
callback.onSuccess(new ArrayList<GWTJahiaWorkflowHistoryItem>());
}
}
};
// tree loader
final TreeLoader<GWTJahiaWorkflowHistoryItem> loader = new BaseTreeLoader<GWTJahiaWorkflowHistoryItem>(proxy) {
@Override
public boolean hasChildren(GWTJahiaWorkflowHistoryItem parent) {
return parent instanceof GWTJahiaWorkflowHistoryProcess;
}
};
// trees store
final TreeStore<GWTJahiaWorkflowHistoryItem> store = new TreeStore<GWTJahiaWorkflowHistoryItem>(loader);
store.setStoreSorter(new StoreSorter<GWTJahiaWorkflowHistoryItem>() {
@Override
public int compare(Store<GWTJahiaWorkflowHistoryItem> store, GWTJahiaWorkflowHistoryItem m1, GWTJahiaWorkflowHistoryItem m2, String property) {
return m1.getStartDate().compareTo(m2.getStartDate());
}
});
List<ColumnConfig> config = new ArrayList<ColumnConfig>();
ColumnConfig column = new ColumnConfig("displayName", Messages.get("label.name", "Name"), 400);
column.setRenderer(new WidgetTreeGridCellRenderer<GWTJahiaWorkflowHistoryItem>() {
@Override
public Widget getWidget(GWTJahiaWorkflowHistoryItem historyItem, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GWTJahiaWorkflowHistoryItem> gwtJahiaWorkflowHistoryItemListStore, Grid<GWTJahiaWorkflowHistoryItem> grid) {
if (dashboard && historyItem instanceof GWTJahiaWorkflowHistoryTask) {
final GWTJahiaWorkflowHistoryProcess parent = (GWTJahiaWorkflowHistoryProcess) ((TreeGrid<GWTJahiaWorkflowHistoryItem>) grid).getTreeStore().getParent(historyItem);
for (final GWTJahiaWorkflowTask task : parent.getAvailableTasks()) {
if (task.getId().equals(historyItem.getId())) {
Button b = new Button(historyItem.<String>get("displayName"));
b.addStyleName("button-details");
b.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
EngineWindow container = new EngineWindow();
container.setClosable(false);
container.setMaximizable(false);
container.setMinimizable(false);
container.addStyleName("workflow-dashboard-publication-window");
container.setId("workflow-dashboard-publication-window");
// get path from the publication info, not used for unpublished
CustomWorkflow customWorkflowInfo = parent.getRunningWorkflow().getCustomWorkflowInfo();
String path = "";
if (customWorkflowInfo instanceof PublicationWorkflow && ((PublicationWorkflow) customWorkflowInfo).getPublicationInfos().size() > 0) {
path = ((PublicationWorkflow) customWorkflowInfo).getPublicationInfos().get(0).getMainPath();
}
new WorkflowActionDialog(path, parent.getRunningWorkflow(), task, linker, customWorkflowInfo, container);
container.showEngine();
final RootPanel rootPanel = RootPanel.get("workflowComponent");
final ContentPanel rootPanelWidget = (ContentPanel) rootPanel.getWidget(0);
// rootPanelWidget.hide();
container.addListener(Events.Hide, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
rootPanelWidget.show();
init();
layout(true);
}
});
rootPanel.add(container.getPanel());
}
});
return b;
}
}
}
return new Label(historyItem.<String>get("displayName"));
}
});
config.add(column);
column = new ColumnConfig("locale", 80);
column.setRenderer(new GridCellRenderer<ModelData>() {
@Override
public Object render(ModelData historyItem, String property, ColumnData config, int rowIndex, int colIndex, ListStore<ModelData> store, Grid<ModelData> grid) {
if (dashboard && historyItem.get("workflow") instanceof GWTJahiaWorkflow) {
String lang = ((GWTJahiaWorkflow) historyItem.get("workflow")).get("locale");
if (lang != null && JahiaGWTParameters.getLanguage(lang) != null) {
return "<img src=\"" + JahiaGWTParameters.getLanguage(lang).getImage() + "\"/> ";
}
}
return "";
}
});
config.add(column);
column = new ColumnConfig("user", Messages.get("label.user", "User"), 140);
config.add(column);
column = new ColumnConfig("nodeWrapper", Messages.get("label.workflow.start.node", "Workflow Starting Node"), 400);
column.setRenderer(new GridCellRenderer<GWTJahiaWorkflowHistoryItem>() {
/**
* Returns the HTML to be used in a grid cell.
*
* @param model the model
* @param property the model property
* @param config the column config
* @param rowIndex the row index
* @param colIndex the cell index
* @param store the data store
* @param grid the grid
* @return the cell HTML or Component instance
*/
@Override
public Object render(GWTJahiaWorkflowHistoryItem model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GWTJahiaWorkflowHistoryItem> store, Grid<GWTJahiaWorkflowHistoryItem> grid) {
final GWTJahiaNode wrapper = (GWTJahiaNode) model.getProperties().get("nodeWrapper");
if (wrapper != null) {
return new Label(wrapper.getDisplayName() + " (" + wrapper.getPath() + ")");
}
List<GWTJahiaWorkflowHistoryItem> models = store.getModels();
for (final GWTJahiaWorkflowHistoryItem historyItem : models) {
final GWTJahiaNode nodewrapper = (GWTJahiaNode) historyItem.getProperties().get("nodeWrapper");
if (nodewrapper != null && historyItem.getProcessId().equals(model.getProcessId()) && historyItem instanceof GWTJahiaWorkflowHistoryProcess) {
ButtonBar buttonBar = new ButtonBar();
Button previewButton = new Button(Messages.get("label.preview"));
previewButton.addStyleName("button-preview");
previewButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
String path = nodewrapper.getPath();
String locale = nodewrapper.getLanguageCode();
JahiaContentManagementService.App.getInstance().getNodeURL("render", path, null, null, "default", locale, false, new BaseAsyncCallback<String>() {
@Override
public void onSuccess(String url) {
Window window = new Window();
window.addStyleName("content-preview");
window.setMaximizable(true);
window.setSize(800, 600);
window.setUrl(url);
// window.setPosition(engine.getPosition(true).x + 50, engine.getPosition(true).y + 50);
window.show();
}
});
}
});
buttonBar.add(previewButton);
Button inContextButton = new Button(Messages.get("label.preview.context"));
inContextButton.addStyleName("button-incontext-preview");
inContextButton.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
String path = nodewrapper.getPath();
String locale = JahiaGWTParameters.getLanguage();
JahiaContentManagementService.App.getInstance().getNodeURL("render", path, null, null, "default", locale, true, new BaseAsyncCallback<String>() {
@Override
public void onSuccess(String url) {
Window window = new Window();
window.addStyleName("content-incontext-preview");
window.setMaximizable(true);
window.setSize(1000, 750);
window.setUrl(url);
// window.setPosition(engine.getPosition(true).x + 50, engine.getPosition(true).y + 50);
window.show();
}
});
}
});
buttonBar.add(inContextButton);
return buttonBar;
}
}
return new Label("");
}
});
config.add(column);
column = new ColumnConfig("startDate", Messages.get("org.jahia.engines.processDisplay.tab.startdate", "Start date"), 150);
column.setDateTimeFormat(Formatter.DEFAULT_DATETIME_FORMAT);
config.add(column);
column = new ColumnConfig("endDate", Messages.get("org.jahia.engines.processDisplay.tab.enddate", "End date"), 150);
column.setDateTimeFormat(Formatter.DEFAULT_DATETIME_FORMAT);
config.add(column);
column = new ColumnConfig("duration", Messages.get("org.jahia.engines.processDisplay.column.duration", "Duration"), 80);
column.setRenderer(new GridCellRenderer<GWTJahiaWorkflowHistoryItem>() {
@Override
public Object render(GWTJahiaWorkflowHistoryItem historyItem, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GWTJahiaWorkflowHistoryItem> store, Grid<GWTJahiaWorkflowHistoryItem> grid) {
Long duration = historyItem.getDuration();
String display = "-";
if (duration != null) {
long time = duration.longValue();
if (time < 1000) {
display = time + " " + Messages.get("label.milliseconds", "ms");
} else if (time < 1000 * 60L) {
display = ((long) (time / 1000)) + " " + Messages.get("label.seconds", "sec");
} else if (time < 1000 * 60 * 60L) {
display = ((long) (time / (1000 * 60L))) + " " + Messages.get("label.minutes", "min") + " " + ((long) ((time % (1000 * 60L)) / 1000)) + " " + Messages.get("label.seconds", "sec");
} else {
display = ((long) (time / (1000 * 60 * 60L))) + " " + Messages.get("label_hours", "h") + " " + ((long) ((time % (1000 * 60 * 60L)) / (1000 * 60L))) + " " + Messages.get("label.minutes", "min");
}
}
return new Label(display);
}
});
config.add(column);
if (PermissionsUtils.isPermitted("viewWorkflowTab", JahiaGWTParameters.getSiteNode().getPermissions())) {
column = new ColumnConfig("operation", Messages.get("label.operation", "Operation"), 150);
column.setRenderer(new GridCellRenderer<GWTJahiaWorkflowHistoryItem>() {
@Override
public Object render(final GWTJahiaWorkflowHistoryItem model, String property, ColumnData config, int rowIndex, int colIndex, ListStore<GWTJahiaWorkflowHistoryItem> gwtJahiaWorkflowHistoryItemListStore, Grid<GWTJahiaWorkflowHistoryItem> gwtJahiaWorkflowHistoryItemGrid) {
if (model instanceof GWTJahiaWorkflowHistoryProcess && !((GWTJahiaWorkflowHistoryProcess) model).isFinished()) {
Button button = new Button(Messages.get("label.abort", "Abort"));
button.addStyleName("button-abort");
button.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent ce) {
JahiaContentManagementService.App.getInstance().abortWorkflow(model.getId(), model.getProvider(), new BaseAsyncCallback<String>() {
@Override
public void onSuccess(String url) {
store.removeAll();
loader.load();
}
});
}
});
button.setIcon(StandardIconsProvider.STANDARD_ICONS.delete());
return button;
}
return new Label("");
}
});
config.add(column);
}
ColumnModel cm = new ColumnModel(config);
final TreeGrid<GWTJahiaWorkflowHistoryItem> tree = new TreeGrid<GWTJahiaWorkflowHistoryItem>(store, cm);
tree.setStateful(true);
tree.setBorders(true);
tree.getStyle().setNodeOpenIcon(StandardIconsProvider.STANDARD_ICONS.workflow());
tree.getStyle().setNodeCloseIcon(StandardIconsProvider.STANDARD_ICONS.workflow());
tree.getStyle().setLeafIcon(StandardIconsProvider.STANDARD_ICONS.workflowTask());
tree.setAutoExpandColumn("displayName");
tree.getTreeView().setRowHeight(25);
tree.setTrackMouseOver(false);
tree.setAutoExpandMax(1000);
add(tree);
listener = new Poller.PollListener<TaskEvent>() {
@Override
public void handlePollingResult(TaskEvent result) {
if (result.getEndedTask() != null) {
for (GWTJahiaWorkflowHistoryItem item : new ArrayList<GWTJahiaWorkflowHistoryItem>(store.getAllItems())) {
if (item instanceof GWTJahiaWorkflowHistoryProcess) {
for (GWTJahiaWorkflowTask task : new ArrayList<GWTJahiaWorkflowTask>(item.getAvailableTasks())) {
if (task.getId().equals(result.getEndedTask())) {
item.getAvailableTasks().remove(task);
}
}
if (item.getAvailableTasks().isEmpty()) {
store.remove(item);
}
} else if (item instanceof GWTJahiaWorkflowHistoryTask && item.getId().equals(result.getEndedTask())) {
store.remove(item);
}
}
}
}
};
Poller.getInstance().registerListener(listener, TaskEvent.class);
if (engine != null) {
engine.addListener(Events.Hide, new Listener<BaseEvent>() {
@Override
public void handleEvent(BaseEvent be) {
if (listener != null) {
Poller.getInstance().unregisterListener(listener, TaskEvent.class);
}
}
});
}
}
Aggregations