Example usage for com.google.gwt.user.client.ui TextBox setVisibleLength

List of usage examples for com.google.gwt.user.client.ui TextBox setVisibleLength

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui TextBox setVisibleLength.

Prototype

public void setVisibleLength(int length) 

Source Link

Document

Sets the number of visible characters in the text box.

Usage

From source file:org.kie.guvnor.metadata.client.widget.MetadataWidget.java

License:Apache License

/**
 * This binds a field, and returns a TextBox editor for it.
 * @param bind Interface to bind to.//from  w ww  . jav a 2 s .  c om
 * @param toolTip tool tip.
 * @return
 */
private Widget editableText(final FieldBinding bind, String toolTip) {
    if (!readOnly) {
        final TextBox tbox = new TextBox();
        tbox.setTitle(toolTip);
        tbox.setText(bind.getValue());
        tbox.setVisibleLength(10);
        tbox.addChangeHandler(new ChangeHandler() {
            public void onChange(final ChangeEvent event) {
                bind.setValue(tbox.getText());
            }
        });
        return tbox;
    } else {
        return new Label(bind.getValue());
    }
}

From source file:org.kie.guvnor.testscenario.client.VerifyRulesFiredWidget.java

License:Apache License

private FlexTable render(final FixtureList rfl, final Scenario sc) {
    FlexTable data = new DirtyableFlexTable();

    for (int i = 0; i < rfl.size(); i++) {
        final VerifyRuleFired v = (VerifyRuleFired) rfl.get(i);

        if (showResults && v.getSuccessResult() != null) {
            if (!v.getSuccessResult().booleanValue()) {
                data.setWidget(i, 0, new Image(CommonImages.INSTANCE.warning()));
                data.setWidget(i, 4,//from  www  .java 2 s.  com
                        new HTML(TestScenarioConstants.INSTANCE.ActualResult(v.getActualResult().toString())));

                data.getCellFormatter().addStyleName(i, 4, "testErrorValue"); //NON-NLS

            } else {
                data.setWidget(i, 0, new Image(TestScenarioImages.INSTANCE.testPassed()));
            }

        }
        data.setWidget(i, 1, new SmallLabel(v.getRuleName() + ":"));
        data.getFlexCellFormatter().setAlignment(i, 1, HasHorizontalAlignment.ALIGN_RIGHT,
                HasVerticalAlignment.ALIGN_MIDDLE);

        final ListBox b = new ListBox();
        b.addItem(TestScenarioConstants.INSTANCE.firedAtLeastOnce(), "y");
        b.addItem(TestScenarioConstants.INSTANCE.didNotFire(), "n");
        b.addItem(TestScenarioConstants.INSTANCE.firedThisManyTimes(), "e");
        final TextBox num = new TextBox();
        num.setVisibleLength(5);

        if (v.getExpectedFire() != null) {
            b.setSelectedIndex((v.getExpectedFire().booleanValue()) ? 0 : 1);
            num.setVisible(false);
        } else {
            b.setSelectedIndex(2);
            String xc = (v.getExpectedCount() != null) ? "" + v.getExpectedCount().intValue() : "0";
            num.setText(xc);
        }

        b.addChangeHandler(new ChangeHandler() {
            public void onChange(ChangeEvent event) {
                String s = b.getValue(b.getSelectedIndex());
                if (s.equals("y") || s.equals("n")) {
                    num.setVisible(false);
                    v.setExpectedFire((s.equals("y")) ? Boolean.TRUE : Boolean.FALSE);
                    v.setExpectedCount(null);
                } else {
                    num.setVisible(true);
                    v.setExpectedFire(null);
                    num.setText("1");
                    v.setExpectedCount(new Integer(1));
                }
            }
        });

        b.addItem(TestScenarioConstants.INSTANCE.ChooseDotDotDot());

        num.addChangeHandler(new ChangeHandler() {
            public void onChange(ChangeEvent event) {
                v.setExpectedCount(new Integer(num.getText()));
            }
        });

        HorizontalPanel h = new HorizontalPanel();
        h.add(b);
        h.add(num);
        data.setWidget(i, 2, h);

        Image del = CommonAltedImages.INSTANCE.DeleteItemSmall();
        del.setAltText(TestScenarioConstants.INSTANCE.RemoveThisRuleExpectation());
        del.setTitle(TestScenarioConstants.INSTANCE.RemoveThisRuleExpectation());
        del.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent w) {
                if (Window.confirm(
                        TestScenarioConstants.INSTANCE.AreYouSureYouWantToRemoveThisRuleExpectation())) {
                    rfl.remove(v);
                    sc.removeFixture(v);
                    outer.setWidget(1, 0, render(rfl, sc));
                }
            }
        });

        data.setWidget(i, 3, del);

        //we only want numbers here...
        num.addKeyPressHandler(new KeyPressHandler() {
            public void onKeyPress(KeyPressEvent event) {
                if (Character.isLetter(event.getCharCode())) {
                    ((TextBox) event.getSource()).cancelKey();
                }
            }
        });
    }
    return data;
}

