Java Code Examples for com.google.gwt.user.client.Command

The following examples show how to use com.google.gwt.user.client.Command. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: vertx-vaadin   Source File: SockJSPushConnection.java    License: MIT License 6 votes vote down vote up
@Override
public void disconnect(Command command) {
    assert command != null;

    switch (state) {
        case CONNECTING:
            // Make the connection callback initiate the disconnection again
            state = State.CLOSING;
            pendingDisconnectCommand = command;
            break;
        case OPEN:
            // Normal disconnect
            getLogger().info("Closing push connection");
            doDisconnect(socket);
            state = State.CLOSED;
            command.execute();
            break;
        case CLOSING:
        case CLOSED:
            throw new IllegalStateException(
                "Can not disconnect more than once");
    }

}
 
Example 2
Source Project: EasyML   Source File: DiagramController.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Show the context menu of the mouse position.(Position from mouse down event)
 * 
 * @param event  mouse down event.
 */
public void showContextualMenu(MouseDownEvent event){
	final int X = event.getRelativeX(widgetPanel.getElement());
	final int Y = event.getRelativeY(widgetPanel.getElement());
	getMousePoint().setLeft(X);
	getMousePoint().setTop(Y);

	final int offsetX = event.getClientX();
	final int offsetY = event.getClientY();
	mouseOffsetPoint.setLeft(offsetX);
	mouseOffsetPoint.setTop(offsetY);

	cmenu.hide();
	cmenu = new ContextMenu();
	Command command = new Command() {
		@Override
		public void execute() {
			cmenu.hide();
		}
	};
}
 
Example 3
Source Project: unitime   Source File: SuggestionsPageContext.java    License: Apache License 2.0 6 votes vote down vote up
protected void invert(final DateLocation date, boolean fireUpdate) {
	if (iSelectedDate != null) {
		iSelectedDate.removeStyleName("selected");
		if (iSelectedDate.equals(date)) {
			iSelectedDate = null;
			return;
		}
	}
	iSelectedDate = date;
	if (iSelectedDate != null) iSelectedDate.addStyleName("selected");
	if (fireUpdate) onSelection(new Command() {
		@Override
		public void execute() {
			invert(date, false);
		}
	});
}
 
Example 4
Source Project: EasyML   Source File: ProgramUpdateMenu.java    License: Apache License 2.0 6 votes vote down vote up
public static MenuItem create(final ProgramLeaf node, final ProgramTree tree) {

		Command command = new MenuItemCommand(node) {

			@Override
			public void execute() {
				UpdateProgramPanel panel = new UpdateProgramPanel(tree,node);
				panel.show(node.getModule());
				this.component.getContextMenu().hide();
			}

		};

		MenuItem item = new MenuItem("Update", command);
		return item;
	}
 
Example 5
Source Project: unitime   Source File: StudentStatusDialog.java    License: Apache License 2.0 6 votes vote down vote up
public void massCancel(Command command) {
	iCommand = command;
	iForm.clear();
	if (iSubject.getText().isEmpty() || iSubject.getText().equals(MESSAGES.defaulSubject()) || iSubject.getText().equals(SectioningStatusCookie.getInstance().getEmailSubject()))
		iSubject.setText(MESSAGES.defaulSubjectMassCancel());
	iForm.addRow(MESSAGES.emailSubject(), iSubject);
	iForm.addRow(MESSAGES.emailCC(), iCC);
	iForm.addRow(MESSAGES.emailBody(), iMessage);
	iStatus.setSelectedIndex(0);
	for (int i = 0; i < iStatus.getItemCount(); i++)
		if ("Cancelled".equalsIgnoreCase(iStatus.getValue(i))) {
			iStatus.setSelectedIndex(i);
			break;
		}
	iStatusRow = iForm.addRow(MESSAGES.newStatus(), iStatus);
	iForm.addBottomRow(iButtons);
	iButtons.setEnabled("set-note", false);
	iButtons.setEnabled("send-email", false);
	iButtons.setEnabled("mass-cancel", true);
	iButtons.setEnabled("set-status", false);
	setText(MESSAGES.massCancel());
	statusChanged();
	center();
}
 
Example 6
Source Project: EasyML   Source File: BaseWidgetMenuItemFactory.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create DownloadDataItem
 * @param com
 * @return DownloadDataItem
 */
