/** Initializes and assembles all commands into buttons in the toolbar. */ public DesignToolbar() { super(); projectNameLabel = new Label(); projectNameLabel.setStyleName("ya-ProjectName"); HorizontalPanel toolbar = (HorizontalPanel) getWidget(); toolbar.insert(projectNameLabel, 0); toolbar.setCellWidth(projectNameLabel, "222px"); // width of palette minus // cellspacing/border of buttons addButton(new ToolbarItem(WIDGET_NAME_SAVE, MESSAGES.saveButton(), new SaveAction())); addButton(new ToolbarItem(WIDGET_NAME_SAVE_AS, MESSAGES.saveAsButton(), new SaveAsAction())); addButton( new ToolbarItem( WIDGET_NAME_CHECKPOINT, MESSAGES.checkpointButton(), new CheckpointAction())); if (AppInventorFeatures.allowMultiScreenApplications()) { addButton( new ToolbarItem(WIDGET_NAME_ADDFORM, MESSAGES.addFormButton(), new AddFormAction())); addButton( new ToolbarItem( WIDGET_NAME_REMOVEFORM, MESSAGES.removeFormButton(), new RemoveFormAction())); } List<ToolbarItem> connectToItems = Lists.newArrayList(); addDropDownButton(WIDGET_NAME_CONNECT_TO, MESSAGES.connectToButton(), connectToItems, true); updateConnectToDropDownButton(false, false, false); List<ToolbarItem> screenItems = Lists.newArrayList(); addDropDownButton(WIDGET_NAME_SCREENS_DROPDOWN, MESSAGES.screensButton(), screenItems, true); addButton( new ToolbarItem( WIDGET_NAME_SWITCH_TO_FORM_EDITOR, MESSAGES.switchToFormEditorButton(), new SwitchToFormEditorAction()), true); addButton( new ToolbarItem( WIDGET_NAME_SWITCH_TO_BLOCKS_EDITOR, MESSAGES.switchToBlocksEditorButton(), new SwitchToBlocksEditorAction()), true); List<ToolbarItem> buildItems = Lists.newArrayList(); buildItems.add( new ToolbarItem( WIDGET_NAME_BUILD_BARCODE, MESSAGES.showBarcodeButton(), new BarcodeAction())); buildItems.add( new ToolbarItem( WIDGET_NAME_BUILD_DOWNLOAD, MESSAGES.downloadToComputerButton(), new DownloadAction())); if (AppInventorFeatures.hasYailGenerationOption() && Ode.getInstance().getUser().getIsAdmin()) { buildItems.add( new ToolbarItem( WIDGET_NAME_BUILD_YAIL, MESSAGES.generateYailButton(), new GenerateYailAction())); } addDropDownButton(WIDGET_NAME_BUILD, MESSAGES.buildButton(), buildItems, true); toggleEditor(false); // Gray out the Designer button and enable the blocks button }
/** Enables and/or disables buttons based (mostly) on whether there is a current form. */ private void updateButtons() { String screenName = (currentProject == null) ? null : currentProject.currentScreen; boolean enabled = (currentProject != null); setButtonEnabled(WIDGET_NAME_SAVE, enabled); setButtonEnabled(WIDGET_NAME_SAVE_AS, enabled); setButtonEnabled(WIDGET_NAME_CHECKPOINT, enabled); setDropItemEnabled(WIDGET_NAME_BUILD, WIDGET_NAME_BUILD_BARCODE, enabled); setDropItemEnabled(WIDGET_NAME_BUILD, WIDGET_NAME_BUILD_DOWNLOAD, enabled); if (AppInventorFeatures.allowMultiScreenApplications()) { setButtonEnabled(WIDGET_NAME_ADDFORM, enabled); enabled = (currentProject != null && !YoungAndroidSourceNode.SCREEN1_FORM_NAME.equals(screenName)); setButtonEnabled(WIDGET_NAME_REMOVEFORM, enabled); } if (currentProject != null) { setDropDownButtonCaption(WIDGET_NAME_SCREENS_DROPDOWN, screenName); } else { setDropDownButtonCaption(WIDGET_NAME_SCREENS_DROPDOWN, MESSAGES.screensButton()); } }