From source file:org.pentaho.mantle.client.admin.ContentCleanerPanel.java

License:Open Source License

public void activate() {
    clear();//  w w  w.  j  a  v  a  2s. c  o  m
    String moduleBaseURL = GWT.getModuleBaseURL();
    String moduleName = GWT.getModuleName();
    String contextURL = moduleBaseURL.substring(0, moduleBaseURL.lastIndexOf(moduleName));

    RequestBuilder scheduleFileRequestBuilder = new RequestBuilder(RequestBuilder.GET,
            contextURL + "api/scheduler/getContentCleanerJob?cb=" + System.currentTimeMillis());
    scheduleFileRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
    scheduleFileRequestBuilder.setHeader("Content-Type", "application/json"); //$NON-NLS-1$//$NON-NLS-2$
    scheduleFileRequestBuilder.setHeader("accept", "application/json"); //$NON-NLS-1$//$NON-NLS-2$

    try {
        scheduleFileRequestBuilder.sendRequest("", new RequestCallback() {
            public void onError(Request request, Throwable exception) {
            }

            public void onResponseReceived(Request request, Response response) {
                final TextBox nowTextBox = new TextBox();
                nowTextBox.setWidth("24px");
                nowTextBox.getElement().getStyle().setPadding(5, Unit.PX);
                nowTextBox.getElement().getStyle().setMarginLeft(5, Unit.PX);
                nowTextBox.getElement().getStyle().setMarginRight(5, Unit.PX);
                final TextBox scheduleTextBox = new TextBox();
                scheduleTextBox.setVisibleLength(4);

                JsJob tmpJsJob = parseJsonJob(JsonUtils.escapeJsonForEval(response.getText()));

                boolean fakeJob = false;
                if (tmpJsJob == null) {
                    tmpJsJob = createJsJob();
                    fakeJob = true;
                }
                final JsJob jsJob = tmpJsJob;

                if (jsJob != null) {
                    scheduleTextBox.setValue("" + (Long.parseLong(jsJob.getJobParamValue("age")) / 86400L));
                } else {
                    scheduleTextBox.setText("180");
                }
                scheduleTextBox.addChangeHandler(new ChangeHandler() {
                    public void onChange(ChangeEvent event) {
                        if (jsJob != null) {
                            JsArray<JsJobParam> params = jsJob.getJobParams();
                            for (int i = 0; i < params.length(); i++) {
                                if (params.get(i).getName().equals("age")) {
                                    params.get(i).setValue(
                                            "" + (Long.parseLong(scheduleTextBox.getText()) * 86400L));
                                    break;
                                }
                            }
                        }
                    }
                });

                Label settingsLabel = new Label(Messages.getString("settings"));
                settingsLabel.setStyleName("pentaho-fieldgroup-major");
                add(settingsLabel, DockPanel.NORTH);

                VerticalPanel nowPanelWrapper = new VerticalPanel();
                Label deleteNowLabel = new Label(Messages.getString("deleteGeneratedFilesNow"));
                deleteNowLabel.getElement().getStyle().setPaddingTop(15, Unit.PX);
                deleteNowLabel.setStyleName("pentaho-fieldgroup-minor");
                nowPanelWrapper.add(deleteNowLabel);

                HorizontalPanel nowLabelPanel = new HorizontalPanel();
                nowLabelPanel.getElement().getStyle().setPaddingTop(10, Unit.PX);
                nowLabelPanel.getElement().getStyle().setPaddingBottom(10, Unit.PX);

                Label deleteGeneratedFilesOlderThan = new Label(
                        Messages.getString("deleteGeneratedFilesOlderThan"));
                deleteGeneratedFilesOlderThan.getElement().getStyle().setPaddingTop(7, Unit.PX);
                nowLabelPanel.add(deleteGeneratedFilesOlderThan);

                nowLabelPanel.add(nowTextBox);
                nowTextBox.setText("180");
                Label days = new Label(Messages.getString("daysDot"));
                days.getElement().getStyle().setPaddingTop(7, Unit.PX);
                nowLabelPanel.add(days);
                Button deleteNowButton = new Button(Messages.getString("deleteNow"));
                deleteNowButton.setStylePrimaryName("pentaho-button");
                deleteNowButton.addStyleName("first");
                deleteNowButton.addClickHandler(new ClickHandler() {
                    public void onClick(ClickEvent event) {
                        MessageDialogBox warning = new MessageDialogBox(Messages.getString("deleteNow"),
                                Messages.getString("confirmDeleteGeneratedContentNow"), false, false, true,
                                Messages.getString("yes"), null, Messages.getString("no"));
                        warning.setCallback(new IDialogCallback() {
                            @Override
                            public void okPressed() {
                                deleteContentNow(Long.parseLong(nowTextBox.getValue()) * 86400L);
                            }

                            @Override
                            public void cancelPressed() {
                            }
                        });
                        warning.center();
                    }
                });
                nowPanelWrapper.add(nowLabelPanel);
                nowPanelWrapper.add(deleteNowButton);
                add(nowPanelWrapper, DockPanel.NORTH);

                // scheduled
                VerticalPanel scheduledPanel = new VerticalPanel();
                Label deleteScheduleLabel = new Label(Messages.getString("scheduleDeletionOfGeneratedFiles"));
                deleteScheduleLabel.setStyleName("pentaho-fieldgroup-minor");
                deleteScheduleLabel.getElement().getStyle().setPaddingTop(15, Unit.PX);
                scheduledPanel.add(deleteScheduleLabel);

                Label descLabel;
                if (!fakeJob) {
                    String desc = jsJob.getJobTrigger().getDescription();
                    descLabel = new Label(desc);
                    scheduledPanel.add(descLabel);
                } else {
                    descLabel = new Label(Messages.getString("generatedFilesAreNotScheduledToBeDeleted"));
                    scheduledPanel.add(descLabel);
                }
                descLabel.getElement().getStyle().setPaddingTop(10, Unit.PX);
                descLabel.getElement().getStyle().setPaddingBottom(10, Unit.PX);

                Button editScheduleButton = new Button(Messages.getString("edit"));
                if (fakeJob) {
                    editScheduleButton.setText(Messages.getString("scheduleDeletion"));
                }
                Button deleteScheduleButton = new Button(Messages.getString("cancelSchedule"));
                deleteScheduleButton.setStylePrimaryName("pentaho-button");
                deleteScheduleButton.addStyleName("last");
                deleteScheduleButton.addClickHandler(new ClickHandler() {
                    public void onClick(ClickEvent event) {
                        deleteContentCleaner(jsJob);
                    }
                });
                editScheduleButton.setStylePrimaryName("pentaho-button");
                editScheduleButton.addStyleName("first");
                editScheduleButton.addClickHandler(new ClickHandler() {
                    public void onClick(ClickEvent event) {
                        IDialogCallback callback = new IDialogCallback() {
                            public void okPressed() {
                                deleteContentCleaner(jsJob);
                            }

                            public void cancelPressed() {
                            }
                        };

                        HorizontalPanel scheduleLabelPanel = new HorizontalPanel();
                        scheduleLabelPanel
                                .add(new Label(Messages.getString("deleteGeneratedFilesOlderThan"), false));
                        scheduleLabelPanel.add(scheduleTextBox);
                        scheduleLabelPanel
                                .add(new Label(Messages.getString("daysUsingTheFollowingRules"), false));
                        ScheduleRecurrenceDialog editSchedule = new ScheduleRecurrenceDialog(null, jsJob,
                                callback, false, false, AbstractWizardDialog.ScheduleDialogType.SCHEDULER);
                        editSchedule.setShowSuccessDialog(false);
                        editSchedule.addCustomPanel(scheduleLabelPanel, DockPanel.NORTH);
                        editSchedule.center();
                    }
                });
                HorizontalPanel scheduleButtonPanel = new HorizontalPanel();
                scheduleButtonPanel.add(editScheduleButton);
                if (!fakeJob) {
                    scheduleButtonPanel.add(deleteScheduleButton);
                }
                scheduledPanel.add(scheduleButtonPanel);
                add(scheduledPanel, DockPanel.NORTH);

                VerticalPanel fillPanel = new VerticalPanel();
                add(fillPanel, DockPanel.NORTH);
                fillPanel.getElement().getParentElement().getStyle().setHeight(100, Unit.PCT);
            }
        });
    } catch (RequestException re) {
        //ignored
    }

}