public static MenuItem createDownloadData(HasRightMouseUpMenu com) {
	Command command = new MenuItemCommand(com) {

		@Override
		public void execute() {

			DatasetWidget widget = (DatasetWidget) this.component;
			widget.getContextMenu().hide();
			OutNodeShape shape = widget.getOutNodeShapes().get(0);
			String filename = shape.getAbsolutePath() + "/" + shape.getFileId();
			String url = GWT.getModuleBaseURL().split("EMLStudio")[0]
					+ "EMLStudioMonitor/filedownload?filename=" + filename;
			Window.open(url, "_blank", "status=0,toolbar=0,menubar=0,location=0");

		}

	};

	MenuItem item = new MenuItem("Download", command);
	return item;
}
 
Example 7
Source Project: unitime   Source File: SuggestionsPage.java    License: Apache License 2.0 6 votes vote down vote up
protected void selectAssignment(SelectedAssignment selection, Command undo) {
	if (selection == null) return;
	SelectedAssignmentsRequest request = new SelectedAssignmentsRequest(selection.getClassId());
	if (iSelectedAssignments != null) {
		for (Iterator<SelectedAssignment> i =  iSelectedAssignments.iterator(); i.hasNext(); ) {
			SelectedAssignment a = i.next();
			if (!a.getClassId().equals(request.getClassId()))
				request.addAssignment(a);
			else
				i.remove();
		}
		iSelectedAssignments.add(selection);
	} else {
		iSelectedAssignments = new ArrayList<SelectedAssignment>();
		iSelectedAssignments.add(selection);
	}
	request.addAssignment(selection);
	computeSuggestion(request, undo);
}
 
Example 8
@Override
public void addItem(String name, Command onSelect) {
    AnchorElement anchor = Document.get().createAnchorElement();
    anchor.setInnerText(name);

    LIElement li = Document.get().createLIElement();
    li.getStyle().setCursor(Style.Cursor.POINTER);
    li.appendChild(anchor);
    selectorItems.appendChild((Node) li);

    Event.sinkEvents(anchor, Event.ONCLICK);
    Event.setEventListener(anchor, event -> {
        if(Event.ONCLICK == event.getTypeInt()) {
            onSelect.execute();
        }
    });
}
 
Example 9
@Override
protected void execute(final ProjectNode node) {
  Ode.getInstance().getEditorManager().generateYailForBlocksEditors(
      new Command() {
        @Override
        public void execute() {
          executeNextCommand(node);
        }
      },
      new Command() {
        @Override
        public void execute() {
          executionFailedOrCanceled();
        }
      });
}
 
Example 10
Source Project: unitime   Source File: SuggestionsPage.java    License: Apache License 2.0 6 votes vote down vote up
protected void computeSuggestion(final SelectedAssignmentsRequest request, final Command undo) {
	iCurrentAssignment.showLoading();
	RPC.execute(request, new AsyncCallback<Suggestion>() {
		@Override
		public void onFailure(Throwable t) {
			if (undo != null) undo.execute();
			iCurrentAssignment.setErrorMessage(MESSAGES.failedToComputeSelectedAssignment(t.getMessage()));
			UniTimeNotifications.error(MESSAGES.failedToComputeSelectedAssignment(t.getMessage()), t);
		}

		@Override
		public void onSuccess(Suggestion suggestion) {
			iCurrentAssignment.clearMessage();
			iCurrentAssignment.setShowUnassign(!suggestion.hasDifferentAssignments());
			iSelectedSuggestion.setValue(suggestion);
			if (iSuggestions != null) iSuggestions.setRequest(request);
		}
	});
}
 
Example 11
Source Project: appinventor-extensions   Source File: TopToolbar.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void execute() {
  ProjectRootNode projectRootNode = Ode.getInstance().getCurrentYoungAndroidProjectRootNode();
  if (projectRootNode != null) {
    String target = YoungAndroidProjectNode.YOUNG_ANDROID_TARGET_ANDROID;
    ChainableCommand cmd = new SaveAllEditorsCommand(
        new GenerateYailCommand(
            new BuildCommand(target, secondBuildserver,
              new ShowProgressBarCommand(target,
                new WaitForBuildResultCommand(target,
                  new DownloadProjectOutputCommand(target)), "DownloadAction"))));
    if (!Ode.getInstance().getWarnBuild(secondBuildserver)) {
      cmd = new WarningDialogCommand(target, secondBuildserver, cmd);
      Ode.getInstance().setWarnBuild(secondBuildserver, true);
    }
    cmd.startExecuteChain(Tracking.PROJECT_ACTION_BUILD_DOWNLOAD_YA, projectRootNode,
        new Command() {
          @Override
          public void execute() {
          }
        });
  }
}
 
