Example usage for com.google.gwt.user.client Window prompt

List of usage examples for com.google.gwt.user.client Window prompt

Introduction

In this page you can find the example usage for com.google.gwt.user.client Window prompt.

Prototype

public static String prompt(String msg, String initialValue) 

Source Link

Usage

From source file:org.jahia.ajax.gwt.client.util.content.actions.ContentActions.java

License:Open Source License

/**
 * Create a node./*  w  ww  . j av  a2 s  . c om*/
 *
 * @param nodeName the name of the node to be created
 * @param linker
 * @param windowHeader
 * @param nodeType
 * @param mixins
 * @param nodeProperties 
 * @param useMainNode
 */
public static void createNode(final String nodeName, final Linker linker, final String windowHeader,
        final String nodeType, List<String> mixins, List<GWTJahiaNodeProperty> nodeProperties,
        boolean useMainNode) {
    GWTJahiaNode parent;
    if (useMainNode) {
        parent = linker.getSelectionContext().getMainNode();
    } else {
        parent = linker.getSelectionContext().getSingleSelection();
    }
    if (parent != null) {
        // if node name is provided, use it; otherwise prompt for it
        boolean isNodeNameProvided = nodeName != null && nodeName.length() > 0;
        String name = isNodeNameProvided ? nodeName : Window.prompt(windowHeader, "untitled");
        if (name != null && name.length() > 0) {
            linker.loading(Messages.get("statusbar.newfoldering.label"));
            JahiaContentManagementService.App.getInstance().createNode(parent.getPath(), name, nodeType, mixins,
                    null, nodeProperties, null, null, null, !isNodeNameProvided,
                    new BaseAsyncCallback<GWTJahiaNode>() {
                        public void onSuccess(GWTJahiaNode node) {
                            linker.setSelectPathAfterDataUpdate(Arrays.asList(node.getPath()));
                            linker.loaded();
                            Map<String, Object> data = new HashMap<String, Object>();
                            data.put("node", node);
                            if (linker instanceof ManagerLinker) {
                                data.put(Linker.REFRESH_MAIN, "true");
                            }
                            linker.refresh(data);
                        }

                        public void onApplicationFailure(Throwable throwable) {
                            Log.error("Unable to create [" + nodeType + "]", throwable);
                            linker.loaded();
                        }
                    });
        }
    }
}

From source file:org.jahia.ajax.gwt.client.widget.content.ContentRepositoryTabs.java

License:Open Source License

/**
 * Rename Search/*from   w ww.  j  a  va  2s.  c  o m*/
 *
 * @param selection
 */
private void renameSearch(GWTJahiaNode selection) {
    if (selection != null) {
        if (selection.isLocked()) {
            Window.alert(selection.getName() + " is locked");
            return;
        }
        String newName = Window.prompt("Enter the new name for "
                + (selection.isFile().booleanValue() ? "file " : "folder ") + selection.getName(),
                selection.getName());
        if (newName != null && newName.length() > 0 && !newName.equals(selection.getName())) {
            service.rename(selection.getPath(), newName, new BaseAsyncCallback<GWTJahiaNode>() {
                public void onApplicationFailure(Throwable throwable) {
                    Window.alert("Rename failed\n\n" + throwable.getLocalizedMessage());
                }

                public void onSuccess(GWTJahiaNode o) {
                    retrieveSavedSearch();
                }
            });
        }
    }
}

From source file:org.jahia.ajax.gwt.client.widget.content.ContentSearchForm.java

License:Open Source License

/**
 * Save search/*from w w w . j  ava  2  s .  c  o  m*/
 */
public void saveSearch() {
    GWTJahiaSearchQuery query = getCurrentQuery();
    if (query != null && query.getQuery().length() > 0) {
        String name = Window.prompt(Messages.get("saveSearchName.label", "Please enter a name for this search"),
                JCRClientUtils.cleanUpFilename(query.getQuery()));
        if (name != null && name.length() > 0) {
            name = JCRClientUtils.cleanUpFilename(name);
            final JahiaContentManagementServiceAsync service = JahiaContentManagementService.App.getInstance();
            service.saveSearch(query, null, name, false, new BaseAsyncCallback<GWTJahiaNode>() {
                public void onSuccess(GWTJahiaNode o) {
                    Log.debug("saved.");
                }

                public void onApplicationFailure(Throwable throwable) {
                    if (throwable instanceof ExistingFileException) {
                        Window.alert(Messages.get("fm_inUseSaveSearch", "The entered name is already in use."));
                    } else {
                        Log.error("error", throwable);
                    }
                }

            });
        }
    }

}

