use of com.extjs.gxt.ui.client.data.RpcProxy in project kura by eclipse.
the class NatConfigTab method initGrid.
private void initGrid() {
//
// Column Configuration
ColumnConfig column = null;
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
column = new ColumnConfig("inInterface", MSGS.firewallNatInInterface(), 60);
column.setAlignment(HorizontalAlignment.CENTER);
configs.add(column);
column = new ColumnConfig("outInterface", MSGS.firewallNatOutInterface(), 60);
column.setAlignment(HorizontalAlignment.CENTER);
configs.add(column);
column = new ColumnConfig("protocol", MSGS.firewallNatProtocol(), 60);
column.setAlignment(HorizontalAlignment.CENTER);
configs.add(column);
column = new ColumnConfig("sourceNetwork", MSGS.firewallNatSourceNetwork(), 120);
column.setAlignment(HorizontalAlignment.CENTER);
configs.add(column);
column = new ColumnConfig("destinationNetwork", MSGS.firewallNatDestinationNetwork(), 120);
column.setAlignment(HorizontalAlignment.CENTER);
configs.add(column);
column = new ColumnConfig("masquerade", MSGS.firewallNatMasquerade(), 60);
column.setAlignment(HorizontalAlignment.CENTER);
configs.add(column);
// rpc data proxy
RpcProxy<ListLoadResult<GwtFirewallNatEntry>> proxy = new RpcProxy<ListLoadResult<GwtFirewallNatEntry>>() {
@Override
protected void load(Object loadConfig, final AsyncCallback<ListLoadResult<GwtFirewallNatEntry>> callback) {
gwtXSRFService.generateSecurityToken(new AsyncCallback<GwtXSRFToken>() {
@Override
public void onFailure(Throwable ex) {
FailureHandler.handle(ex);
}
@Override
public void onSuccess(GwtXSRFToken token) {
gwtNetworkService.findDeviceFirewallNATs(token, callback);
}
});
}
};
m_loader = new BaseListLoader<ListLoadResult<GwtFirewallNatEntry>>(proxy);
m_loader.setSortDir(SortDir.DESC);
m_loader.setSortField("inInterface");
SwappableListStore<GwtFirewallNatEntry> m_store = new SwappableListStore<GwtFirewallNatEntry>(m_loader);
m_store.setKeyProvider(new ModelKeyProvider<GwtFirewallNatEntry>() {
public String getKey(GwtFirewallNatEntry firewallNatEntry) {
return firewallNatEntry.getInInterface();
}
});
m_grid = new Grid<GwtFirewallNatEntry>(m_store, new ColumnModel(configs));
m_grid.setBorders(false);
m_grid.setStateful(false);
m_grid.setLoadMask(true);
m_grid.setStripeRows(true);
m_grid.setAutoExpandColumn("inInterface");
m_grid.getView().setAutoFill(true);
m_loader.addLoadListener(new DataLoadListener(m_grid));
GridSelectionModel<GwtFirewallNatEntry> selectionModel = new GridSelectionModel<GwtFirewallNatEntry>();
selectionModel.setSelectionMode(SelectionMode.SINGLE);
m_grid.setSelectionModel(selectionModel);
m_grid.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<GwtFirewallNatEntry>() {
@Override
public void selectionChanged(SelectionChangedEvent<GwtFirewallNatEntry> se) {
m_selectedEntry = se.getSelectedItem();
if (m_selectedEntry != null) {
m_editButton.setEnabled(true);
m_deleteButton.setEnabled(true);
} else {
m_editButton.setEnabled(false);
m_deleteButton.setEnabled(false);
}
}
});
}
use of com.extjs.gxt.ui.client.data.RpcProxy in project jahia by Jahia.
the class SettingsTabItem method create.
@Override
public TabItem create(GWTSidePanelTab config) {
super.create(config);
tab.setLayout(new FitLayout());
tab.setId("JahiaGxtSettingsTab");
settingsPanel = new ContentPanel();
settingsPanel.setAnimCollapse(false);
settingsPanel.setHeadingHtml(Messages.get(label));
settingsPanel.setLayout(new FitLayout());
tab.add(settingsPanel);
LayoutContainer treeContainer = new LayoutContainer();
treeContainer.setBorders(false);
treeContainer.setScrollMode(Style.Scroll.AUTO);
treeContainer.setLayout(new FitLayout());
// resolve paths from dependencies
resetPaths();
nodesBySettingsPath = new HashMap<String, Set<GWTJahiaNode>>();
NodeColumnConfigList columns = new NodeColumnConfigList(Arrays.asList(new GWTColumn("displayName", "", -1)));
columns.init();
columns.get(0).setRenderer(new TreeGridCellRenderer<GWTJahiaNode>() {
@Override
protected String getText(TreeGrid<GWTJahiaNode> gwtJahiaNodeTreeGrid, GWTJahiaNode node, String property, int rowIndex, int colIndex) {
String v = node.get(property);
if (v != null) {
v = SafeHtmlUtils.htmlEscape(v);
}
return v;
}
});
final List<String> fields = new ArrayList<String>();
fields.add(GWTJahiaNode.LOCKS_INFO);
fields.add(GWTJahiaNode.PERMISSIONS);
fields.add(GWTJahiaNode.CHILDREN_INFO);
fields.add(GWTJahiaNode.ICON);
fields.add(GWTJahiaNode.LOCKS_INFO);
fields.add("j:requiredPermissionNames");
fields.add("j:requiredLicenseFeature");
fields.add("j:templateLink");
fields.add("j:hashLocation");
RpcProxy<List<GWTJahiaNode>> proxy = new RpcProxy<List<GWTJahiaNode>>() {
@Override
protected void load(Object loadConfig, final AsyncCallback<List<GWTJahiaNode>> callback) {
if (mainNode == null) {
return;
}
final AsyncCallback<List<GWTJahiaNode>> asyncCallback = new AsyncCallback<List<GWTJahiaNode>>() {
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
@Override
public void onSuccess(List<GWTJahiaNode> nodes) {
List<GWTJahiaNode> result = new ArrayList<GWTJahiaNode>();
for (GWTJahiaNode node : nodes) {
merge(result, node);
}
callback.onSuccess(result);
}
private void merge(List result, GWTJahiaNode node) {
String settingsPath = getSettingsPath(node);
Set<GWTJahiaNode> nodeSet = nodesBySettingsPath.get(settingsPath);
if (nodeSet == null) {
nodeSet = new HashSet<GWTJahiaNode>();
nodesBySettingsPath.put(settingsPath, nodeSet);
}
nodeSet.add(node);
String nodeName = node.getName();
boolean add = true;
for (Object data : result) {
GWTJahiaNode previousNode = (GWTJahiaNode) data;
if (previousNode.getName().equals(nodeName)) {
add = false;
if (previousNode.get("alternativePath") == null) {
previousNode.set("alternativePath", new ArrayList<String>());
}
((List<String>) previousNode.get("alternativePath")).add(node.getPath() + "/*");
for (ModelData child : node.getChildren()) {
merge(previousNode.getChildren(), (GWTJahiaNode) child);
}
}
}
if (node.getName().equals(MainModule.getInstance().getTemplate())) {
node.setSelectedOnLoad(true);
}
if (add) {
List<ModelData> all = new ArrayList<ModelData>(node.getChildren());
node.getChildren().clear();
for (ModelData child : all) {
merge(node.getChildren(), (GWTJahiaNode) child);
}
List<String> requiredPermissions = node.get("j:requiredPermissionNames");
boolean access = true;
if (requiredPermissions != null) {
for (String p : requiredPermissions) {
if (!PermissionsUtils.isPermitted(p, JahiaGWTParameters.getSiteNode())) {
access = false;
break;
}
}
}
node.set("hasAccessToSettings", Boolean.valueOf(access));
if (access) {
result.add(node);
}
}
}
};
if (loadConfig == null) {
JahiaContentManagementService.App.getInstance().getRoot(paths, Arrays.asList("jnt:template", "jnt:templateLink"), null, null, fields, factory.getSelectedPath(), factory.getOpenPath(), true, false, null, null, true, asyncCallback);
} else {
GWTJahiaNode gwtJahiaNode = (GWTJahiaNode) loadConfig;
if (gwtJahiaNode.isExpandOnLoad()) {
List<GWTJahiaNode> list = new ArrayList<GWTJahiaNode>();
for (ModelData modelData : gwtJahiaNode.getChildren()) {
list.add((GWTJahiaNode) modelData);
}
asyncCallback.onSuccess(list);
} else {
List<String> nodePaths = new ArrayList<String>();
nodePaths.add(gwtJahiaNode.getPath() + "/*");
List<String> alt = gwtJahiaNode.get("alternativePath");
if (alt != null) {
nodePaths.addAll(alt);
}
JahiaContentManagementService.App.getInstance().getRoot(nodePaths, Arrays.asList("jnt:template", "jnt:templateLink"), null, null, fields, factory.getSelectedPath(), factory.getOpenPath(), true, false, null, null, true, asyncCallback);
}
}
}
};
settingsLoader = new BaseTreeLoader<GWTJahiaNode>(proxy) {
@Override
public boolean hasChildren(GWTJahiaNode parent) {
return !parent.isNodeType("jnt:contentTemplate") && !parent.isNodeType("jnt:templateLink");
}
};
factory = new GWTJahiaNodeTreeFactory(settingsLoader, "settingsTab");
settingsStore = factory.getStore();
settingsStore.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;
}
}));
TreeGrid<GWTJahiaNode> settingsTree = factory.getTreeGrid(new ColumnModel(columns));
settingsTree.setAutoExpandColumn("displayName");
settingsTree.getTreeView().setRowHeight(25);
settingsTree.getTreeView().setForceFit(true);
settingsTree.setHeight("100%");
settingsTree.setIconProvider(ContentModelIconProvider.getInstance());
treeContainer.add(settingsTree);
settingsTree.setHideHeaders(true);
settingsTree.setAutoExpand(false);
// get List of site settings
settingsTree.setSelectionModel(new TreeGridSelectionModel<GWTJahiaNode>() {
@Override
protected void handleMouseClick(GridEvent<GWTJahiaNode> e) {
super.handleMouseClick(e);
final String path = settingPath.replaceAll("\\$site", JahiaGWTParameters.getSiteNode().getPath()).replaceAll("\\$user", JahiaGWTParameters.getCurrentUserPath());
if (e.getModel().isNodeType("jnt:contentTemplate") && !Boolean.FALSE.equals(e.getModel().get("hasAccessToSettings"))) {
MainModule.staticGoTo(path, getSelectedItem().getName(), "generic", "");
} else if (e.getModel().isNodeType("jnt:templateLink")) {
MainModule.getInstance().resetFramePosition();
String url = MainModule.getInstance().getUrl(path, (String) e.getModel().get("j:templateLink"), "generic", "", false) + "#" + e.getModel().get("j:hashLocation");
MainModule.getInstance().goToSettingsUrl(url);
}
}
});
VBoxLayoutData treeVBoxData = new VBoxLayoutData();
treeVBoxData.setFlex(1);
settingsPanel.add(treeContainer, treeVBoxData);
return tab;
}
use of com.extjs.gxt.ui.client.data.RpcProxy in project jahia by Jahia.
the class TemplatesTabItem method create.
/**
* Performs the creation of the tab item and populates its content. The tab contains two panes: one with the tree of templates,
* available in the module, and the second pane with the detail structure of the template content.
*
* @param config
* the tab configuration
* @return the created tab item
*/
@Override
public TabItem create(GWTSidePanelTab config) {
super.create(config);
this.tree.setSelectionModel(new TreeGridSelectionModel<GWTJahiaNode>() {
@Override
protected void handleMouseClick(GridEvent<GWTJahiaNode> e) {
super.handleMouseClick(e);
if (!getSelectedItem().getPath().equals(editLinker.getMainModule().getPath())) {
if (!getSelectedItem().getNodeTypes().contains("jnt:virtualsite") && !getSelectedItem().getNodeTypes().contains("jnt:templatesFolder")) {
MainModule.staticGoTo(getSelectedItem().getPath(), null);
}
}
}
});
this.tree.getSelectionModel().setSelectionMode(Style.SelectionMode.SINGLE);
this.tree.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<GWTJahiaNode>() {
@Override
public void selectionChanged(SelectionChangedEvent<GWTJahiaNode> se) {
detailTree.getSelectionModel().deselectAll();
if (se.getSelectedItem() != null) {
detailLoader.load(se.getSelectedItem());
} else {
detailStore.removeAll();
}
}
});
tree.setContextMenu(createContextMenu(config.getTreeContextMenu(), tree.getSelectionModel()));
selectMainNodeTreeLoadListener = new SelectMainNodeTreeLoadListener(tree);
NodeColumnConfigList columns = new NodeColumnConfigList(config.getTreeColumns());
columns.init();
columns.get(0).setRenderer(NodeColumnConfigList.NAME_TREEGRID_RENDERER);
RpcProxy<List<GWTJahiaNode>> proxy = new RpcProxy<List<GWTJahiaNode>>() {
@Override
protected void load(Object currentPage, final AsyncCallback<List<GWTJahiaNode>> callback) {
if (currentPage != null) {
GWTJahiaNode gwtJahiaNode = (GWTJahiaNode) currentPage;
List<String> fields = new ArrayList<String>();
fields.add(GWTJahiaNode.LOCKS_INFO);
fields.add(GWTJahiaNode.PERMISSIONS);
fields.add(GWTJahiaNode.CHILDREN_INFO);
fields.add(GWTJahiaNode.ICON);
JahiaContentManagementService.App.getInstance().lsLoad(gwtJahiaNode.getPath(), displayedDetailTypes, null, null, fields, false, 0, 0, false, hiddenDetailTypes, null, false, false, new AsyncCallback<PagingLoadResult<GWTJahiaNode>>() {
@Override
public void onFailure(Throwable caught) {
callback.onFailure(caught);
}
@Override
public void onSuccess(PagingLoadResult<GWTJahiaNode> nodes) {
callback.onSuccess(nodes.getData());
}
});
}
}
};
detailLoader = new BaseTreeLoader<GWTJahiaNode>(proxy) {
@Override
public boolean hasChildren(GWTJahiaNode parent) {
return parent.hasChildren();
}
};
detailStore = new TreeStore<GWTJahiaNode>(detailLoader);
detailTree = new TreeGrid<GWTJahiaNode>(detailStore, new ColumnModel(columns));
detailTree.setAutoExpandColumn("displayName");
detailTree.getTreeView().setRowHeight(25);
detailTree.getTreeView().setForceFit(true);
detailTree.setHeight("100%");
detailTree.setIconProvider(ContentModelIconProvider.getInstance());
detailTree.setAutoExpand(true);
detailTree.setContextMenu(createContextMenu(config.getTableContextMenu(), detailTree.getSelectionModel()));
detailTree.setView(new TreeGridView() {
@Override
protected void handleComponentEvent(GridEvent ge) {
switch(ge.getEventTypeInt()) {
case Event.ONMOUSEOVER:
GWTJahiaNode selection = (GWTJahiaNode) ge.getModel();
if (selection != null) {
List<Module> modules = ModuleHelper.getModulesByPath().get(selection.getPath());
if (modules != null) {
for (Module module : modules) {
Hover.getInstance().addHover(module, ge);
}
}
}
break;
case Event.ONMOUSEOUT:
selection = (GWTJahiaNode) ge.getModel();
if (selection != null) {
List<Module> modules = ModuleHelper.getModulesByPath().get(selection.getPath());
if (modules != null) {
for (Module module : modules) {
Hover.getInstance().removeHover(module);
}
}
}
break;
}
editLinker.getMainModule().setCtrlActive(ge);
super.handleComponentEvent(ge);
}
});
detailTree.getSelectionModel().addSelectionChangedListener(new SelectionChangedListener<GWTJahiaNode>() {
@Override
public void selectionChanged(SelectionChangedEvent<GWTJahiaNode> se) {
if (se.getSelection() != null) {
for (GWTJahiaNode selection : se.getSelection()) {
List<Module> modules = ModuleHelper.getModulesByPath().get(selection.getPath());
if (modules != null) {
for (Module module : modules) {
if (!editLinker.getMainModule().getSelections().containsKey(module)) {
editLinker.getMainModule().handleNewModuleSelection(module);
}
}
}
}
}
}
});
contentContainer = new LayoutContainer();
contentContainer.setBorders(false);
contentContainer.setScrollMode(Style.Scroll.AUTO);
contentContainer.setLayout(new FitLayout());
contentContainer.setTitle(Messages.get("label.detail", "detail"));
contentContainer.add(detailTree);
VBoxLayoutData contentVBoxData = new VBoxLayoutData();
contentVBoxData.setFlex(2);
tab.add(contentContainer, contentVBoxData);
return tab;
}
use of com.extjs.gxt.ui.client.data.RpcProxy in project jahia by Jahia.
the class CustomizedPreviewActionItem method onComponentSelection.
@Override
public void onComponentSelection() {
final Window window = new Window();
window.addStyleName("customized-preview");
window.setSize(500, 430);
window.setPlain(true);
window.setModal(true);
window.setBlinkModal(true);
window.setBorders(false);
window.setHeadingHtml(Messages.get("label.preview.window.title", "Customized preview"));
window.setLayout(new FitLayout());
window.setButtonAlign(Style.HorizontalAlignment.CENTER);
window.setBodyBorder(false);
// data proxy
RpcProxy<PagingLoadResult<GWTJahiaNode>> proxy = new RpcProxy<PagingLoadResult<GWTJahiaNode>>() {
@Override
protected void load(Object pageLoaderConfig, AsyncCallback<PagingLoadResult<GWTJahiaNode>> callback) {
if (userSearchField != null) {
String newSearch = userSearchField.getText().trim().replace("'", "''");
String query = "select * from [jnt:user] as u where (isdescendantnode(u,'/users/') or isdescendantnode(u,'/sites/" + JahiaGWTParameters.getSiteKey().replace("'", "''") + "/users/'))";
if (newSearch.length() > 0) {
query += " and (CONTAINS(u.*,'*" + newSearch + "*') OR LOWER(u.[j:nodename]) LIKE '*" + newSearch.toLowerCase() + "*') ";
}
query += " ORDER BY u.[j:nodename]";
// reset offset to 0 if the search value has changed
int offset = lastUserSearchValue != null && lastUserSearchValue.equals(newSearch) ? ((PagingLoadConfig) pageLoaderConfig).getOffset() : 0;
final JahiaContentManagementServiceAsync service = JahiaContentManagementService.App.getInstance();
service.searchSQL(query, ((PagingLoadConfig) pageLoaderConfig).getLimit(), offset, null, GWTJahiaNode.DEFAULT_USER_FIELDS, false, callback);
// remember last searched value
lastUserSearchValue = newSearch;
}
}
};
final BasePagingLoader<PagingLoadResult<GWTJahiaNode>> loader = new BasePagingLoader<PagingLoadResult<GWTJahiaNode>>(proxy);
userSearchField = new SearchField(Messages.get("label.search", "Search: "), false) {
@Override
public void onFieldValidation(String value) {
loader.load();
}
@Override
public void onSaveButtonClicked(String value) {
}
};
userSearchField.setWidth(490);
loader.setLimit(10);
loader.load();
HorizontalPanel panel = new HorizontalPanel();
panel.add(userSearchField);
ListStore<GWTJahiaNode> store = new ListStore<GWTJahiaNode>(loader);
List<ColumnConfig> columns = new ArrayList<ColumnConfig>();
columns.add(new ColumnConfig("displayName", Messages.get("label.username", "User name"), 150));
columns.add(new ColumnConfig("j:lastName", Messages.get("label.lastName", "Last name"), 130));
columns.add(new ColumnConfig("j:firstName", Messages.get("label.firstName", "First name"), 130));
// columns.add(new ColumnConfig("siteName", "Site name", 80));
columns.add(new ColumnConfig("providerKey", Messages.get("column.provider.label", "Provider"), 75));
// columns.add(new ColumnConfig("email", "Email", 100));
ColumnModel cm = new ColumnModel(columns);
final PagingToolBar toolBar = new PagingToolBar(10);
toolBar.bind(loader);
toolBar.setBorders(false);
toolBar.setWidth(480);
userGrid = new Grid<GWTJahiaNode>(store, cm);
userGrid.getSelectionModel().setSelectionMode(Style.SelectionMode.SINGLE);
userGrid.setLoadMask(true);
userGrid.setBorders(false);
userGrid.setHeight(250);
userGrid.setWidth(490);
VerticalPanel verticalPanel = new VerticalPanel();
verticalPanel.add(userGrid);
verticalPanel.add(toolBar);
window.setTopComponent(panel);
panel = new HorizontalPanel();
panel.setTableHeight("30px");
panel.setVerticalAlign(Style.VerticalAlignment.BOTTOM);
Label label = new Label(" " + Messages.get("label.preview.window.date", "Pick a date for the preview") + " ");
label.setWidth(200);
label.setLabelFor("previewDate");
final Date date = new Date();
final CalendarField calendarField = new CalendarField("yyyy-MM-dd HH:mm", true, false, "previewDate", false, date);
panel.add(label);
panel.add(calendarField);
verticalPanel.add(panel);
window.add(verticalPanel);
// Channel selector
panel = new HorizontalPanel();
panel.setTableHeight("30px");
panel.setVerticalAlign(Style.VerticalAlignment.BOTTOM);
label = new Label(" " + Messages.get("label.preview.window.channel", "Channel") + " ");
label.setLabelFor("previewChannel");
// we will setup the right elements now because we will need to reference them in the event listener
final Label orientationLabel = new Label(" " + Messages.get("label.preview.window.channelOrientation", "Orientation") + " ");
orientationLabel.setLabelFor("previewChannelOrientation");
orientationLabel.hide();
final ListStore<GWTJahiaBasicDataBean> orientations = new ListStore<GWTJahiaBasicDataBean>();
final ComboBox<GWTJahiaBasicDataBean> orientationCombo = new ComboBox<GWTJahiaBasicDataBean>();
orientationCombo.setDisplayField("displayName");
orientationCombo.setName("previewChannelOrientation");
orientationCombo.setStore(orientations);
orientationCombo.setTypeAhead(true);
orientationCombo.setTriggerAction(TriggerAction.ALL);
orientationCombo.hide();
// now we can setup the channel selection combo box
final ListStore<GWTJahiaChannel> states = new ListStore<GWTJahiaChannel>();
final ComboBox<GWTJahiaChannel> combo = new ComboBox<GWTJahiaChannel>();
JahiaContentManagementServiceAsync contentService = JahiaContentManagementService.App.getInstance();
contentService.getChannels(new BaseAsyncCallback<List<GWTJahiaChannel>>() {
public void onSuccess(List<GWTJahiaChannel> result) {
states.add(result);
combo.setStore(states);
}
});
combo.setDisplayField("display");
combo.setName("previewChannel");
combo.setStore(states);
combo.setTypeAhead(true);
combo.setTriggerAction(TriggerAction.ALL);
combo.addSelectionChangedListener(new SelectionChangedListener<GWTJahiaChannel>() {
@Override
public void selectionChanged(SelectionChangedEvent<GWTJahiaChannel> event) {
GWTJahiaChannel selectedChannel = event.getSelectedItem();
Map<String, String> capabilities = selectedChannel.getCapabilities();
if (capabilities != null && capabilities.containsKey("variants")) {
String[] variants = capabilities.get("variants").split(",");
String[] displayNames = null;
if (capabilities.containsKey("variants-displayNames")) {
displayNames = capabilities.get("variants-displayNames").split(",");
}
ListStore<GWTJahiaBasicDataBean> orientations = orientationCombo.getStore();
orientations.removeAll();
for (int i = 0; i < variants.length; i++) {
String displayName = (displayNames == null ? variants[i] : displayNames[i]);
orientations.add(new GWTJahiaBasicDataBean(variants[i], displayName));
}
orientationCombo.setValue(orientations.getAt(0));
orientationLabel.show();
orientationCombo.show();
} else {
orientationLabel.hide();
orientationCombo.hide();
}
}
});
panel.add(label);
panel.add(combo);
panel.add(orientationLabel);
panel.add(orientationCombo);
verticalPanel.add(panel);
window.add(verticalPanel);
Button ok = new Button(Messages.get("label.preview.window.confirm", "Show customized preview"));
ok.addStyleName("button-preview");
ok.addSelectionListener(new SelectionListener<ButtonEvent>() {
@Override
public void componentSelected(ButtonEvent buttonEvent) {
final GWTJahiaNode node = linker.getSelectionContext().getMainNode();
if (node != null) {
String path = node.getPath();
String locale = JahiaGWTParameters.getLanguage();
JahiaContentManagementService.App.getInstance().getNodeURL(null, path, null, null, "default", locale, false, new BaseAsyncCallback<String>() {
@Override
public void onSuccess(String url) {
GWTJahiaNode selectedItem = userGrid.getSelectionModel().getSelectedItem();
String alias = null;
List<String> urlParameters = new ArrayList<String>();
if (selectedItem != null) {
alias = "alias=" + selectedItem.getName();
urlParameters.add(alias);
}
String previewDate = null;
if (calendarField.getValue().after(date)) {
previewDate = "prevdate=" + calendarField.getValue().getTime();
urlParameters.add(previewDate);
}
GWTJahiaChannel channel = combo.getValue();
String windowFeatures = null;
if ((channel != null) && (!"default".equals(channel.getValue()))) {
urlParameters.add("channel=" + channel.getValue());
Map<String, String> capabilities = channel.getCapabilities();
if (capabilities != null && capabilities.containsKey("variants")) {
int variantIndex = 0;
String[] variants = capabilities.get("variants").split(",");
String variant = orientationCombo.getValue().getValue();
urlParameters.add("variant=" + variant);
for (int i = 0; i < variants.length; i++) {
if (variants[i].equals(variant)) {
variantIndex = i;
break;
}
}
int[] imageSize = channel.getVariantDecoratorImageSize(variantIndex);
windowFeatures = "resizable=no,status=no,menubar=no,toolbar=no,width=" + imageSize[0] + ",height=" + imageSize[1];
}
}
StringBuilder urlParams = new StringBuilder();
for (int i = 0; i < urlParameters.size(); i++) {
if (i == 0) {
urlParams.append("?");
}
urlParams.append(urlParameters.get(i));
if (i < urlParameters.size() - 1) {
urlParams.append("&");
}
}
String url1 = url + urlParams.toString();
openWindow(url1, "customizedpreview", windowFeatures != null ? windowFeatures : defaultWindowOptions);
}
});
}
}
});
window.setBottomComponent(ok);
window.show();
}
use of com.extjs.gxt.ui.client.data.RpcProxy 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