From source file:org.pentaho.mantle.client.commands.NewFolderCommand.java

License:Open Source License

protected void performOperation(boolean feedback) {
    final SolutionFolderActionEvent event = new SolutionFolderActionEvent();
    event.setAction(this.getClass().getName());

    final TextBox folderNameTextBox = new TextBox();
    folderNameTextBox.setTabIndex(1);//from ww  w  .j a  v  a2s  .  c  o m
    folderNameTextBox.setVisibleLength(40);

    VerticalPanel vp = new VerticalPanel();
    vp.add(new Label(Messages.getString("newFolderName"))); //$NON-NLS-1$
    vp.add(folderNameTextBox);
    final PromptDialogBox newFolderDialog = new PromptDialogBox(Messages.getString("newFolder"), //$NON-NLS-1$
            Messages.getString("ok"), Messages.getString("cancel"), false, true, vp); //$NON-NLS-1$ //$NON-NLS-2$
    newFolderDialog.setFocusWidget(folderNameTextBox);
    folderNameTextBox.setFocus(true);

    final IDialogCallback callback = new IDialogCallback() {

        public void cancelPressed() {
            newFolderDialog.hide();
        }

        public void okPressed() {

            if (!NameUtils.isValidFolderName(folderNameTextBox.getText())) {
                event.setMessage(Messages.getString("containsIllegalCharacters", folderNameTextBox.getText()));
                EventBusUtil.EVENT_BUS.fireEvent(event);
                return;
            }

            solutionPath = parentFolder.getPath() + "/" + URL.encodePathSegment(folderNameTextBox.getText());

            String createDirUrl = contextURL + "api/repo/dirs/" + SolutionBrowserPanel.pathToId(solutionPath); //$NON-NLS-1$
            RequestBuilder createDirRequestBuilder = new RequestBuilder(RequestBuilder.PUT, createDirUrl);

            try {
                createDirRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
                createDirRequestBuilder.sendRequest("", new RequestCallback() {

                    @Override
                    public void onError(Request createFolderRequest, Throwable exception) {
                        MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                                Messages.getString("couldNotCreateFolder", folderNameTextBox.getText()), //$NON-NLS-1$
                                false, false, true);
                        dialogBox.center();
                        event.setMessage(
                                Messages.getString("couldNotCreateFolder", folderNameTextBox.getText()));
                        EventBusUtil.EVENT_BUS.fireEvent(event);
                    }

                    @Override
                    public void onResponseReceived(Request createFolderRequest, Response createFolderResponse) {
                        if (createFolderResponse.getStatusText().equalsIgnoreCase("OK")) { //$NON-NLS-1$
                            NewFolderCommand.this.callback.onHandle(solutionPath);
                            new RefreshRepositoryCommand().execute(false);
                            event.setMessage("Success");
                            FileChooserDialog.setIsDirty(Boolean.TRUE);
                            setBrowseRepoDirty(Boolean.TRUE);
                            EventBusUtil.EVENT_BUS.fireEvent(event);
                        } else {
                            event.setMessage(StringUtils.isEmpty(createFolderResponse.getText())
                                    || Messages.getString(createFolderResponse.getText()) == null
                                            ? Messages.getString("couldNotCreateFolder", //$NON-NLS-1$
                                                    folderNameTextBox.getText()) : Messages.getString(createFolderResponse.getText(),
                                                    folderNameTextBox.getText()));
                            EventBusUtil.EVENT_BUS.fireEvent(event);

                        }
                    }

                });
            } catch (RequestException e) {
                Window.alert(e.getLocalizedMessage());
                event.setMessage(e.getLocalizedMessage());
                EventBusUtil.EVENT_BUS.fireEvent(event);
            }

        }
    };
    newFolderDialog.setCallback(callback);
    newFolderDialog.center();
}