From source file:org.jahia.ajax.gwt.client.widget.toolbar.action.DuplicateTemplatesSetActionItem.java

License:Open Source License

@Override
public void onComponentSelection() {
    String name = Window.prompt(Messages.get("newPackageName.label"), "New package name");
    if (name != null) {
        linker.loading("Duplicating template set...");
        JahiaContentManagementService.App.getInstance().createTemplateSet(name, JahiaGWTParameters.getSiteKey(),
                null, new BaseAsyncCallback<GWTJahiaNode>() {
                    public void onSuccess(GWTJahiaNode result) {
                        linker.loaded();
                        Info.display(Messages.get("label.information", "Information"), Messages
                                .get("message.templateSetCreated", "Templates set successfully created"));
                        JahiaGWTParameters.getSitesMap().put(result.getUUID(), result);
                        JahiaGWTParameters.setSite(result, linker);
                        ((EditLinker) linker).getSidePanel().refresh(EditLinker.REFRESH_ALL);
                        ((EditLinker) linker).onMainSelection(result.getPath(), null, null);
                        SiteSwitcherActionItem.refreshAllSitesList(linker);
                    }//from  ww  w . j a va 2 s .  co  m

                    public void onApplicationFailure(Throwable caught) {
                        linker.loaded();
                        Info.display(Messages.get("label.error", "Error"), Messages
                                .get("message.templateSetCreationFailed", "Templates set creation failed"));
                    }
                });
    }
}

From source file:org.jahia.ajax.gwt.client.widget.toolbar.action.NewPackageActionItem.java

License:Open Source License

public void onComponentSelection() {
    GWTJahiaNode parent = linker.getSelectionContext().getSingleSelection();
    if (parent != null) {
        final String nodeName = Window.prompt(Messages.get("label.newJavaPackage"), "untitled");
        if (nodeName == null || nodeName.length() == 0 || !nodeName.matches("^([a-z0-9-_]+\\.)*[a-z0-9-_]+$")) {
            Info.display(Messages.get("label.error", "Error"), Messages.getWithArgs(
                    "label.newJavaPackage.wrong", "Wrong package name {0}", new Object[] { nodeName }));
            return;
        }//from www.j  av a2 s . com
        linker.loading("");
        StringBuilder parentPath = new StringBuilder(parent.getPath());
        Map<String, String> parentNodesType = new HashMap<String, String>();
        List<String> packages = new ArrayList<String>(Arrays.asList(nodeName.split("\\.")));
        String newNodeName = packages.remove(packages.size() - 1);
        String nodeType = "jnt:folder";
        for (String packageName : packages) {
            if (parentPath.length() == 0 || parentPath.charAt(parentPath.length() - 1) != '/') {
                parentPath.append("/");
            }
            parentPath.append(packageName);
            parentNodesType.put(parentPath.toString(), nodeType);
        }
        JahiaContentManagementService.App.getInstance().createNode(parentPath.toString(), newNodeName, nodeType,
                null, null, null, null, null, parentNodesType, false, new BaseAsyncCallback<GWTJahiaNode>() {
                    public void onSuccess(GWTJahiaNode node) {
                        linker.setSelectPathAfterDataUpdate(Arrays.asList(node.getPath()));
                        linker.loaded();
                        Map<String, Object> data = new HashMap<String, Object>();
                        data.put("node", node);
                        linker.refresh(data);
                    }

                    public void onApplicationFailure(Throwable throwable) {
                        linker.loaded();
                        Info.display(Messages.get("label.error", "Error"),
                                Messages.getWithArgs("label.newJavaPackage.failed",
                                        "Failed to create package {0}", new Object[] { nodeName }));
                    }
                });
    }
}

From source file:org.jahia.ajax.gwt.client.widget.toolbar.action.NewTemplatesSetActionItem.java