Example 12
Source Project: appinventor-extensions   Source File: UserSettings.java    License: Apache License 2.0 6 votes vote down vote up
public void loadSettings(final Command next) {
  loading = true;
  Ode.getInstance().getUserInfoService().loadUserSettings(
      new OdeAsyncCallback<String>(MESSAGES.settingsLoadError()) {
        @Override
        public void onSuccess(String result) {
          OdeLog.log("Loaded global settings: " + result);
          decodeSettings(result);

          changed = false;
          loaded = true;
          loading = false;

          if (Ode.handleUserLocale() && next != null) {
            next.execute();
          }
        }

        @Override
        public void onFailure(Throwable caught) {
          super.onFailure(caught);
          loading = false;
        }
      });
}
 
Example 13
@Override
public void show() {
  super.show();
  // Wizard size (having it resize between page changes is quite annoying)
  int width = 340;
  int height = 40;
  this.center();

  setPixelSize(width, height);
  super.setPagePanelHeight(85);

  DeferredCommand.addCommand(new Command() {
    public void execute() {
      projectNameTextBox.setFocus(true);
      projectNameTextBox.selectAll();
    }
  });
}
 
Example 14
@Override
protected void onReset() {
    super.onReset();

    loadSocketBindings(new Command() {
        @Override
        public void execute() {

            if (serverStore.getSelectedServer() != null) {
                refreshView();
            }

            getView().toggle(
                    placeManager.getCurrentPlaceRequest().getParameter("action", "none")
            );
        }
    });
}
 
Example 15
@Override
public void show() {
  super.show();
  // Wizard size (having it resize between page changes is quite annoying)
  int width = 500;
  int height = 40;
  this.center();

  setPixelSize(width, height);
  super.setPagePanelHeight(40);

  DeferredCommand.addCommand(new Command() {
    public void execute() {
      urlTextBox.setFocus(true);
      urlTextBox.selectAll();
    }
  });
}
 
Example 16
@Override
public void prepareFromRequest(PlaceRequest request) {
    Command cmd = () ->  {
        getProxy().manualReveal(ServerConfigPresenter.this);
    };

    SecurityContextChangedEvent.AddressResolver resolver = new SecurityContextChangedEvent.AddressResolver<AddressTemplate>() {
        @Override
        public String resolve(AddressTemplate template) {
            String resolved = template.resolveAsKey(statementContext, serverStore.getSelectedServer().getServerName());
            return resolved;
        }
    };

    // RBAC: context change propagation
    SecurityContextChangedEvent.fire(
            ServerConfigPresenter.this,
            cmd,
            resolver
    );

}
 
Example 17
Source Project: appinventor-extensions   Source File: EditorManager.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates the editor manager.
 */
public EditorManager() {
  openProjectEditors = Maps.newHashMap();

  dirtyProjectSettings = new HashSet<ProjectSettings>();
  dirtyFileEditors = new HashSet<FileEditor>();

  autoSaveTimer = new Timer() {
    @Override
    public void run() {
      // When the timer goes off, save all dirtyProjectSettings and
      // dirtyFileEditors.
      Ode.getInstance().lockScreens(true); // Lock out changes
      saveDirtyEditors(new Command() {
          @Override
          public void execute() {
            Ode.getInstance().lockScreens(false); // I/O finished, unlock
          }
        });
    }
  };
}
 
Example 18
Source Project: incubator-retired-wave   Source File: StageTwoProvider.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Swaps order of open and render.
 */
@Override
protected void install() {
  if (isNewWave) {
    // For a new wave, initial state comes from local initialization.
    getConversations().createRoot().getRootThread().appendBlip();

    // Adding any initial participant to the new wave
    getConversations().getRoot().addParticipantIds(otherParticipants);
    super.install();
    whenReady.use(StageTwoProvider.this);
  } else {
    // For an existing wave, while we're still using the old protocol,
    // rendering must be delayed until the channel is opened, because the
    // initial state snapshots come from the channel.
    getConnector().connect(new Command() {
      @Override
      public void execute() {
        // This code must be kept in sync with the default install()
        // method, but excluding the connect() call.

        // Install diff control before rendering, because logical diff state
        // may
        // need to be adjusted due to arbitrary UI policies.
        getDiffController().install();

        // Ensure the wave is rendered.
        stageOne.getDomAsViewProvider().setRenderer(getRenderer());
        ensureRendered();

        // Install eager UI.
        installFeatures();

        // Rendering, and therefore the whole stage is now ready.
        whenReady.use(StageTwoProvider.this);
      }
    });
  }
}
 