From source file:org.pentaho.mantle.client.commands.NewRootFolderCommand.java

License:Open Source License

protected void performOperation(boolean feedback) {
    final TextBox folderNameTextBox = new TextBox();
    folderNameTextBox.setTabIndex(1);//from w w  w .ja  va  2 s  . co  m
    folderNameTextBox.setVisibleLength(40);

    VerticalPanel vp = new VerticalPanel();
    vp.add(new Label(Messages.getString("newFolderName"))); //$NON-NLS-1$
    vp.add(folderNameTextBox);
    final PromptDialogBox newFolderDialog = new PromptDialogBox(Messages.getString("newFolder"), //$NON-NLS-1$
            Messages.getString("ok"), Messages.getString("cancel"), false, true, vp); //$NON-NLS-1$ //$NON-NLS-2$
    newFolderDialog.setFocusWidget(folderNameTextBox);
    folderNameTextBox.setFocus(true);

    final IDialogCallback callback = new IDialogCallback() {

        public void cancelPressed() {
            newFolderDialog.hide();
        }

        public void okPressed() {
            String url = ""; //$NON-NLS-1$
            if (GWT.isScript()) {
                String windowpath = Window.Location.getPath();
                if (!windowpath.endsWith("/")) { //$NON-NLS-1$
                    windowpath = windowpath.substring(0, windowpath.lastIndexOf("/") + 1); //$NON-NLS-1$
                }
                url = windowpath + "SolutionRepositoryService?component=createNewFolder&solution=" + solution //$NON-NLS-1$
                        + "&path=" + repoPath + "&name=" //$NON-NLS-1$ //$NON-NLS-2$
                        + folderNameTextBox.getText(); //$NON-NLS-1$
            } else if (!GWT.isScript()) {
                url = "http://localhost:8080/pentaho/SolutionRepositoryService?component=createNewFolder&solution=" //$NON-NLS-1$
                        + solution + "&path=" //$NON-NLS-1$
                        + repoPath + "&name=" + folderNameTextBox.getText(); //$NON-NLS-1$ //$NON-NLS-2$
            }
            final String myurl = url;
            RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, myurl);
            try {
                builder.sendRequest(null, new RequestCallback() {

                    public void onError(Request request, Throwable exception) {
                        MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                                Messages.getString("couldNotCreateFolder", folderNameTextBox.getText()), //$NON-NLS-1$
                                false, false, true);
                        dialogBox.center();
                    }

                    public void onResponseReceived(Request request, Response response) {
                        Document resultDoc = (Document) XMLParser.parse((String) (String) response.getText());
                        boolean result = "true" //$NON-NLS-1$
                                .equals(resultDoc.getDocumentElement().getFirstChild().getNodeValue());
                        if (result) {
                            RefreshRepositoryCommand cmd = new RefreshRepositoryCommand();
                            cmd.execute(false);
                        } else {
                            MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                                    Messages.getString("couldNotCreateFolder", folderNameTextBox.getText()), //$NON-NLS-1$
                                    false, false, true);
                            dialogBox.center();
                        }
                    }

                });
            } catch (RequestException e) {
            }
        }
    };
    newFolderDialog.setCallback(callback);
    newFolderDialog.center();
}