License:Open Source License

@Override
public void onComponentSelection() {
    String name = Window.prompt(Messages.get("newPackageName.label"), "New package name");
    if (name != null) {
        linker.loading("Creating template set...");
        JahiaContentManagementService.App.getInstance().createTemplateSet(name, null, siteType,
                new BaseAsyncCallback<GWTJahiaNode>() {
                    public void onSuccess(GWTJahiaNode result) {
                        linker.loaded();
                        Info.display(Messages.get("label.information", "Information"), Messages
                                .get("message.templateSetCreated", "Templates set successfully created"));
                        JahiaGWTParameters.getSitesMap().put(result.getUUID(), result);
                        JahiaGWTParameters.setSite(result, linker);
                        ((EditLinker) linker).getSidePanel().refresh(EditLinker.REFRESH_ALL);
                        ((EditLinker) linker).onMainSelection(result.getPath(), null, null);
                        SiteSwitcherActionItem.refreshAllSitesList(linker);
                    }/*from  w  ww .  j  a  v  a  2 s . c o m*/

                    public void onApplicationFailure(Throwable caught) {
                        linker.loaded();
                        Info.display(Messages.get("label.error", "Error"), Messages
                                .get("message.templateSetCreationFailed", "Templates set creation failed"));
                    }
                });
    }
}

From source file:org.jahia.ajax.gwt.client.widget.toolbar.action.RenameActionItem.java

License:Open Source License

public void onComponentSelection() {
    final GWTJahiaNode selection = linker.getSelectionContext().getSingleSelection();
    if (selection != null) {
        if (selection.isLocked()) {
            Window.alert(selection.getName() + " is locked");
            return;
        }//from ww w  .  ja va2s. co m
        MainModule mainModule = MainModule.getInstance();
        final boolean goTo;
        if (mainModule != null) {
            goTo = selection.getPath().equals(mainModule.getNode().getPath());
        } else {
            goTo = false;
        }
        linker.loading(Messages.get("statusbar.renaming.label"));
        String newName = Window.prompt(Messages.get("confirm.newName.label") + " " + selection.getName(),
                selection.getName());
        if (selection.isNodeType("nt:hierarchyNode") && newName != null
                && FileUploader.filenameHasInvalidCharacters(newName)) {
            MessageBox.alert(Messages.get("label.error"),
                    Messages.getWithArgs("failure.upload.invalid.filename", "{0} is an invalid name",
                            new String[] { newName }),
                    null);
        } else if (maxNameSize > 0 && newName != null && newName.length() > 0
                && newName.length() > maxNameSize) {
            MessageBox.alert(Messages.get("label.error"),
                    Messages.getWithArgs("failure.upload.invalid.filename.toolong",
                            "The name is too long. The maximum length is {0}",
                            new String[] { String.valueOf(maxNameSize) }),
                    null);
        } else if (newName != null && newName.length() > 0 && !newName.equals(selection.getName())) {
            JahiaContentManagementService.App.getInstance().rename(selection.getPath(), newName,
                    new BaseAsyncCallback<GWTJahiaNode>() {
                        public void onApplicationFailure(Throwable throwable) {
                            MessageBox.alert(Messages.get("failure.rename.label"),
                                    throwable.getLocalizedMessage(), null);
                            linker.loaded();
                        }

                        public void onSuccess(GWTJahiaNode node) {
                            if (goTo) {
                                linker.setSelectPathAfterDataUpdate(Arrays.asList(node.getPath()));
                            }
                            linker.loaded();
                            Map<String, Object> data = new HashMap<String, Object>();
                            data.put("node", node);
                            if (linker instanceof ManagerLinker) {
                                data.put(Linker.REFRESH_ALL, true);
                            }
                            linker.refresh(data);
                        }
                    });
        } else {
            linker.loaded();
        }
    }
}

From source file:org.jahia.ajax.gwt.client.widget.toolbar.action.ZipActionItem.java

License:Open Source License

