List of usage examples for com.google.gwt.core.client JsArrayString get
public final native String get(int index) ;
From source file:org.rstudio.studio.client.workbench.views.source.editors.text.ChunkHtmlPage.java
License:Open Source License
public ChunkHtmlPage(String url, NotebookHtmlMetadata metadata, int ordinal, final Command onRenderComplete, ChunkOutputSize chunkOutputSize) { super(ordinal); // extract classes from metadata if present JsArrayString classes = JsArrayString.createArray().cast(); if (metadata != null) classes = metadata.getClasses(); String clazz = classes.length() > 0 ? classes.get(0) : "html"; thumbnail_ = new ChunkOutputThumbnail(clazz, classes.length() > 1 ? classes.get(1) : "", new ChunkHtmlPreview(), ChunkOutputWidget.getEditorColors()); // amend the URL to cause any contained widget to use the RStudio viewer // sizing policy if (url.indexOf('?') > 0) url += "&"; else// w w w. ja va2s . c o m url += "?"; url += "viewer_pane=1"; frame_ = new ChunkOutputFrame(); if (chunkOutputSize != ChunkOutputSize.Full) { content_ = new FixedRatioWidget(frame_, ChunkOutputUi.OUTPUT_ASPECT, ChunkOutputUi.MAX_HTMLWIDGET_WIDTH); } else { frame_.getElement().getStyle().setWidth(100, Unit.PCT); content_ = frame_; } frame_.loadUrlDelayed(url, 400, new Command() { @Override public void execute() { Element body = frame_.getDocument().getBody(); Style bodyStyle = body.getStyle(); bodyStyle.setPadding(0, Unit.PX); bodyStyle.setMargin(0, Unit.PX); onEditorThemeChanged(ChunkOutputWidget.getEditorColors()); Timer frameFinishLoadTimer = new Timer() { @Override public void run() { onRenderComplete.execute(); } }; frameFinishLoadTimer.schedule(100); }; }); afterRender_ = new Command() { @Override public void execute() { Element body = frame_.getDocument().getBody(); Style bodyStyle = body.getStyle(); bodyStyle.setPadding(0, Unit.PX); bodyStyle.setMargin(0, Unit.PX); if (themeColors_ != null) { bodyStyle.setColor(themeColors_.foreground); } } }; frame_.runAfterRender(afterRender_); }
From source file:org.rstudio.studio.client.workbench.views.source.editors.text.rmd.ChunkContextUi.java
License:Open Source License
@Override public void switchChunk(String chunkType) { if (chunk_ != null) { DocDisplay docDisplay = target_.getDocDisplay(); Position start = chunk_.getPreamble(); Position end = chunk_.getEnd(); String chunkText = docDisplay.getTextForRange(Range.fromPoints(start, end)); JsArrayString chunkLines = StringUtil.split(chunkText, "\n"); if (chunkLines.length() > 0) { String firstLine = chunkLines.get(0); Position linedEnd = Position.create(start.getRow(), firstLine.length()); String newFirstLine = firstLine.replaceFirst("[, ]*engine='[a-zA-Z]+'", ""); newFirstLine = newFirstLine.replaceFirst("{[a-zA-Z]+", "{" + chunkType); docDisplay.replaceRange(Range.fromPoints(start, linedEnd), newFirstLine); target_.getNotebook().clearChunkOutput(chunk_); }// w ww .j av a 2 s .co m } }
From source file:org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTargetRMarkdownHelper.java
License:Open Source License
private RmdFrontMatterOutputOptions transferOptions(RmdFrontMatter frontMatter, RmdTemplate template, String format) {//w ww .jav a 2 s . c o m RmdFrontMatterOutputOptions result = RmdFrontMatterOutputOptions.create(); // loop over each option applicable to the new format; if it's // transferable, try to find it in one of the other formats JsArrayString options = template.getFormat(format).getOptions(); for (int i = 0; i < options.length(); i++) { String optionName = options.get(i); RmdTemplateFormatOption option = template.getOption(optionName); if (!option.isTransferable()) continue; // option is transferable, is it present in another front matter entry? JsArrayString formats = frontMatter.getFormatList(); for (int j = 0; j < formats.length(); j++) { RmdFrontMatterOutputOptions outOptions = frontMatter.getOutputOption(formats.get(j)); if (outOptions == null) continue; String val = outOptions.getOptionValue(optionName); if (val != null) result.setOptionValue(option, val); } } return result; }
From source file:org.rstudio.studio.client.workbench.views.source.editors.text.ui.ChooseEncodingDialog.java
License:Open Source License
private void setEncodings(JsArrayString encodings, String encoding) { listBox_.clear();//from w w w .jav a 2s .c o m for (int i = 0; i < encodings.length(); i++) { listBox_.addItem(encodings.get(i)); } int sysIndex = findSystemEncodingIndex(); if (!StringUtil.isNullOrEmpty(systemEncoding_)) { // Remove the system encoding (if it is present) so we can move it // to the top of the list. If it's already present, use the same // label (un-normalized encoding name) so it's consistent with // related encodings that are also present in the list. String sysEncName = sysIndex < 0 ? systemEncoding_ : listBox_.getValue(sysIndex); if (sysIndex >= 0) listBox_.removeItem(sysIndex); listBox_.insertItem(sysEncName + " (System default)", systemEncoding_, 0); } if (includePromptForEncoding_) { listBox_.insertItem(ASK_LABEL, "", 0); } if (isSystemEncoding(encoding)) setCurrentValue(listBox_.getValue(includePromptForEncoding_ ? 1 : 0)); else setCurrentValue(encoding); }
From source file:org.rstudio.studio.client.workbench.views.source.Source.java
License:Open Source License
private void openProjectDocs(final Session session) { JsArrayString openDocs = session.getSessionInfo().getProjectOpenDocs(); if (openDocs.length() > 0) { // set new tab pending for the duration of the continuation newTabPending_++;// w w w . j a v a2 s . com // create a continuation for opening the source docs SerializedCommandQueue openCommands = new SerializedCommandQueue(); for (int i = 0; i < openDocs.length(); i++) { String doc = openDocs.get(i); final FileSystemItem fsi = FileSystemItem.createFile(doc); openCommands.addCommand(new SerializedCommand() { @Override public void onExecute(final Command continuation) { openFile(fsi, fileTypeRegistry_.getTextTypeForFile(fsi), new CommandWithArg<EditingTarget>() { @Override public void execute(EditingTarget arg) { continuation.execute(); } }); } }); } // decrement newTabPending and select first tab when done openCommands.addCommand(new SerializedCommand() { @Override public void onExecute(Command continuation) { newTabPending_--; onFirstTab(); continuation.execute(); } }); // execute the continuation openCommands.run(); } }
From source file:org.rstudio.studio.client.workbench.views.source.SourceWindowManager.java
License:Open Source License
@Inject public SourceWindowManager(Provider<SatelliteManager> pSatelliteManager, Provider<Satellite> pSatellite, Provider<WorkbenchContext> pWorkbenchContext, SourceServerOperations server, EventBus events, FileTypeRegistry registry, GlobalDisplay display, SourceShim sourceShim, Session session, UIPrefs uiPrefs) {/*from ww w .j a va 2 s . co m*/ events_ = events; server_ = server; pSatelliteManager_ = pSatelliteManager; pSatellite_ = pSatellite; pWorkbenchContext_ = pWorkbenchContext; display_ = display; sourceShim_ = sourceShim; uiPrefs_ = uiPrefs; events_.addHandler(DocWindowChangedEvent.TYPE, this); if (isMainSourceWindow()) { // most event handlers only make sense on the main window events_.addHandler(EditorCommandDispatchEvent.TYPE, this); events_.addHandler(PopoutDocEvent.TYPE, this); events_.addHandler(DocTabDragStartedEvent.TYPE, this); events_.addHandler(ShinyApplicationStatusEvent.TYPE, this); events_.addHandler(AllSatellitesClosingEvent.TYPE, this); events_.addHandler(SourceDocAddedEvent.TYPE, this); events_.addHandler(SourceFileSavedEvent.TYPE, this); events_.addHandler(CodeBrowserCreatedEvent.TYPE, this); events_.addHandler(SatelliteClosedEvent.TYPE, this); events_.addHandler(SatelliteFocusedEvent.TYPE, this); events_.addHandler(DocTabClosedEvent.TYPE, this); events_.addHandler(CollabEditStartedEvent.TYPE, this); events_.addHandler(CollabEditEndedEvent.TYPE, this); events_.addHandler(DocFocusedEvent.TYPE, this); events_.addHandler(RestartStatusEvent.TYPE, this); JsArray<SourceDocument> docs = session.getSessionInfo().getSourceDocuments(); sourceDocs_ = docs; exportFromMain(); new JSObjectStateValue("source-window", "sourceWindowGeometry", ClientState.PROJECT_PERSISTENT, session.getSessionInfo().getClientState(), false) { @Override protected void onInit(JsObject value) { // save the window geometries if (value != null) windowGeometry_ = value; // compute the max ordinal value in the geometry set JsArrayString windowIds = windowGeometry_.keys(); for (int i = 0; i < windowIds.length(); i++) { SatelliteWindowGeometry geometry = windowGeometry_.getObject(windowIds.get(i)).cast(); maxOrdinal_ = Math.max(geometry.getOrdinal(), maxOrdinal_); } } @Override protected JsObject getValue() { return windowGeometry_; } @Override protected boolean hasChanged() { return updateWindowGeometry(); } }; // keep track of whether the main window has focus (helps us infer the // user's perception of the 'active' doc) WindowEx.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent arg0) { mainWindowFocused_ = true; } }); WindowEx.addBlurHandler(new BlurHandler() { @Override public void onBlur(BlurEvent arg0) { mainWindowFocused_ = false; } }); // open this session's source windows for (int i = 0; i < docs.length(); i++) { String windowId = docs.get(i).getSourceWindowId(); if (!StringUtil.isNullOrEmpty(windowId) && !isSourceWindowOpen(windowId)) { openSourceWindow(windowId, null, null, null); } } } // signal that this window has focus if (WindowEx.get().getDocument().hasFocus()) MainWindowObject.lastFocusedWindow().set(getSourceWindowId()); WindowEx.addFocusHandler(new FocusHandler() { @Override public void onFocus(FocusEvent event) { MainWindowObject.lastFocusedWindow().set(getSourceWindowId()); } }); }
From source file:org.rstudio.studio.client.workbench.views.source.SourceWindowManager.java
License:Open Source License
private boolean hasSourceAndConsolePaired(JsArrayString panes) { // default config if (panes == null) return true; // if there aren't 4 panes this is a configuration we // don't recognize if (panes.length() != 4) return false; // check for paired config return hasSourceAndConsolePaired(panes.get(0), panes.get(1)) || hasSourceAndConsolePaired(panes.get(2), panes.get(3)); }
From source file:org.rstudio.studio.client.workbench.views.vcs.BranchToolbarButton.java
License:Open Source License
@Override public void onVcsRefresh(VcsRefreshEvent event) { ToolbarPopupMenu rootMenu = getMenu(); rootMenu.clearItems();/* ww w . j a v a 2 s.c o m*/ JsArrayString branches = pVcsState_.get().getBranchInfo().getBranches(); onBeforePopulateMenu(rootMenu); for (int i = 0; i < branches.length(); i++) { String branch = branches.get(i); final String branchLabel = branch.replaceFirst("^remotes/", ""); final String branchValue = branch.replaceFirst(" ->.*", ""); rootMenu.addItem(new MenuItem(branchLabel, new SwitchBranchCommand(branchLabel, branchValue))); } }
From source file:org.sakaiproject.gradebook.gwt.client.gxt.model.EntityModel.java
License:Educational Community License
public Collection<String> getPropertyNames() { if (null == overlay) return super.getPropertyNames(); Set<String> set = new FastSet(); JsArrayString array = overlay.getKeys(); if (array != null) { for (int i = 0; i < array.length(); i++) { set.add(array.get(i)); }/*from w w w. j a v a 2 s . co m*/ } return set; }
From source file:org.sigmah.offline.indexeddb.Database.java
License:Open Source License
/** * Retrieves the name of every object store in this database. * // w w w. ja v a2 s . c o m * @return A set of the object stores names. */ public Set<String> getObjectStoreNames() { final JsArrayString names = nativeDatabase.getObjectStoreNames(); final HashSet<String> result = new HashSet<String>(); for (int index = 0; index < names.length(); index++) { result.add(names.get(index)); } return result; }