Example 19
Source Project: EasyML   Source File: Connection.java    License: Apache License 2.0 5 votes vote down vote up
protected void initMenu() {
	menu = new ContextMenu();
	menu.addItem(new MenuItem(deleteMenuText, true, new Command() {
		@Override
		public void execute() {
			controller.deleteConnection(Connection.this);
			startShape.removeConnection(Connection.this);
			endShape.removeConnection(Connection.this);
			menu.hide();
		}
	}));
}
 
Example 20
Source Project: EasyML   Source File: ProgramEditMenu.java    License: Apache License 2.0 5 votes vote down vote up
public static MenuItem create(final ProgramLeaf node, final ProgramTree tree) {

		Command command = new MenuItemCommand(node) {
			@Override
			public void execute() {
				EditProgramPanel panel = new EditProgramPanel(AppController.email,tree,node);

				panel.show(node.getModule());

				this.component.getContextMenu().hide();
			}
		};
		MenuItem item = new MenuItem("Edit", command);
		return item;
	}
 
Example 21
Source Project: appinventor-extensions   Source File: ChainableCommand.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Kick off the chain of commands.
 *
 * @param actionName the name of action this chain of commands represents
 * @param node the project node to which the chain of commands is applied
 * @param finallyCommand a command to execute after the chain is finished,
 *                       regardless of whether it succeeds
 */
public final void startExecuteChain(String actionName, ProjectNode node,
    Command finallyCommand) {
  // The node must not be null.
  // If you are calling startExecuteChain with null for the node parameter, maybe you should
  // question why you are using a ChainableCommand at all. ChainableCommands were designed to
  // perform an operation on a ProjectNode.
  Preconditions.checkNotNull(node);

  setFinallyCommand(finallyCommand);
  initTrackingInformation(actionName, new Duration());

  executeLink(node);
}
 
Example 22
@Override
public void execute(final ProjectNode node) {
  // Ode.getInstance().getEditorManager().saveDirtyEditors(new Command() {
  final Ode ode = Ode.getInstance();
  ode.lockScreens(true);      // Lock out screen switching
  ode.getEditorManager().saveDirtyEditors(new Command() {
    @Override
    public void execute() {
      ode.lockScreens(false); // Screen switch OK now
      ErrorReporter.reportInfo(MESSAGES.savedProject(
          DateTimeFormat.getMediumDateTimeFormat().format(new Date())));
      executeNextCommand(node);
    }
  });
}
 
Example 23
Source Project: swellrt   Source File: LiveChannelBinder.java    License: Apache License 2.0 5 votes vote down vote up
private LiveChannelBinder(StaticChannelBinder binder, WaveletOperationalizer operationalizer,
    WaveViewImpl<OpBasedWavelet> wave, OperationChannelMultiplexer mux, Command whenOpened,
    WaveDocOpTracker docOpCache) {
  this.binder = binder;
  this.operationalizer = operationalizer;
  this.wave = wave;
  this.mux = mux;
  this.whenOpened = whenOpened;
  this.docOpCache = docOpCache;
}
 
Example 24
Source Project: unitime   Source File: UniTimeConfirmationDialog.java    License: Apache License 2.0 5 votes vote down vote up
public static void _confirm(String message, final JavaScriptObject callback, String question, String answer) {
	new UniTimeConfirmationDialog(callback == null ? Type.ALERT : Type.CONFIRM, message, question, answer, callback == null ? null : new Command() {
		@Override
		public void execute() {
			fireCallback(callback);
		}
	}).center();
}
 
Example 25
Source Project: unitime   Source File: StudentSectioningWidget.java    License: Apache License 2.0 5 votes vote down vote up
protected Command confirmEnrollmentVariableCredits(final Command callback) {
	if (iEligibilityCheck != null && iEligibilityCheck.hasGradeModes()) {
		final List<String> changes = getCourseChangesWithVarbiableCredit();
		if (changes != null && !changes.isEmpty()) {
			return new Command() {
				@Override
				public void execute() {
					UniTimeConfirmationDialog.confirm(useDefaultConfirmDialog(), MESSAGES.confirmEnrollmentVariableCreditChange(ToolBox.toString(changes)), callback);
				}
			};
		}
	}
	return callback;
}
 