From source file:org.pentaho.mantle.client.commands.OpenURLCommand.java

License:Open Source License

protected void performOperation(boolean feedback) {
    final TextBox textBox = new TextBox();
    textBox.setText("http://"); //$NON-NLS-1$
    textBox.setWidth("500px"); //$NON-NLS-1$
    textBox.setVisibleLength(72);
    IDialogCallback callback = new IDialogCallback() {

        public void cancelPressed() {
        }/*  www .ja v  a  2 s  . c  o  m*/

        public void okPressed() {
            SolutionBrowserPanel.getInstance().getContentTabPanel().showNewURLTab(textBox.getText(),
                    textBox.getText(), textBox.getText(), false);
        }

    };
    IDialogValidatorCallback validatorCallback = new IDialogValidatorCallback() {
        public boolean validate() {
            boolean isValid = !"".equals(textBox.getText()) && textBox.getText() != null; //$NON-NLS-1$
            if (!isValid) {
                MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                        Messages.getString("urlNotSpecified"), false, false, true); //$NON-NLS-1$
                dialogBox.center();
            }
            return isValid;
        }
    };
    PromptDialogBox promptDialog = new PromptDialogBox(Messages.getString("enterURL"), Messages.getString("ok"), //$NON-NLS-1$//$NON-NLS-2$
            Messages.getString("cancel"), false, true, textBox); //$NON-NLS-1$
    promptDialog.setValidatorCallback(validatorCallback);
    promptDialog.setCallback(callback);
    promptDialog.setWidth("500px"); //$NON-NLS-1$
    promptDialog.center();
}

From source file:org.pentaho.mantle.client.dialogs.folderchooser.NewFolderCommand.java

License:Open Source License

