List of usage examples for com.google.gwt.user.client.ui HorizontalPanel setCellHorizontalAlignment
public void setCellHorizontalAlignment(IsWidget w, HorizontalAlignmentConstant align)
From source file:org.rstudio.core.client.widget.CaptionWithHelp.java
License:Open Source License
public CaptionWithHelp(String caption, String helpCaption, final String rstudioLinkName) { RStudioGinjector.INSTANCE.injectMembers(this); rstudioLinkName_ = rstudioLinkName;/* ww w. j av a 2s .c o m*/ HorizontalPanel panel = new HorizontalPanel(); panel.setWidth("100%"); captionLabel_ = new Label(caption); panel.add(captionLabel_); helpPanel_ = new HorizontalPanel(); Image helpImage = new Image(ThemeResources.INSTANCE.help()); helpImage.setStylePrimaryName(styles.helpImage()); helpPanel_.add(helpImage); HyperlinkLabel link = new HyperlinkLabel(helpCaption); link.addStyleName(styles.helpLink()); link.addClickHandler(new ClickHandler() { public void onClick(ClickEvent event) { if (rstudioLinkName_ != null) globalDisplay_.openRStudioLink(rstudioLinkName_, includeVersionInfo_); } }); helpPanel_.add(link); panel.add(helpPanel_); panel.setCellHorizontalAlignment(helpPanel_, HasHorizontalAlignment.ALIGN_RIGHT); outerPanel_ = panel; initWidget(panel); }
From source file:org.rstudio.core.client.widget.MiniDialogPopupPanel.java
License:Open Source License
private void commonInit() { addStyleName(ThemeStyles.INSTANCE.miniDialogPopupPanel()); verticalPanel_ = new VerticalPanel(); verticalPanel_.setStyleName(ThemeStyles.INSTANCE.miniDialogContainer()); // title bar/*from www.j av a 2s . c om*/ HorizontalPanel titleBar = new HorizontalPanel(); titleBar.setWidth("100%"); captionLabel_ = new Label(); captionLabel_.setStyleName(ThemeStyles.INSTANCE.miniDialogCaption()); titleBar.add(captionLabel_); titleBar.setCellHorizontalAlignment(captionLabel_, HasHorizontalAlignment.ALIGN_LEFT); HorizontalPanel toolsPanel = new HorizontalPanel(); toolsPanel.setStyleName(ThemeStyles.INSTANCE.miniDialogTools()); ToolbarButton hideButton = new ToolbarButton(ThemeResources.INSTANCE.closeChevron(), new ClickHandler() { public void onClick(ClickEvent event) { MiniDialogPopupPanel.this.hideMiniDialog(); } }); hideButton.setTitle("Close"); toolsPanel.add(hideButton); titleBar.add(toolsPanel); titleBar.setCellHorizontalAlignment(toolsPanel, HasHorizontalAlignment.ALIGN_RIGHT); verticalPanel_.add(titleBar); // main widget verticalPanel_.add(createMainWidget()); setWidget(verticalPanel_); }
From source file:org.rstudio.studio.client.common.vcs.SshKeyWidget.java
License:Open Source License
public SshKeyWidget(GitServerOperations server, String textWidth) { server_ = server;/*from w ww. j a v a 2 s . c o m*/ progressIndicator_ = new NullProgressIndicator(); FlowPanel panel = new FlowPanel(); // caption panel HorizontalPanel captionPanel = new HorizontalPanel(); captionPanel.addStyleName(RES.styles().captionPanel()); captionPanel.setWidth(textWidth); Label sshKeyPathLabel = new Label("SSH RSA Key:"); captionPanel.add(sshKeyPathLabel); captionPanel.setCellHorizontalAlignment(sshKeyPathLabel, HasHorizontalAlignment.ALIGN_LEFT); HorizontalPanel linkPanel = new HorizontalPanel(); publicKeyLink_ = new HyperlinkLabel("View public key"); publicKeyLink_.addStyleName(RES.styles().viewPublicKeyLink()); publicKeyLink_.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { viewPublicKey(); } }); linkPanel.add(publicKeyLink_); captionPanel.add(publicKeyLink_); captionPanel.setCellHorizontalAlignment(publicKeyLink_, HasHorizontalAlignment.ALIGN_RIGHT); panel.add(captionPanel); // chooser txtSshKeyPath_ = new TextBox(); txtSshKeyPath_.addStyleName(RES.styles().keyPath()); txtSshKeyPath_.setReadOnly(true); txtSshKeyPath_.setWidth(textWidth); panel.add(txtSshKeyPath_); // ssh key path action buttons HorizontalPanel sshButtonPanel = new HorizontalPanel(); sshButtonPanel.addStyleName(RES.styles().sshButtonPanel()); createKeyButton_ = new SmallButton(); createKeyButton_.setText("Create RSA Key..."); createKeyButton_.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { showCreateKeyDialog(); } }); sshButtonPanel.add(createKeyButton_); panel.add(sshButtonPanel); initWidget(panel); }
From source file:org.rstudio.studio.client.workbench.exportplot.ExportPlotSizeEditor.java
License:Open Source License
public ExportPlotSizeEditor(int initialWidth, int initialHeight, boolean keepRatio, Widget extraWidget, ExportPlotPreviewer previewer, final Observer observer) { // alias objects and resources previewer_ = previewer;//w w w. j a va2 s .c o m observer_ = observer; ExportPlotResources resources = ExportPlotResources.INSTANCE; // main widget VerticalPanel verticalPanel = new VerticalPanel(); // if we have an extra widget then enclose it within a horizontal // panel with it on the left and the options on the right HorizontalPanel topPanel = new HorizontalPanel(); CellPanel optionsPanel = null; HorizontalPanel widthAndHeightPanel = null; if (extraWidget != null) { topPanel.setWidth("100%"); topPanel.add(extraWidget); topPanel.setCellHorizontalAlignment(extraWidget, HasHorizontalAlignment.ALIGN_LEFT); optionsPanel = new VerticalPanel(); optionsPanel.setStylePrimaryName(resources.styles().verticalSizeOptions()); optionsPanel.setSpacing(0); topPanel.add(optionsPanel); topPanel.setCellHorizontalAlignment(optionsPanel, HasHorizontalAlignment.ALIGN_RIGHT); widthAndHeightPanel = new HorizontalPanel(); widthAndHeightPanel.setStylePrimaryName(resources.styles().widthAndHeightEntry()); configureHorizontalOptionsPanel(widthAndHeightPanel); optionsPanel.add(widthAndHeightPanel); } else { optionsPanel = topPanel; optionsPanel.setStylePrimaryName(resources.styles().horizontalSizeOptions()); widthAndHeightPanel = topPanel; configureHorizontalOptionsPanel(topPanel); } // image width widthAndHeightPanel.add(createImageOptionLabel("Width:")); widthTextBox_ = createImageSizeTextBox(); widthTextBox_.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { // screen out programmatic sets if (settingDimenensionInProgress_) return; // enforce min size int width = constrainWidth(getImageWidth()); // preserve aspect ratio if requested if (getKeepRatio()) { double ratio = (double) lastHeight_ / (double) lastWidth_; int height = constrainHeight((int) (ratio * (double) width)); setHeightTextBox(height); } // set width setWidthTextBox(width); } }); widthAndHeightPanel.add(widthTextBox_); // image height widthAndHeightPanel.add(new HTML(" ")); widthAndHeightPanel.add(createImageOptionLabel("Height:")); heightTextBox_ = createImageSizeTextBox(); heightTextBox_.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { // screen out programmatic sets if (settingDimenensionInProgress_) return; // enforce min size int height = constrainHeight(getImageHeight()); // preserve aspect ratio if requested if (getKeepRatio()) { double ratio = (double) lastWidth_ / (double) lastHeight_; int width = constrainWidth((int) (ratio * (double) height)); setWidthTextBox(width); } // always set height setHeightTextBox(height); } }); widthAndHeightPanel.add(heightTextBox_); // add width and height panel to options panel container if necessary if (widthAndHeightPanel != optionsPanel) optionsPanel.add(widthAndHeightPanel); // lock ratio check box keepRatioCheckBox_ = new CheckBox(); keepRatioCheckBox_.setStylePrimaryName(resources.styles().maintainAspectRatioCheckBox()); keepRatioCheckBox_.setValue(keepRatio); keepRatioCheckBox_.setText("Maintain aspect ratio"); optionsPanel.add(keepRatioCheckBox_); // image and sizer in layout panel (create now so we can call // setSize in update button click handler) previewPanel_ = new LayoutPanel(); // update button ThemedButton updateButton = new ThemedButton("Update Preview", new ClickHandler() { public void onClick(ClickEvent event) { updatePreview(); } }); updateButton.setStylePrimaryName(resources.styles().updateImageSizeButton()); optionsPanel.add(updateButton); // add top panel verticalPanel.add(topPanel); // previewer Widget previewWidget = previewer_.getWidget(); // Stops mouse events from being routed to the iframe, which would // interfere with resizing final GlassPanel glassPanel = new GlassPanel(previewWidget); glassPanel.getChildContainerElement().getStyle().setOverflow(Overflow.VISIBLE); glassPanel.setSize("100%", "100%"); previewPanel_.add(glassPanel); previewPanel_.setWidgetLeftRight(glassPanel, 0, Unit.PX, IMAGE_INSET, Unit.PX); previewPanel_.setWidgetTopBottom(glassPanel, 0, Unit.PX, IMAGE_INSET, Unit.PX); previewPanel_.getWidgetContainerElement(glassPanel).getStyle().setOverflow(Overflow.VISIBLE); // resize gripper gripper_ = new ResizeGripper(new ResizeGripper.Observer() { @Override public void onResizingStarted() { int startWidth = getImageWidth(); int startHeight = getImageHeight(); widthAspectRatio_ = (double) startWidth / (double) startHeight; heightAspectRatio_ = (double) startHeight / (double) startWidth; glassPanel.setGlass(true); } @Override public void onResizing(int xDelta, int yDelta) { // get start width and height int startWidth = getImageWidth(); int startHeight = getImageHeight(); // calculate new height and width int newWidth = constrainWidth(startWidth + xDelta); int newHeight = constrainHeight(startHeight + yDelta); // preserve aspect ratio if requested if (getKeepRatio()) { if (Math.abs(xDelta) > Math.abs(yDelta)) newHeight = (int) (heightAspectRatio_ * (double) newWidth); else newWidth = (int) (widthAspectRatio_ * (double) newHeight); } // set text boxes setWidthTextBox(newWidth); setHeightTextBox(newHeight); // set image preview size setPreviewPanelSize(newWidth, newHeight); } @Override public void onResizingCompleted() { glassPanel.setGlass(false); previewer_.updatePreview(getImageWidth(), getImageHeight()); observer.onResized(true); } private double widthAspectRatio_ = 1.0; private double heightAspectRatio_ = 1.0; }); // layout gripper previewPanel_.add(gripper_); previewPanel_.setWidgetRightWidth(gripper_, 0, Unit.PX, gripper_.getImageWidth(), Unit.PX); previewPanel_.setWidgetBottomHeight(gripper_, 0, Unit.PX, gripper_.getImageHeight(), Unit.PX); // constrain dimensions initialWidth = constrainWidth(initialWidth); initialHeight = constrainHeight(initialHeight); // initialie text boxes setWidthTextBox(initialWidth); setHeightTextBox(initialHeight); // initialize preview setPreviewPanelSize(initialWidth, initialHeight); verticalPanel.add(previewPanel_); // set initial focus widget if (extraWidget == null) initialFocusWidget_ = widthTextBox_; else initialFocusWidget_ = null; initWidget(verticalPanel); }
From source file:org.rstudio.studio.client.workbench.prefs.views.SourceControlPreferencesPane.java
License:Open Source License
private void addTextBoxChooser(Label captionLabel, HyperlinkLabel link, String captionPanelStyle, TextBoxWithButton chooser) {//w ww. j a v a2 s. c om String textWidth = "250px"; HorizontalPanel captionPanel = new HorizontalPanel(); captionPanel.setWidth(textWidth); nudgeRight(captionPanel); if (captionPanelStyle != null) captionPanel.addStyleName(captionPanelStyle); captionPanel.add(captionLabel); captionPanel.setCellHorizontalAlignment(captionLabel, HasHorizontalAlignment.ALIGN_LEFT); if (link != null) { HorizontalPanel linkPanel = new HorizontalPanel(); linkPanel.add(link); captionPanel.add(linkPanel); captionPanel.setCellHorizontalAlignment(linkPanel, HasHorizontalAlignment.ALIGN_RIGHT); } add(tight(captionPanel)); chooser.setTextWidth(textWidth); nudgeRight(chooser); textBoxWithChooser(chooser); add(chooser); }
From source file:org.rstudio.studio.client.workbench.views.connections.ui.ConnectionCodePanel.java
License:Open Source License
public ConnectionCodePanel(boolean connectViaUI) { RStudioGinjector.INSTANCE.injectMembers(this); container_ = new VerticalPanel(); container_.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP); HorizontalPanel codeHeaderPanel = new HorizontalPanel(); codeHeaderPanel.addStyleName(RES.styles().codePanelHeader()); codeHeaderPanel.setWidth("100%"); Label codeLabel = new Label("Connection:"); codeHeaderPanel.add(codeLabel);/*from w ww .j a v a 2 s . c o m*/ codeHeaderPanel.setCellHorizontalAlignment(codeLabel, HasHorizontalAlignment.ALIGN_LEFT); HorizontalPanel connectPanel = new HorizontalPanel(); Label connectLabel = new Label("Connect from:"); connectLabel.addStyleName(RES.styles().leftLabel()); connectPanel.add(connectLabel); connectVia_ = new ListBox(); updateConnectViaUI_ = new Command() { @Override public void execute() { if (connectVia_.getSelectedValue().equals(ConnectionOptions.CONNECT_COPY_TO_CLIPBOARD)) { if (codeViewer_ != null) { codeViewer_.getEditor().getSession().getSelection().selectAll(); codeViewer_.getEditor().focus(); } } else { if (codeViewer_ != null) codeViewer_.getEditor().getSession().getSelection().moveCursorTo(0, 0, false); } } }; connectVia_.addItem("R Console", ConnectionOptions.CONNECT_R_CONSOLE); connectVia_.addItem("New R Script", ConnectionOptions.CONNECT_NEW_R_SCRIPT); connectVia_.addItem("New R Notebook", ConnectionOptions.CONNECT_NEW_R_NOTEBOOK); if (BrowseCap.INSTANCE.canCopyToClipboard()) { connectVia_.addItem("Copy to Clipboard", ConnectionOptions.CONNECT_COPY_TO_CLIPBOARD); } updateConnectViaUI_.execute(); addConnectViaChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { updateConnectViaUI_.execute(); } }); connectPanel.add(connectVia_); codeHeaderPanel.add(connectPanel); codeHeaderPanel.setCellHorizontalAlignment(connectPanel, HasHorizontalAlignment.ALIGN_RIGHT); if (connectViaUI) container_.add(codeHeaderPanel); initWidget(container_); }
From source file:org.rstudio.studio.client.workbench.views.history.view.Shelf.java
License:Open Source License
public Shelf(boolean large) { large_ = large;//from ww w.j a va 2 s . c om HorizontalPanel mainPanel = binder.createAndBindUi(this); if (large_) mainPanel.setStyleName(RES.styles().largeShelf()); initWidget(mainPanel); left_.setHeight("100%"); right_.setHeight("100%"); left_.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE); right_.setVerticalAlignment(HorizontalPanel.ALIGN_MIDDLE); mainPanel.setCellHorizontalAlignment(right_, HorizontalPanel.ALIGN_RIGHT); }
From source file:org.rstudio.studio.client.workbench.views.plots.ui.export.ExportPlotSizeEditor.java
License:Open Source License
public ExportPlotSizeEditor(int initialWidth, int initialHeight, boolean keepRatio, Widget extraWidget, PlotsServerOperations server, final Observer observer) { // alias objects and resources server_ = server;//from ww w .j a v a2 s .c o m ExportPlotResources resources = ExportPlotResources.INSTANCE; // main widget VerticalPanel verticalPanel = new VerticalPanel(); // if we have an extra widget then enclose it within a horizontal // panel with it on the left and the options on the right HorizontalPanel topPanel = new HorizontalPanel(); CellPanel optionsPanel = null; HorizontalPanel widthAndHeightPanel = null; if (extraWidget != null) { topPanel.setWidth("100%"); topPanel.add(extraWidget); topPanel.setCellHorizontalAlignment(extraWidget, HasHorizontalAlignment.ALIGN_LEFT); optionsPanel = new VerticalPanel(); optionsPanel.setStylePrimaryName(resources.styles().verticalSizeOptions()); optionsPanel.setSpacing(0); topPanel.add(optionsPanel); topPanel.setCellHorizontalAlignment(optionsPanel, HasHorizontalAlignment.ALIGN_RIGHT); widthAndHeightPanel = new HorizontalPanel(); widthAndHeightPanel.setStylePrimaryName(resources.styles().widthAndHeightEntry()); configureHorizontalOptionsPanel(widthAndHeightPanel); optionsPanel.add(widthAndHeightPanel); } else { optionsPanel = topPanel; optionsPanel.setStylePrimaryName(resources.styles().horizontalSizeOptions()); widthAndHeightPanel = topPanel; configureHorizontalOptionsPanel(topPanel); } // image width widthAndHeightPanel.add(createImageOptionLabel("Width:")); widthTextBox_ = createImageSizeTextBox(); widthTextBox_.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { // screen out programmatic sets if (settingDimenensionInProgress_) return; // enforce min size int width = constrainWidth(getImageWidth()); // preserve aspect ratio if requested if (getKeepRatio()) { double ratio = (double) lastHeight_ / (double) lastWidth_; int height = constrainHeight((int) (ratio * (double) width)); setHeightTextBox(height); } // set width setWidthTextBox(width); } }); widthAndHeightPanel.add(widthTextBox_); // image height widthAndHeightPanel.add(new HTML(" ")); widthAndHeightPanel.add(createImageOptionLabel("Height:")); heightTextBox_ = createImageSizeTextBox(); heightTextBox_.addChangeHandler(new ChangeHandler() { @Override public void onChange(ChangeEvent event) { // screen out programmatic sets if (settingDimenensionInProgress_) return; // enforce min size int height = constrainHeight(getImageHeight()); // preserve aspect ratio if requested if (getKeepRatio()) { double ratio = (double) lastWidth_ / (double) lastHeight_; int width = constrainWidth((int) (ratio * (double) height)); setWidthTextBox(width); } // always set height setHeightTextBox(height); } }); widthAndHeightPanel.add(heightTextBox_); // add width and height panel to options panel container if necessary if (widthAndHeightPanel != optionsPanel) optionsPanel.add(widthAndHeightPanel); // lock ratio check box keepRatioCheckBox_ = new CheckBox(); keepRatioCheckBox_.setStylePrimaryName(resources.styles().maintainAspectRatioCheckBox()); keepRatioCheckBox_.setValue(keepRatio); keepRatioCheckBox_.setText("Maintain aspect ratio"); optionsPanel.add(keepRatioCheckBox_); // image and sizer in layout panel (create now so we can call // setSize in update button click handler) previewPanel_ = new LayoutPanel(); // update button ThemedButton updateButton = new ThemedButton("Update Preview", new ClickHandler() { public void onClick(ClickEvent event) { setPreviewPanelSize(getImageWidth(), getImageHeight()); updateImage(); observer.onPlotResized(false); } }); updateButton.setStylePrimaryName(resources.styles().updateImageSizeButton()); optionsPanel.add(updateButton); // add top panel verticalPanel.add(topPanel); // image frame imageFrame_ = new ImageFrame(); imageFrame_.setUrl("about:blank"); imageFrame_.setSize("100%", "100%"); imageFrame_.setMarginHeight(0); imageFrame_.setMarginWidth(0); imageFrame_.setStylePrimaryName(resources.styles().imagePreview()); // Stops mouse events from being routed to the iframe, which would // interfere with resizing final GlassPanel glassPanel = new GlassPanel(imageFrame_); glassPanel.getChildContainerElement().getStyle().setOverflow(Overflow.VISIBLE); glassPanel.setSize("100%", "100%"); previewPanel_.add(glassPanel); previewPanel_.setWidgetLeftRight(glassPanel, 0, Unit.PX, IMAGE_INSET, Unit.PX); previewPanel_.setWidgetTopBottom(glassPanel, 0, Unit.PX, IMAGE_INSET, Unit.PX); previewPanel_.getWidgetContainerElement(glassPanel).getStyle().setOverflow(Overflow.VISIBLE); // resize gripper ResizeGripper gripper = new ResizeGripper(new ResizeGripper.Observer() { @Override public void onResizingStarted() { int startWidth = getImageWidth(); int startHeight = getImageHeight(); widthAspectRatio_ = (double) startWidth / (double) startHeight; heightAspectRatio_ = (double) startHeight / (double) startWidth; glassPanel.setGlass(true); } @Override public void onResizing(int xDelta, int yDelta) { // get start width and height int startWidth = getImageWidth(); int startHeight = getImageHeight(); // calculate new height and width int newWidth = constrainWidth(startWidth + xDelta); int newHeight = constrainHeight(startHeight + yDelta); // preserve aspect ratio if requested if (getKeepRatio()) { if (Math.abs(xDelta) > Math.abs(yDelta)) newHeight = (int) (heightAspectRatio_ * (double) newWidth); else newWidth = (int) (widthAspectRatio_ * (double) newHeight); } // set text boxes setWidthTextBox(newWidth); setHeightTextBox(newHeight); // set image preview size setPreviewPanelSize(newWidth, newHeight); } @Override public void onResizingCompleted() { glassPanel.setGlass(false); updateImage(); observer.onPlotResized(true); } private double widthAspectRatio_ = 1.0; private double heightAspectRatio_ = 1.0; }); // layout gripper previewPanel_.add(gripper); previewPanel_.setWidgetRightWidth(gripper, 0, Unit.PX, gripper.getImageWidth(), Unit.PX); previewPanel_.setWidgetBottomHeight(gripper, 0, Unit.PX, gripper.getImageHeight(), Unit.PX); // constrain dimensions initialWidth = constrainWidth(initialWidth); initialHeight = constrainHeight(initialHeight); // initialie text boxes setWidthTextBox(initialWidth); setHeightTextBox(initialHeight); // initialize preview setPreviewPanelSize(initialWidth, initialHeight); verticalPanel.add(previewPanel_); // set initial focus widget if (extraWidget == null) initialFocusWidget_ = widthTextBox_; else initialFocusWidget_ = null; initWidget(verticalPanel); }
From source file:org.sigmah.client.page.orgunit.reports.OrgUnitReportsView.java
License:Open Source License
public void setReport(final ProjectReportDTO report) { mainPanel.removeAll();/* ww w . j av a2s . co m*/ // currentReport = report; if (autoSaveTimer != null) { autoSaveTimer.cancel(); autoSaveTimer = null; } if (report == null) return; // Preparing the view for the new report textAreas.clear(); oldContents.clear(); keyQuestionState.clear(); // Title bar final ContentPanel reportPanel = new ContentPanel(new FitLayout()); reportPanel.setScrollMode(Scroll.AUTOY); reportPanel.setHeading(report.getName()); final ToolButton closeButton = new ToolButton("x-tool-close"); closeButton.addListener(Events.Select, new Listener<BaseEvent>() { @Override public void handleEvent(BaseEvent be) { final OrgUnitState state = new OrgUnitState(currentState.getOrgUnitId()); state.setCurrentSection(currentState.getCurrentSection()); state.setArgument("-1"); eventBus.fireEvent(new NavigationEvent(NavigationHandler.NavigationRequested, state, null)); } }); reportPanel.getHeader().addTool(closeButton); // Report container final FlowPanel flowPanel = new FlowPanel(); // Report final FoldPanel root = new FoldPanel(); root.addStyleName("project-report"); final List<ProjectReportSectionDTO> sections = report.getSections(); final StringBuilder prefix = new StringBuilder(); for (int index = 0; index < sections.size(); index++) { final ProjectReportSectionDTO section = sections.get(index); prefix.append(index + 1).append('.'); displaySection(section, root, prefix, 1, report.isDraft()); prefix.setLength(0); } // Toolbar final ToolBar toolBar = new ToolBar(); final IconImageBundle icons = GWT.create(IconImageBundle.class); if (report.isDraft()) { // Draft banner final HorizontalPanel header = new HorizontalPanel(); header.addStyleName("project-report-draft"); // The "Personal Draft" final Label personalDraft = new Label(I18N.MESSAGES.personalDraft()); personalDraft.addStyleName("project-report-personalDraft"); final DateTimeFormat dateFormat = DateTimeFormat.getMediumDateFormat(); final DateTimeFormat timeFormat = DateTimeFormat.getMediumTimeFormat(); // The label showing the last changed time final Label draftLastChangedTime = new Label(I18N.MESSAGES.reportDraftLastChanged( dateFormat.format(report.getLastEditDate()), timeFormat.format(report.getLastEditDate()))); // Add the two labels header.add(personalDraft); header.add(draftLastChangedTime); final Button cancelButton = new Button(I18N.CONSTANTS.delete()); final Button sendButton = new Button(I18N.CONSTANTS.sendReportDraft()); cancelButton.addSelectionListener(new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { final RemoveProjectReportDraft removeDraft = new RemoveProjectReportDraft( report.getVersionId()); final GetProjectReport getReport = new GetProjectReport(report.getId()); final AsyncCallback<VoidResult> callback = AsyncCallbacks.emptyCallback(); dispatcher.execute(removeDraft, null, callback); dispatcher.execute(getReport, null, new AsyncCallback<ProjectReportDTO>() { @Override public void onFailure(Throwable caught) { MessageBox.alert(I18N.CONSTANTS.projectTabReports(), I18N.CONSTANTS.reportEditError(), null); } @Override public void onSuccess(ProjectReportDTO result) { Notification.show(I18N.CONSTANTS.projectTabReports(), I18N.CONSTANTS.reportEditCancelSuccess()); setReport(result); } }); } }); sendButton.addSelectionListener(new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { final HashMap<String, Object> changes = new HashMap<String, Object>(); changes.put("currentPhase", phaseName); for (final Map.Entry<Integer, RichTextArea> entry : textAreas.entrySet()) changes.put(entry.getKey().toString(), entry.getValue().getHTML()); final UpdateEntity updateEntity = new UpdateEntity("ProjectReport", report.getVersionId(), changes); final PromoteProjectReportDraft promoteDraft = new PromoteProjectReportDraft(report.getId(), report.getVersionId()); final AsyncCallback<VoidResult> callback = AsyncCallbacks.emptyCallback(); dispatcher.execute(updateEntity, null, callback); dispatcher.execute(promoteDraft, null, new AsyncCallback<ProjectReportDTO>() { @Override public void onFailure(Throwable caught) { MessageBox.alert(I18N.CONSTANTS.projectTabReports(), I18N.CONSTANTS.reportSaveError(), null); } @Override public void onSuccess(ProjectReportDTO result) { Notification.show(I18N.CONSTANTS.projectTabReports(), I18N.CONSTANTS.reportSaveSuccess()); setReport(result); } }); } }); final HorizontalPanel buttons = new HorizontalPanel(); buttons.setSpacing(5); buttons.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); buttons.addStyleName("project-report-draft-button"); buttons.add(cancelButton); buttons.add(sendButton); header.add(buttons); header.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_RIGHT); flowPanel.add(header); // Save action final Listener<BaseEvent> saveListener = new Listener<BaseEvent>() { @Override public void handleEvent(BaseEvent be) { final HashMap<String, String> changes = new HashMap<String, String>(); changes.put("currentPhase", phaseName); for (final Map.Entry<Integer, RichTextArea> entry : textAreas.entrySet()) changes.put(entry.getKey().toString(), entry.getValue().getHTML()); final UpdateEntity updateEntity = new UpdateEntity("ProjectReport", report.getVersionId(), (Map<String, Object>) (Map<String, ?>) changes); dispatcher.execute(updateEntity, null, new AsyncCallback<VoidResult>() { @Override public void onFailure(Throwable caught) { MessageBox.alert(I18N.CONSTANTS.projectTabReports(), I18N.CONSTANTS.reportSaveError(), null); } @Override public void onSuccess(VoidResult result) { Notification.show(I18N.CONSTANTS.projectTabReports(), I18N.CONSTANTS.reportSaveSuccess()); final Date now = new Date(); header.clear(); draftLastChangedTime.setText(I18N.MESSAGES .reportDraftLastChanged(dateFormat.format(now), timeFormat.format(now))); personalDraft.setText(I18N.MESSAGES.personalDraft()); header.add(personalDraft); header.add(draftLastChangedTime); header.add(buttons); boolean found = false; for (int index = 0; !found && index < store.getCount(); index++) { final ReportReference reference = store.getAt(index); if (reference.getId().equals(report.getId())) { store.remove(reference); reference.setEditorName(authentication.getUserShortName()); reference.setPhaseName(phaseName); reference.setLastEditDate(new Date()); store.add(reference); found = true; } } updateChanges(); autoSaveTimer.cancel(); autoSaveTimer.schedule(AUTO_SAVE_PERIOD); } }); } }; // Save button final Button saveButton = new Button(I18N.CONSTANTS.save(), icons.save()); saveButton.addListener(Events.Select, saveListener); toolBar.add(saveButton); toolBar.add(new SeparatorToolItem()); // Auto save timer autoSaveTimer = new Timer() { @Override public void run() { saveListener.handleEvent(null); } }; autoSaveTimer.schedule(AUTO_SAVE_PERIOD); } else { final Button editReportButton = new Button(I18N.CONSTANTS.edit(), icons.editPage()); if (ProfileUtils.isGranted(authentication, GlobalPermissionEnum.MANAGE_UNIT)) { toolBar.add(editReportButton); } editReportButton.addSelectionListener(new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { // Draft creation final HashMap<String, Object> properties = new HashMap<String, Object>(); properties.put("reportId", report.getId()); properties.put("phaseName", phaseName); final CreateEntity createDraft = new CreateEntity("ProjectReportDraft", properties); // Retrieving the new draft final GetProjectReport getReportDraft = new GetProjectReport(report.getId()); final AsyncCallback<CreateResult> callback = AsyncCallbacks.emptyCallback(); dispatcher.execute(createDraft, null, callback); dispatcher.execute(getReportDraft, null, new AsyncCallback<ProjectReportDTO>() { @Override public void onFailure(Throwable caught) { MessageBox.alert(I18N.CONSTANTS.projectTabReports(), I18N.CONSTANTS.reportEditError(), null); } @Override public void onSuccess(ProjectReportDTO result) { setReport(result); } }); } }); final Button exportReportButton = new Button(I18N.CONSTANTS.exportToWord(), icons.msword()); toolBar.add(exportReportButton); exportReportButton.addSelectionListener(new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { final FormElement form = FormElement.as(DOM.createForm()); form.setAction(GWT.getModuleBaseURL() + "export"); form.setTarget("_downloadFrame"); form.setMethod("POST"); final InputElement typeField = InputElement.as(DOM.createInputText()); typeField.setAttribute("type", "hidden"); typeField.setName(ExportUtils.PARAM_EXPORT_TYPE); typeField.setValue(ExportUtils.ExportType.PROJECT_REPORT.toString()); form.appendChild(typeField); final InputElement formatField = InputElement.as(DOM.createInputText()); formatField.setAttribute("type", "hidden"); formatField.setName(ExportUtils.PARAM_EXPORT_FORMAT); formatField.setValue(ExportUtils.ExportFormat.MS_WORD.name()); form.appendChild(formatField); final InputElement idField = InputElement.as(DOM.createInputText()); idField.setAttribute("type", "hidden"); idField.setName(ExportUtils.PARAM_EXPORT_PROJECT_ID); idField.setAttribute("value", report.getId().toString()); form.appendChild(idField); RootPanel.getBodyElement().appendChild(form); form.submit(); form.removeFromParent(); } }); toolBar.add(new SeparatorToolItem()); } // Key question info final Label keyQuestionLabel = keyQuestionState.getLabel(); toolBar.add(keyQuestionLabel); toolBar.add(new SeparatorToolItem()); // Overview mode final Button foldButton = new Button(I18N.CONSTANTS.reportOverviewMode()); foldButton.addListener(Events.Select, new Listener<BaseEvent>() { @Override public void handleEvent(BaseEvent be) { root.expand(true); root.fold(true); } }); // Expanded mode final Button expandButton = new Button(I18N.CONSTANTS.reportFullMode()); expandButton.addListener(Events.Select, new Listener<BaseEvent>() { @Override public void handleEvent(BaseEvent be) { root.expand(true); } }); toolBar.add(foldButton); toolBar.add(expandButton); if (report.isDraft()) { toolBar.add(new SeparatorToolItem()); createRichTextToolbar(toolBar); } flowPanel.add(root); reportPanel.add(flowPanel); reportPanel.setTopComponent(toolBar); // Display mainPanel.add(reportPanel, new BorderLayoutData(LayoutRegion.CENTER)); mainPanel.layout(); mainPanel.unmask(); }
From source file:org.sigmah.client.page.project.reports.ProjectReportsView.java
License:Open Source License
public void setReport(final ProjectReportDTO report) { mainPanel.removeAll();/*from ww w . j av a2s. c o m*/ // currentReport = report; if (autoSaveTimer != null) { autoSaveTimer.cancel(); autoSaveTimer = null; } if (report == null) { currentReportId = -1; return; } currentReportId = report.getId(); // Preparing the view for the new report textAreas.clear(); oldContents.clear(); keyQuestionState.clear(); // Title bar final ContentPanel reportPanel = new ContentPanel(new FitLayout()); reportPanel.setScrollMode(Scroll.AUTOY); reportPanel.setHeading(report.getName()); final ToolButton closeButton = new ToolButton("x-tool-close"); closeButton.addListener(Events.Select, new Listener<BaseEvent>() { @Override public void handleEvent(BaseEvent be) { final ProjectState state = new ProjectState(currentState.getProjectId()); state.setCurrentSection(currentState.getCurrentSection()); state.setArgument("-1"); eventBus.fireEvent(new NavigationEvent(NavigationHandler.NavigationRequested, state, null)); } }); reportPanel.getHeader().addTool(closeButton); // Report container final FlowPanel flowPanel = new FlowPanel(); // Report final FoldPanel root = new FoldPanel(); root.addStyleName("project-report"); final List<ProjectReportSectionDTO> sections = report.getSections(); final StringBuilder prefix = new StringBuilder(); for (int index = 0; index < sections.size(); index++) { final ProjectReportSectionDTO section = sections.get(index); prefix.append(index + 1).append('.'); displaySection(section, root, prefix, 1, report.isDraft()); prefix.setLength(0); } // Toolbar final ToolBar toolBar = new ToolBar(); final IconImageBundle icons = GWT.create(IconImageBundle.class); if (report.isDraft()) { // Draft banner final HorizontalPanel header = new HorizontalPanel(); header.addStyleName("project-report-draft"); // The "Personal Draft" final Label personalDraft = new Label(I18N.MESSAGES.personalDraft()); personalDraft.addStyleName("project-report-personalDraft"); final DateTimeFormat dateFormat = DateTimeFormat.getMediumDateFormat(); final DateTimeFormat timeFormat = DateTimeFormat.getMediumTimeFormat(); // The label showing the last changed time final Label draftLastChangedTime = new Label(I18N.MESSAGES.reportDraftLastChanged( dateFormat.format(report.getLastEditDate()), timeFormat.format(report.getLastEditDate()))); // Add the two labels header.add(personalDraft); header.add(draftLastChangedTime); final Button cancelButton = new Button(I18N.CONSTANTS.delete()); final Button sendButton = new Button(I18N.CONSTANTS.sendReportDraft()); cancelButton.addSelectionListener(new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { final RemoveProjectReportDraft removeDraft = new RemoveProjectReportDraft( report.getVersionId()); final GetProjectReport getReport = new GetProjectReport(report.getId()); final AsyncCallback<VoidResult> callback = AsyncCallbacks.emptyCallback(); dispatcher.execute(removeDraft, null, callback); dispatcher.execute(getReport, null, new AsyncCallback<ProjectReportDTO>() { @Override public void onFailure(Throwable caught) { MessageBox.alert(I18N.CONSTANTS.projectTabReports(), I18N.CONSTANTS.reportEditError(), null); } @Override public void onSuccess(ProjectReportDTO result) { Notification.show(I18N.CONSTANTS.projectTabReports(), I18N.CONSTANTS.reportEditCancelSuccess()); setReport(result); } }); } }); sendButton.addSelectionListener(new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { final HashMap<String, Object> changes = new HashMap<String, Object>(); changes.put("currentPhase", phaseName); for (final Map.Entry<Integer, RichTextArea> entry : textAreas.entrySet()) changes.put(entry.getKey().toString(), entry.getValue().getHTML()); final UpdateEntity updateEntity = new UpdateEntity("ProjectReport", report.getVersionId(), changes); final PromoteProjectReportDraft promoteDraft = new PromoteProjectReportDraft(report.getId(), report.getVersionId()); final AsyncCallback<VoidResult> callback = AsyncCallbacks.emptyCallback(); dispatcher.execute(updateEntity, null, callback); dispatcher.execute(promoteDraft, null, new AsyncCallback<ProjectReportDTO>() { @Override public void onFailure(Throwable caught) { MessageBox.alert(I18N.CONSTANTS.projectTabReports(), I18N.CONSTANTS.reportSaveError(), null); } @Override public void onSuccess(ProjectReportDTO result) { Notification.show(I18N.CONSTANTS.projectTabReports(), I18N.CONSTANTS.reportSaveSuccess()); setReport(result); } }); } }); final HorizontalPanel buttons = new HorizontalPanel(); buttons.setSpacing(5); buttons.setVerticalAlignment(HasVerticalAlignment.ALIGN_MIDDLE); buttons.addStyleName("project-report-draft-button"); buttons.add(cancelButton); buttons.add(sendButton); header.add(buttons); header.setCellHorizontalAlignment(buttons, HasHorizontalAlignment.ALIGN_RIGHT); flowPanel.add(header); // Save action final Listener<BaseEvent> saveListener = new Listener<BaseEvent>() { @Override public void handleEvent(BaseEvent be) { final HashMap<String, String> changes = new HashMap<String, String>(); changes.put("currentPhase", phaseName); for (final Map.Entry<Integer, RichTextArea> entry : textAreas.entrySet()) changes.put(entry.getKey().toString(), entry.getValue().getHTML()); final UpdateEntity updateEntity = new UpdateEntity("ProjectReport", report.getVersionId(), (Map<String, Object>) (Map<String, ?>) changes); dispatcher.execute(updateEntity, null, new AsyncCallback<VoidResult>() { @Override public void onFailure(Throwable caught) { MessageBox.alert(I18N.CONSTANTS.projectTabReports(), I18N.CONSTANTS.reportSaveError(), null); } @Override public void onSuccess(VoidResult result) { Notification.show(I18N.CONSTANTS.projectTabReports(), I18N.CONSTANTS.reportSaveSuccess()); final Date now = new Date(); header.clear(); draftLastChangedTime.setText(I18N.MESSAGES .reportDraftLastChanged(dateFormat.format(now), timeFormat.format(now))); personalDraft.setText(I18N.MESSAGES.personalDraft()); header.add(personalDraft); header.add(draftLastChangedTime); header.add(buttons); boolean found = false; for (int index = 0; !found && index < store.getCount(); index++) { final ReportReference reference = store.getAt(index); if (reference.getId().equals(report.getId())) { store.remove(reference); reference.setEditorName(authentication.getUserShortName()); reference.setPhaseName(phaseName); reference.setLastEditDate(new Date()); store.add(reference); found = true; } } updateChanges(); autoSaveTimer.cancel(); autoSaveTimer.schedule(AUTO_SAVE_PERIOD); } }); } }; // Save button final Button saveButton = new Button(I18N.CONSTANTS.save(), icons.save()); saveButton.addListener(Events.Select, saveListener); toolBar.add(saveButton); toolBar.add(new SeparatorToolItem()); // Auto save timer autoSaveTimer = new Timer() { @Override public void run() { saveListener.handleEvent(null); } }; autoSaveTimer.schedule(AUTO_SAVE_PERIOD); } else { final Button editReportButton = new Button(I18N.CONSTANTS.edit(), icons.editPage()); if (ProfileUtils.isGranted(authentication, GlobalPermissionEnum.EDIT_PROJECT)) { toolBar.add(editReportButton); } editReportButton.addSelectionListener(new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { // Draft creation final HashMap<String, Object> properties = new HashMap<String, Object>(); properties.put("reportId", report.getId()); properties.put("phaseName", phaseName); final CreateEntity createDraft = new CreateEntity("ProjectReportDraft", properties); // Retrieving the new draft final GetProjectReport getReportDraft = new GetProjectReport(report.getId()); final AsyncCallback<CreateResult> callback = AsyncCallbacks.emptyCallback(); dispatcher.execute(createDraft, null, callback); dispatcher.execute(getReportDraft, null, new AsyncCallback<ProjectReportDTO>() { @Override public void onFailure(Throwable caught) { MessageBox.alert(I18N.CONSTANTS.projectTabReports(), I18N.CONSTANTS.reportEditError(), null); } @Override public void onSuccess(ProjectReportDTO result) { setReport(result); } }); } }); final Button exportReportButton = new Button(I18N.CONSTANTS.exportToWord(), icons.msword()); toolBar.add(exportReportButton); exportReportButton.addSelectionListener(new SelectionListener<ButtonEvent>() { @Override public void componentSelected(ButtonEvent ce) { final FormElement form = FormElement.as(DOM.createForm()); form.setAction(GWT.getModuleBaseURL() + "export"); form.setTarget("_downloadFrame"); form.setMethod("POST"); final InputElement typeField = InputElement.as(DOM.createInputText()); typeField.setAttribute("type", "hidden"); typeField.setName(ExportUtils.PARAM_EXPORT_TYPE); typeField.setValue(ExportUtils.ExportType.PROJECT_REPORT.toString()); form.appendChild(typeField); final InputElement formatField = InputElement.as(DOM.createInputText()); formatField.setAttribute("type", "hidden"); formatField.setName(ExportUtils.PARAM_EXPORT_FORMAT); formatField.setValue(ExportUtils.ExportFormat.MS_WORD.name()); form.appendChild(formatField); final InputElement idField = InputElement.as(DOM.createInputText()); idField.setAttribute("type", "hidden"); idField.setName(ExportUtils.PARAM_EXPORT_PROJECT_ID); idField.setAttribute("value", report.getId().toString()); form.appendChild(idField); RootPanel.getBodyElement().appendChild(form); form.submit(); form.removeFromParent(); } }); toolBar.add(new SeparatorToolItem()); } // Key question info final Label keyQuestionLabel = keyQuestionState.getLabel(); toolBar.add(keyQuestionLabel); toolBar.add(new SeparatorToolItem()); // Overview mode final Button foldButton = new Button(I18N.CONSTANTS.reportOverviewMode()); foldButton.addListener(Events.Select, new Listener<BaseEvent>() { @Override public void handleEvent(BaseEvent be) { root.expand(true); root.fold(true); } }); // Expanded mode final Button expandButton = new Button(I18N.CONSTANTS.reportFullMode()); expandButton.addListener(Events.Select, new Listener<BaseEvent>() { @Override public void handleEvent(BaseEvent be) { root.expand(true); } }); toolBar.add(foldButton); toolBar.add(expandButton); if (report.isDraft()) { toolBar.add(new SeparatorToolItem()); createRichTextToolbar(toolBar); } flowPanel.add(root); reportPanel.add(flowPanel); reportPanel.setTopComponent(toolBar); // Display mainPanel.add(reportPanel, new BorderLayoutData(LayoutRegion.CENTER)); mainPanel.layout(); mainPanel.unmask(); }