Example 26
Source Project: unitime   Source File: SuggestionsPageContext.java    License: Apache License 2.0 5 votes vote down vote up
protected void select(final TimeLocation time, boolean fireUpdate) {
	if (iSelectedTime != null)
		iSelectedTime.removeStyleName("selected");
	iSelectedTime = time;
	if (iSelectedTime != null) iSelectedTime.addStyleName("selected");
	if (fireUpdate) onSelection(new Command() {
		@Override
		public void execute() {
			invert(time, false);
		}
	});
}
 
Example 27
Source Project: swellrt   Source File: PopupMenu.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Constructs a {@PopupMenuItem}
 *
 * @param text The text label for the item.
 * @param cmd The command to run when the item is clicked.
 * @param isEnabled True if this menu item is enabled.
 * @param hide True if clicking this menu item should hide the popup.
 */
public PopupMenuItem(String text, Command cmd, boolean isEnabled, boolean hide) {
  super(text);
  setStyleName(RESOURCES.css().item());
  setEnabled(isEnabled);
  defaultEnabled = isEnabled;
  command = cmd;
  this.hide = hide;
  if (isPreClicked) {
    // If this menu is pre-clicked it doesn't require a full click to select
    // an item, just a mouseup over the item.  If the user then does click the
    // item then that will also give a mouseup so this handler will deal with
    // that case as well.
    addMouseUpHandler(new MouseUpHandler() {
      @Override
      public void onMouseUp(MouseUpEvent event) {
        onClicked();
      }
    });
  } else {
    addClickHandler(new ClickHandler() {
      public void onClick(ClickEvent e) {
        onClicked();
      }
    });
  }
  // Ensure that clicking this menu item doesn't affect the current selection.
  addMouseDownHandler(PREVENT_DEFAULT_HANDLER);
}
 
Example 28
Source Project: appinventor-extensions   Source File: ContextMenu.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Adds a menu item to the context menu.
 *
 * @param text  caption of menu item
 * @param command   command to execute when menu item is chosen
 * @return  menu item
 */
public MenuItem addItem(String text, final Command command) {
  MenuItem menuItem = new MenuItem(text, new Command() {
    @Override
    public void execute() {
      hide();
      command.execute();
    }
  });
  menuItem.setStylePrimaryName("ode-ContextMenuItem");
  menuBar.addItem(menuItem);
  return menuItem;
}
 
Example 29
Source Project: appinventor-extensions   Source File: Box.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a control to resize the box.
 */
private ResizeControl() {
  super(false); // no autohide

  VerticalPanel buttonPanel = new VerticalPanel();
  buttonPanel.setSpacing(10);
  addControlButton(buttonPanel, "-", new Command() {
    @Override
    public void execute() {
      height = Math.max(100, height - 20);
      restoreHeight = height;
      onResize(width, height);
    }
  });
  addControlButton(buttonPanel, "+", new Command() {
    @Override
    public void execute() {
      height = height + 20;
      restoreHeight = height;
      onResize(width, height);
    }
  });
  addControlButton(buttonPanel, MESSAGES.done(), new Command() {
    @Override
    public void execute() {
      hide();
    }
  });
  add(buttonPanel);

  setModal(true);
  setStylePrimaryName("ode-BoxResizeControl");
}
 
Example 30
Source Project: incubator-retired-wave   Source File: GadgetWidgetUi.java    License: Apache License 2.0 5 votes vote down vote up
private void buildMenu() {
  // TODO(user): Use menu builder.
  menu = new MenuButton(CSS.metaButton() + " " + CSS.more(), "Gadget menu");
  menu.addItem("Delete gadget", new Command() {
    @Override
    public void execute() {
      if (listener != null) {
        listener.deleteGadget();
      }
    }
  }, true);
  menu.addItem("Select", new Command() {
    @Override
    public void execute() {
      if (listener != null) {
        listener.selectGadget();
      }
    }
  }, true);
  menu.addItem("Reset", new Command() {
    @Override
    public void execute() {
      if (listener != null) {
        listener.resetGadget();
      }
    }
  }, true);
  metaButtonsPanel.add(menu.getButton());
}