protected void performOperation(boolean feedback) {

    final TextBox folderNameTextBox = new TextBox();
    folderNameTextBox.setTabIndex(1);//  w  w w  .  j a v  a 2 s  .  co  m
    folderNameTextBox.setVisibleLength(40);

    VerticalPanel vp = new VerticalPanel();
    vp.add(new Label(Messages.getString("newFolderName"))); //$NON-NLS-1$
    vp.add(folderNameTextBox);
    final PromptDialogBox newFolderDialog = new PromptDialogBox(Messages.getString("newFolder"), //$NON-NLS-1$
            Messages.getString("ok"), Messages.getString("cancel"), false, true, vp); //$NON-NLS-1$ //$NON-NLS-2$
    newFolderDialog.setFocusWidget(folderNameTextBox);
    folderNameTextBox.setFocus(true);

    final IDialogCallback callback = new IDialogCallback() {

        public void cancelPressed() {
            newFolderDialog.hide();
        }

        public void okPressed() {
            if (!NameUtils.isValidFolderName(folderNameTextBox.getText())) {
                //event.setMessage( Messages.getString( "containsIllegalCharacters", folderNameTextBox.getText() ) );
                //EventBusUtil.EVENT_BUS.fireEvent( event );
                MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                        Messages.getString("containsIllegalCharacters", folderNameTextBox.getText()), //$NON-NLS-1$
                        false, false, true);
                dialogBox.center();
                return;
            }

            solutionPath = parentFolder.getPath() + "/" + URL.encodePathSegment(folderNameTextBox.getText());

            String createDirUrl = contextURL + "api/repo/dirs/" + pathToId(solutionPath); //$NON-NLS-1$
            RequestBuilder createDirRequestBuilder = new RequestBuilder(RequestBuilder.PUT, createDirUrl);

            try {
                createDirRequestBuilder.setHeader("If-Modified-Since", "01 Jan 1970 00:00:00 GMT");
                createDirRequestBuilder.sendRequest("", new RequestCallback() {

                    @Override
                    public void onError(Request createFolderRequest, Throwable exception) {
                        MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                                Messages.getString("couldNotCreateFolder", folderNameTextBox.getText()), //$NON-NLS-1$
                                false, false, true);
                        dialogBox.center();
                        //event.setMessage( Messages.getString( "couldNotCreateFolder", folderNameTextBox.getText() ) );
                        //EventBusUtil.EVENT_BUS.fireEvent( event );
                    }

                    @Override
                    public void onResponseReceived(Request createFolderRequest, Response createFolderResponse) {
                        if (createFolderResponse.getStatusText().equalsIgnoreCase("OK")) { //$NON-NLS-1$
                            NewFolderCommand.this.callback.onHandle(solutionPath);
                            //new RefreshRepositoryCommand().execute( false );
                            //event.setMessage( "Success" );
                            FileChooserDialog.setIsDirty(Boolean.TRUE);
                            setBrowseRepoDirty(Boolean.TRUE);
                            //EventBusUtil.EVENT_BUS.fireEvent( event );
                        } else {

                            String errorMessage = StringUtils.isEmpty(createFolderResponse.getText())
                                    || Messages.getString(createFolderResponse.getText()) == null
                                            ? Messages.getString("couldNotCreateFolder", //$NON-NLS-1$
                                                    folderNameTextBox.getText()) : Messages.getString(createFolderResponse.getText(),
                                                    folderNameTextBox.getText());
                            MessageDialogBox dialogBox = new MessageDialogBox(Messages.getString("error"), //$NON-NLS-1$
                                    errorMessage, //$NON-NLS-2$
                                    false, false, true);
                            dialogBox.center();
                            /*event.setMessage(
                                StringUtils.isEmpty( createFolderResponse.getText() )
                                    || Messages.getString( createFolderResponse.getText() ) == null
                                    ? Messages.getString( "couldNotCreateFolder", folderNameTextBox.getText() ) //$NON-NLS-1$
                                    : Messages.getString( createFolderResponse.getText(), folderNameTextBox.getText() )
                            );
                            EventBusUtil.EVENT_BUS.fireEvent( event );
                            */
                        }
                    }

                });
            } catch (RequestException e) {
                Window.alert(e.getLocalizedMessage());
                /*event.setMessage( e.getLocalizedMessage() );
                EventBusUtil.EVENT_BUS.fireEvent( event );*/
            }

        }
    };
    newFolderDialog.setCallback(callback);
    newFolderDialog.center();
}

From source file:org.pentaho.mantle.client.solutionbrowser.tabs.TabWidget.java

License:Open Source License

public void createDeepLink() {
    if (tabContent instanceof IFrameTabPanel) {
        PromptDialogBox dialogBox = new PromptDialogBox(Messages.getString("deepLink"), //$NON-NLS-1$
                Messages.getString("ok"), Messages.getString("cancel"), false, //$NON-NLS-1$ //$NON-NLS-2$
                true);/*from  w  ww .ja  va  2  s  .co m*/
        String url = Window.Location.getProtocol() + "//" + Window.Location.getHostName() + ":" //$NON-NLS-1$//$NON-NLS-2$
                + Window.Location.getPort() + Window.Location.getPath() + "?name=" + textLabel.getText() + "&startup-url="; //$NON-NLS-1$ //$NON-NLS-2$
        String startup = ((IFrameTabPanel) tabContent).getUrl();
        TextBox urlbox = new TextBox();
        urlbox.setText(url + URL.encodeComponent(startup));
        urlbox.setVisibleLength(80);
        dialogBox.setContent(urlbox);
        dialogBox.center();
    }
}

From source file:org.primordion.xholon.io.AbstractXholonGui.java

License:Open Source License

/**
 * Create a GUI to interact with the attributes of an IXholon node.
 * @param node An IXholon node.// ww w. java2  s  .c  o  m
 * @param modal Whether or not the attributes GUI is modal.
 */