public void onComponentSelection() {
    final List<GWTJahiaNode> selectedItems = linker.getSelectionContext().getMultipleSelection();
    if (selectedItems != null && selectedItems.size() > 0) {
        final GWTJahiaNode selection = selectedItems.get(0);
        if (selection != null) {
            linker.loading(Messages.get("statusbar.zipping.label"));
            String defaultArchName;
            if (selectedItems.size() == 1) {
                defaultArchName = selection.getName() + ".zip";
            } else {
                defaultArchName = "archive.zip";
            }//  ww  w .  j  ava  2s . c om
            final String archName = Window.prompt(Messages.get("confirm.archiveName.label"), defaultArchName);
            if (archName != null && archName.length() > 0) {
                final String parentPath = selection.getPath().substring(0,
                        selection.getPath().lastIndexOf('/'));
                JahiaContentManagementService.App.getInstance().checkExistence(parentPath + "/" + archName,
                        new BaseAsyncCallback<Boolean>() {
                            public void onApplicationFailure(Throwable throwable) {
                                if (throwable instanceof ExistingFileException) {
                                    if (Window.confirm(Messages.get("alreadyExists.label") + "\n"
                                            + Messages.get("confirm.overwrite.label"))) {
                                        forceZip(selectedItems, archName, linker);
                                    }
                                } else {
                                    Window.alert(Messages.get("failure.zip.label") + "\n"
                                            + throwable.getLocalizedMessage());
                                    linker.loaded();
                                }
                            }

                            public void onSuccess(Boolean aBoolean) {
                                forceZip(selectedItems, archName, linker);
                            }
                        });
            }
        }
    }
}

From source file:org.javahispano.javaleague.client.application.cars.CarsView.java

License:Apache License

@UiHandler("filter")
void onFilter(ClickEvent event) {
    String color = Strings.emptyToNull(Window.prompt("Enter a color:", ""));

    getUiHandlers().filter(color, 0, pager.getPageSize());
}

From source file:org.kie.guvnor.categories.client.CategoriesEditorViewImpl.java

License:Apache License

@PostConstruct
public void init() {
    explorer = new CategoryTreeEditorWidget();
    form = new PrettyFormLayout();

    form.addHeader(Images.INSTANCE.EditCategories(), new HTML(Constants.INSTANCE.EditCategories()));
    form.startSection(Constants.INSTANCE.CategoriesPurposeTip());

    final SimplePanel editable = new SimplePanel();
    editable.add(explorer);//  w  ww. jav a  2s  .co  m

    form.addAttribute(Constants.INSTANCE.CurrentCategories(), editable);

    final HorizontalPanel actions = new HorizontalPanel();

    form.addAttribute("", actions);

    final Button newCat = new Button(Constants.INSTANCE.NewCategory());
    newCat.setTitle(Constants.INSTANCE.CreateANewCategory());
    newCat.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent w) {
            final CategoryEditor newCat;
            if (explorer.getSelectedCategory() == null) {
                newCat = new CategoryEditor(explorer.getCategories());
            } else {
                newCat = new CategoryEditor(explorer.getSelectedCategory());
            }

            newCat.show();
        }
    });

    actions.add(newCat);

    final Button rename = new Button(Constants.INSTANCE.RenameSelected());
    rename.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent w) {
            if (!explorer.isSelected()) {
                Window.alert(Constants.INSTANCE.PleaseSelectACategoryToRename());
                return;
            }
            final String name = Window.prompt(Constants.INSTANCE.CategoryNewNamePleaseEnter(), "");
            if (name != null) {
                isDirty = true;
                explorer.renameSelected(name);
            }
        }
    });

    actions.add(rename);

    final Button delete = new Button(Constants.INSTANCE.DeleteSelected());
    delete.addClickHandler(new ClickHandler() {
        public void onClick(final ClickEvent w) {
            if (!explorer.isSelected()) {
                Window.alert(Constants.INSTANCE.PleaseSelectACategoryToDelete());
                return;
            }
            if (Window.confirm(Constants.INSTANCE.AreYouSureYouWantToDeleteCategory()
                    + explorer.getSelectedCategory().getName())) {
                isDirty = true;
                explorer.removeSelected();
            }
        }
    });
    delete.setTitle(Constants.INSTANCE.DeleteSelectedCat());

    actions.add(delete);

    form.endSection();

    initWidget(form);
}