protected void createAttributesGui(IXholon node, boolean modal) {
    final IReflection ir = ReflectionFactory.instance();
    Object rowData[][] = null;
    if ("Application".equals(node.getRoleName())) {
        node = app;
    }
    final IXholon attrNode = node;
    rowData = ir.getAttributes(attrNode);

    Object columnNames[] = new Object[2];
    columnNames[0] = "Name";
    columnNames[1] = "Value";
    final Grid attrTable = new Grid(rowData.length + 1, 2); // (rowData, columnNames);
    attrTable.setText(0, 0, (String) columnNames[0]);
    attrTable.setText(0, 1, (String) columnNames[1]);
    for (int i = 0; i < rowData.length; i++) {
        attrTable.setText(i + 1, 0, (String) rowData[i][0]);
        if (rowData[i][1] == null) {
            attrTable.setText(i + 1, 1, "");
        } else {
            attrTable.setText(i + 1, 1, rowData[i][1].toString());
        }
    }

    attrTable.addClickHandler(new ClickHandler() {

        public void onClick(ClickEvent event) {
            Cell cell = attrTable.getCellForEvent(event);
            if (cell != null) {
                int cellIndex = cell.getCellIndex();
                if (cellIndex == 0) {
                    return;
                }
                final int rowIndex = cell.getRowIndex();
                if ((attrNode != app) && (app.getAppSpecificAttribute(attrNode,
                        (Class<IXholon>) attrNode.getClass(), attrTable.getText(rowIndex, 0)) == null)) {
                    // this is a non-editable attribute
                    return;
                }
                Element ele = cell.getElement();
                String text = ele.getInnerText();
                //System.out.println(text);

                final TextBox textBox = new TextBox();
                // style it like a label so it looks like the original Element
                //textBox.setStylePrimaryName("gwt-Label"); // does nothing
                // set the style manually so it looks like the original Element
                textBox.getElement().setAttribute("style",
                        "border-width: 0px; padding-top: 0px; padding-bottom: 0px;");
                int textLen = text.length();
                textBox.setVisibleLength(textLen == 0 ? 5 : textLen); // can't be 0
                textBox.setText(text); // or setValue( ?
                attrTable.setWidget(rowIndex, 1, textBox);
                textBox.setFocus(true);
                // add a ChangeHandler to tell when user has finished editing
                textBox.addChangeHandler(new ChangeHandler() {
                    public void onChange(ChangeEvent event) {
                        if (attrNode == app) {
                            // change the value of an Application parameter
                            //ir.setParam(attrTable.getText(rowIndex, 0), textBox.getText(), app);
                            app.setParam(attrTable.getText(rowIndex, 0), textBox.getText());
                        } else {
                            // change the value of the Xholon node
                            app.setAppSpecificAttribute(attrNode, (Class<IXholon>) attrNode.getClass(),
                                    attrTable.getText(rowIndex, 0), textBox.getText());
                        }
                        // set the changed text back into the Attributes panel
                        attrTable.setText(rowIndex, 1, textBox.getText());
                    }
                });
                // add a BlurHandler
                textBox.addBlurHandler(new BlurHandler() {
                    public void onBlur(BlurEvent event) {
                        attrTable.setText(rowIndex, 1, textBox.getText());
                    }
                });
            }
        }

    });

    ScrollPanel scrollPanel = new ScrollPanel(attrTable);
    scrollPanel.setSize("500px", "500px");

    PopupPanel popup = new PopupPanel(true);
    popup.setTitle("Atttributes of " + attrNode.getName());
    popup.add(scrollPanel);
    popup.center();
}

From source file:org.wyona.security.gwt.accesspolicyeditor.client.AccessPolicyEditor.java

License:Apache License

/**
 * Execute at the very beginning//w  w  w  .  ja  va 2s.  c o  m
 */
public void onModuleLoad() {
    String language = "en"; // DEFAULT

    String groupURL = "DEFAULT-group.xml";
    String identitiesURL = "DEFAULT-identities-and-usecases.xml";
    String readPolicyURL = "DEFAULT-policy.xml";
    boolean cancelURLBaseEqualsHostPageURL = false;
    String cancelURL = "DEFAULT-cancel.html";
    String savePolicyURL = "DEFAULT-save-policy.xml";
    String i18nURL = "DEFAULT-i18n.xml";
    // Get URLs from host/html page
    try {
        Dictionary dict = Dictionary.getDictionary("getURLs");
        language = dict.get("language");
        groupURL = GWT.getHostPageBaseURL() + dict.get("group-url").replace("&amp;", "&"); // INFO: The property 'group-url' is set by src/java/org/wyona/yanel/impl/resources/policymanager/PolicyManagerResource.java
        identitiesURL = dict.get("identities-url");
        readPolicyURL = dict.get("policy-url");
        cancelURL = dict.get("cancel-url").replace("&amp;", "&");
        cancelURLBaseEqualsHostPageURL = new Boolean(dict.get("cancel-url-base-equals-host-page-url"))
                .booleanValue();
        savePolicyURL = dict.get("save-url");

        // TODO: Read this URL and use data instead from hardcoded I18n class
        i18nURL = dict.get("i18n-url");
    } catch (java.util.MissingResourceException e) {
        Window.alert("Exception: " + e.getMessage());
    }

    // Get identities/groups and available rights from server
    identitiesLBW = new IdentitiesListBoxWidget(visibleItemCount, language);
    getIdentitiesAndRights(identitiesURL);

    // Get policy from server (within getPolicy() the identities list will be updated accordingly)
    policyLBW = new PolicyListBoxWidget(visibleItemCount, policyUsers, policyGroups, useInheritedPolicies,
            language);
    getPolicy(readPolicyURL);

    // Setup GUI
    VerticalPanel vp = new VerticalPanel();
    vp.setStyleName("gwt-wyona-main-vp");
    vp.setSpacing(15);
    RootPanel.get("access-policy-editor-hook").add(vp);

    HorizontalPanel searchFilterPanel = new HorizontalPanel();
    searchFilterPanel.setStyleName("gwt-wyona-search-hp");
    vp.add(searchFilterPanel);

    searchFilterPanel.add(new Label(I18n.getLabel("search-box-label", language)));

    final TextBox searchTB = new TextBox();
    searchTB.setVisibleLength(30);
    searchFilterPanel.add(searchTB);

    // Search functionality
    searchTB.addKeyboardListener(new KeyboardListenerAdapter() {
        public void onKeyUp(Widget sender, char keyCode, int modifiers) {
            identitiesLBW.listBySearchMatch(searchTB.getText());
        }
    });

    /* TODO: Is this still needed?!
            Button searchButton = new Button("Search User or Group", new ClickListener() {
    public void onClick(Widget sender) {
        int itemCount = identitiesLBW.getListBox().getItemCount();
        for (int i = 0; i < itemCount; i++) {
            String itemText = identitiesLBW.getListBox().getItemText(i);
            if (itemText.indexOf(searchTB.getText()) >= 0) Window.alert("Result: " + itemText);
                    
        }
    }
              
            });
            searchFilterPanel.add(searchButton);
    */

    HorizontalPanel hp = new HorizontalPanel();
    vp.add(hp);

    HorizontalPanel buttonHP = new HorizontalPanel();
    buttonHP.setSpacing(5);
    vp.add(buttonHP);
    //buttonHP.add(new Button("Apply Policy"));

    // Save Button
    final String savePolicyUrl = GWT.getHostPageBaseURL() + savePolicyURL.replaceAll("&amp;", "&");
    //saveButton = new Button("Save Policy and Exit", new ClickListener() {
    saveButton = new Button("Save/Apply Policy", new ClickListener() {
        public void onClick(Widget sender) {
            final AsynchronousPolicySetter aps = new AsynchronousPolicySetter(savePolicyUrl);
            try {
                com.google.gwt.http.client.Request request = aps.sendRequest(policyLBW.getItems(),
                        policyLBW.getUseInheritedPolicies());
                // TODO: Disable button during save (start a timer in order to enable when response has been received)
                //saveButton.setEnabled(false);
            } catch (Exception e) {
                Window.alert("Exception: " + e.getMessage());
            }
        }
    });
    saveButton.addStyleName("gwt-wyona-SaveButton");
    buttonHP.add(saveButton);

    // Cancel Button
    final String cancelUrl = cancelURL;
    final boolean cancelURLBaseEqualsHostPageURLFinal = cancelURLBaseEqualsHostPageURL;
    Button cancelButton = new Button("Cancel/Close", new ClickListener() {
        public void onClick(Widget sender) {
            //Window.alert("Redirect to " + cancelUrl);
            if (cancelURLBaseEqualsHostPageURLFinal) {
                redirectTo(GWT.getHostPageBaseURL() + cancelUrl);
            } else {
                redirectTo(cancelUrl);
            }
        }

        public native void redirectTo(String url) /*-{
                                                  $wnd.location.href=url;
                                                  }-*/;
    });
    cancelButton.addStyleName("gwt-wyona-CancelButton");
    buttonHP.add(cancelButton);

    vp.add(new Label("Wyona Access Control Policy (GWT) Editor version 1.1.0"));

    AddRemoveIdentitiesWidget ariw = new AddRemoveIdentitiesWidget(identitiesLBW, policyLBW.getListBox(),
            policyLBW, groupURL, language);
    ariw.setStyleName("gwt-wyona-AddRemoveWidget");

    CutPasteListOrderWidget cutPasteWidget = new CutPasteListOrderWidget(policyLBW);
    cutPasteWidget.setStyleName("gwt-wyona-CutPasteListOrderWidget");

    hp.add(getFilterUsersAndGroupsButtonsWidget(language));
    hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
    hp.add(identitiesLBW);
    hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE);
    hp.add(ariw);
    hp.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
    hp.add(policyLBW);
    hp.add(cutPasteWidget);
}