Example usage for com.google.gwt.event.dom.client FocusHandler FocusHandler

List of usage examples for com.google.gwt.event.dom.client FocusHandler FocusHandler

Introduction

In this page you can find the example usage for com.google.gwt.event.dom.client FocusHandler FocusHandler.

Prototype

FocusHandler

Source Link

Usage

From source file:org.rstudio.core.client.widget.NumericTextBox.java

License:Open Source License

private void init() {
    addFocusHandler(new FocusHandler() {
        @Override// w w w.  j  a v a  2 s .  co  m
        public void onFocus(FocusEvent event) {
            selectAll();
        }
    });

    addKeyDownHandler(new KeyDownHandler() {
        @Override
        public void onKeyDown(KeyDownEvent event) {
            int modifiers = KeyboardShortcut.getModifierValue(event.getNativeEvent());
            if (modifiers == KeyboardShortcut.NONE && (event.isUpArrow() || event.isDownArrow())) {
                event.preventDefault();
                event.stopPropagation();

                try {
                    int value = Integer.parseInt(getText());
                    value += event.isUpArrow() ? 1 : -1;
                    setValue(value + "", true);
                    selectAll();
                } catch (NumberFormatException nfe) {
                    // just ignore
                }
            }
        }
    });

    addKeyPressHandler(new KeyPressHandler() {
        @Override
        public void onKeyPress(KeyPressEvent event) {
            char charCode = event.getCharCode();
            if (charCode >= '0' && charCode <= '9')
                return;
            if (Character.isLetterOrDigit(charCode))
                event.preventDefault();
        }
    });
}

From source file:org.rstudio.core.client.widget.TextBoxWithCue.java

License:Open Source License

private void hookEvents() {
    unhookEvents();/*  w  w w.  j  a  v  a2 s. co  m*/

    FocusHandler focusHandler = new FocusHandler() {
        public void onFocus(FocusEvent event) {
            if (DomUtils.hasFocus(getElement())) {
                if (isCueMode()) {
                    setText("");
                    removeStyleName(CUE_STYLE);
                }
            }
        }
    };

    BlurHandler blurHandler = new BlurHandler() {
        public void onBlur(BlurEvent event) {
            if (getText().length() == 0) {
                addStyleName(CUE_STYLE);
                setText(cueText_);
            }
        }
    };

    registrations_ = new HandlerRegistration[] { addFocusHandler(focusHandler), addBlurHandler(blurHandler),
            WindowEx.addFocusHandler(focusHandler), WindowEx.addBlurHandler(blurHandler) };

    blurHandler.onBlur(null);
}

From source file:org.rstudio.studio.client.workbench.codesearch.CodeSearch.java

License:Open Source License

@Inject
public CodeSearch(Display display, final FileTypeRegistry fileTypeRegistry, final EventBus eventBus) {
    display_ = display;/*from   ww w  .j ava 2 s .  co  m*/

    final SearchDisplay searchDisplay = display_.getSearchDisplay();
    searchDisplay.setAutoSelectEnabled(true);

    searchDisplay.addSelectionHandler(new SelectionHandler<Suggestion>() {

        @Override
        public void onSelection(SelectionEvent<Suggestion> event) {
            CodeNavigationTarget target = display_.getSearchOracle()
                    .navigationTarget(searchDisplay.getLastValue(), event.getSelectedItem());

            // create full file path and position
            String srcFile = target.getFile();
            final FileSystemItem srcItem = FileSystemItem.createFile(srcFile);
            final FilePosition pos = target.getPosition();

            // fire editing event (delayed so the Enter keystroke 
            // doesn't get routed into the source editor)
            Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                @Override
                public void execute() {
                    display_.getSearchDisplay().clear();
                    display_.getSearchOracle().clear();

                    if (observer_ != null)
                        observer_.onCompleted();

                    fileTypeRegistry.editFile(srcItem, pos);
                }
            });
        }
    });

    searchDisplay.addCloseHandler(new CloseHandler<SearchDisplay>() {
        @Override
        public void onClose(CloseEvent<SearchDisplay> event) {
            display_.getSearchDisplay().clear();

            if (observer_ != null)
                observer_.onCancel();
        }
    });

    // various conditions invalidate the search oracle's cache

    searchDisplay.addBlurHandler(new BlurHandler() {
        @Override
        public void onBlur(BlurEvent event) {
            display_.getSearchOracle().clear();
        }
    });

    searchDisplay.addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            display_.getSearchOracle().clear();
        }
    });

    eventBusHandlers_.add(eventBus.addHandler(FileChangeEvent.TYPE, new FileChangeHandler() {
        @Override
        public void onFileChange(FileChangeEvent event) {
            // if this was an R file then invalide the cache
            CodeSearchOracle oracle = display_.getSearchOracle();
            if (oracle.hasCachedResults()) {
                FileSystemItem fsi = event.getFileChange().getFile();
                if (fsi.getExtension().toLowerCase().equals(".r"))
                    oracle.clear();
            }
        }
    }));

    searchDisplay.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            boolean hasSearch = event.getValue().length() != 0;
            if (!hasSearch) {
                display_.getSearchOracle().invalidateSearches();
                display_.getSuggestionDisplay().hideSuggestions();
            }
        }
    });

    searchDisplay.addKeyDownHandler(new KeyDownHandler() {

        @Override
        public void onKeyDown(KeyDownEvent event) {
            // eat key-up if the suggestions are showing (since the 
            // suggestions menu is taking these and if we take it
            // the cursor will go to the beginning of the selection)
            if (display_.getSuggestionDisplay().isSuggestionListShowing()
                    && (event.getNativeKeyCode() == KeyCodes.KEY_UP)) {
                event.preventDefault();
                event.stopPropagation();
            }
        }

    });
}

From source file:org.rstudio.studio.client.workbench.views.history.view.HistoryPane.java

License:Open Source License

@Override
protected Toolbar createMainToolbar() {
    searchWidget_ = new SearchWidget(new SuggestOracle() {
        @Override/*  www  .  j av a2s.  c o  m*/
        public void requestSuggestions(Request request, Callback callback) {
            callback.onSuggestionsReady(request, new Response(new ArrayList<Suggestion>()));
        }
    });
    searchWidget_.addKeyDownHandler(new KeyDownHandler() {
        public void onKeyDown(KeyDownEvent event) {
            getActiveHistory().getKeyTarget().fireEvent(event);
        }
    });
    searchWidget_.addSelectionCommitHandler(new SelectionCommitHandler<String>() {
        public void onSelectionCommit(SelectionCommitEvent<String> event) {
            if (mode_ == Mode.SearchResults)
                fireEvent(event);
        }
    });
    searchWidget_.addFocusHandler(new FocusHandler() {
        public void onFocus(FocusEvent event) {
            commandList_.getFocusTarget().addClassName(styles_.fakeFocus());
            searchResults_.getFocusTarget().addClassName(styles_.fakeFocus());
            contextResults_.getFocusTarget().addClassName(styles_.fakeFocus());
        }
    });
    searchWidget_.addBlurHandler(new BlurHandler() {
        public void onBlur(BlurEvent event) {
            commandList_.getFocusTarget().removeClassName(styles_.fakeFocus());
            searchResults_.getFocusTarget().removeClassName(styles_.fakeFocus());
            contextResults_.getFocusTarget().removeClassName(styles_.fakeFocus());
        }
    });

    Toolbar toolbar = new Toolbar();
    toolbar.addLeftWidget(commands_.loadHistory().createToolbarButton());
    toolbar.addLeftWidget(commands_.saveHistory().createToolbarButton());
    toolbar.addLeftSeparator();
    toolbar.addLeftWidget(commands_.historySendToConsole().createToolbarButton());
    toolbar.addLeftSeparator();
    toolbar.addLeftWidget(commands_.historySendToSource().createToolbarButton());
    toolbar.addLeftSeparator();
    toolbar.addLeftWidget(commands_.historyRemoveEntries().createToolbarButton());
    toolbar.addLeftWidget(commands_.clearHistory().createToolbarButton());

    toolbar.addRightWidget(searchWidget_);

    return toolbar;
}

From source file:org.rstudio.studio.client.workbench.views.output.lint.DiagnosticsBackgroundPopup.java

License:Open Source License

public DiagnosticsBackgroundPopup(DocDisplay docDisplay) {
    docDisplay_ = docDisplay;/*  w w w  .j  a v  a  2  s. c  o  m*/
    editor_ = (AceEditor) docDisplay_;

    docDisplay_.addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            if (editor_ != null && !isRunning_)
                start();
        }
    });

    docDisplay_.addBlurHandler(new BlurHandler() {
        @Override
        public void onBlur(BlurEvent event) {
            hidePopup();
            stopMonitoring();
            if (handler_ != null) {
                handler_.removeHandler();
                handler_ = null;
            }
        }
    });

    stopRequested_ = false;
    popup_ = null;
    start();
}

From source file:org.rstudio.studio.client.workbench.views.source.editors.text.r.SignatureToolTipManager.java

License:Open Source License

public SignatureToolTipManager(DocDisplay docDisplay) {
    RStudioGinjector.INSTANCE.injectMembers(this);
    toolTip_ = new RCompletionToolTip(docDisplay);
    docDisplay_ = docDisplay;/*from   www.  java2s  .c  om*/
    handlers_ = new HandlerRegistrations();

    timer_ = new Timer() {
        @Override
        public void run() {
            // Bail if we don't ever show tooltips
            if (!uiPrefs_.showSignatureTooltips().getGlobalValue())
                return;

            // Bail if this is a cursor-activated timer and we
            // don't want idle tooltips
            if (coordinates_ == null && !uiPrefs_.showFunctionTooltipOnIdle().getGlobalValue())
                return;

            // Bail if the tooltip is already showing from a non-mouse event.
            if (!isMouseDrivenEvent() && toolTip_.isShowing())
                return;

            resolveActiveFunctionAndDisplayToolTip();
        }
    };

    monitor_ = new Timer() {
        @Override
        public void run() {
            if (ready_) {
                timer_.schedule(TIMER_DELAY_MS);
                ready_ = false;
            }
        }
    };

    handlers_.add(docDisplay_.addFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            beginMonitoring();
        }
    }));

    handlers_.add(docDisplay_.addBlurHandler(new BlurHandler() {
        @Override
        public void onBlur(BlurEvent event) {
            timer_.cancel();
            toolTip_.hide();
            endMonitoring();
        }
    }));

    handlers_.add(docDisplay_.addCursorChangedHandler(new CursorChangedHandler() {
        @Override
        public void onCursorChanged(final CursorChangedEvent event) {
            beginMonitoring();

            // Defer so that anchors can update
            Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
                @Override
                public void execute() {
                    // Check to see if the cursor has moved outside of the anchored region.
                    if (anchor_ != null && toolTip_.isShowing()) {
                        Position position = event.getPosition();
                        if (anchor_.getRange().contains(position)) {
                            // Update the tooltip position if the cursor changes rows.
                            if (position.getRow() > tooltipPosition_.getRow()) {
                                // Allow tooltip to nudge right (but not left)
                                int newColumn = Math.max(tooltipPosition_.getColumn(), position.getColumn());

                                setTooltipPosition(Position.create(position.getRow(), newColumn));
                            }
                        } else {
                            anchor_ = null;
                            toolTip_.hide();
                        }
                    }
                }
            });
        }
    }));

    handlers_.add(toolTip_.addAttachHandler(new AttachEvent.Handler() {
        @Override
        public void onAttachOrDetach(AttachEvent event) {
            if (!event.isAttached()) {
                coordinates_ = null;
                completionPosition_ = null;
                anchor_ = null;
            }
        }
    }));

    handlers_.add(events_.addHandler(ConsoleWriteInputEvent.TYPE, new ConsoleWriteInputHandler() {
        @Override
        public void onConsoleWriteInput(ConsoleWriteInputEvent event) {
            anchor_ = null;
            toolTip_.hide();
        }
    }));
}

From source file:org.rstudio.studio.client.workbench.views.source.editors.text.rmd.TextEditingTargetNotebook.java

License:Open Source License

public TextEditingTargetNotebook(final TextEditingTarget editingTarget, TextEditingTargetChunks chunks,
        TextEditingTarget.Display editingDisplay, DocDisplay docDisplay, DirtyState dirtyState,
        DocUpdateSentinel docUpdateSentinel, SourceDocument document,
        ArrayList<HandlerRegistration> releaseOnDismiss, DependencyManager dependencyManager) {
    docDisplay_ = docDisplay;//  w  ww.j  a v a  2 s.c o m
    docUpdateSentinel_ = docUpdateSentinel;
    dirtyState_ = dirtyState;
    releaseOnDismiss_ = releaseOnDismiss;
    notebookDoc_ = document.getNotebookDoc();
    initialChunkDefs_ = JsArrayUtil.deepCopy(notebookDoc_.getChunkDefs());
    outputs_ = new HashMap<String, ChunkOutputUi>();
    satelliteChunkRequestIds_ = new ArrayList<String>();
    setupCrc32_ = docUpdateSentinel_.getProperty(LAST_SETUP_CRC32);
    editingTarget_ = editingTarget;
    chunks_ = chunks;
    editingDisplay_ = editingDisplay;
    scopeHelper_ = new TextEditingTargetScopeHelper(docDisplay_);
    dependencyManager_ = dependencyManager;
    RStudioGinjector.INSTANCE.injectMembers(this);

    releaseOnDismiss.add(docDisplay_.addEditorFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent arg0) {
            if (queuedResize_ != null) {
                onResize(queuedResize_);
                queuedResize_ = null;
            }
        }
    }));

    // listen for future changes to the preference and sync accordingly
    releaseOnDismiss.add(docUpdateSentinel_.addPropertyValueChangeHandler(CHUNK_OUTPUT_TYPE,
            new ValueChangeHandler<String>() {
                @Override
                public void onValueChange(ValueChangeEvent<String> event) {
                    // propagate to YAML
                    String yaml = RmdEditorOptions.set(YamlFrontMatter.getFrontMatter(docDisplay_),
                            CHUNK_OUTPUT_TYPE, event.getValue());
                    YamlFrontMatter.applyFrontMatter(docDisplay_, yaml);

                    // change the output mode in the document
                    changeOutputMode(event.getValue());
                }
            }));

    // when the width of the outline changes, treat it as a resize
    ValueChangeHandler<String> outlineWidthHandler = new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            onResize(null);
        }
    };

    releaseOnDismiss.add(docUpdateSentinel_.addPropertyValueChangeHandler(TextEditingTarget.DOC_OUTLINE_SIZE,
            outlineWidthHandler));
    releaseOnDismiss.add(docUpdateSentinel_.addPropertyValueChangeHandler(TextEditingTarget.DOC_OUTLINE_VISIBLE,
            outlineWidthHandler));

    releaseOnDismiss.add(docDisplay_.addValueChangeHandler(new ValueChangeHandler<Void>() {
        @Override
        public void onValueChange(ValueChangeEvent<Void> arg0) {
            // check the setup chunk's CRC32 next time we run a chunk
            validateSetupChunk_ = true;

            // if the change happened in one of our scopes, clean up gutter
            // indicators for that scope (debounce this so it doesn't fire on
            // every keystroke)
            cleanErrorGutter_.schedule(250);
        }
    }));

    // rendering of chunk output line widgets (we wait until after the first
    // render to ensure that ace places the line widgets correctly)
    renderReg_ = docDisplay_.addRenderFinishedHandler(this);

    releaseOnDismiss_.add(editingTarget_.addInterruptChunkHandler(new InterruptChunkEvent.Handler() {
        @Override
        public void onInterruptChunk(InterruptChunkEvent event) {
            int row = event.getRow();
            String chunkId = getRowChunkId(row);

            // just interrupt R if we have no chunk id for some reason (shouldn't happen)
            if (StringUtil.isNullOrEmpty(chunkId)) {
                RStudioGinjector.INSTANCE.getApplicationInterrupt().interruptR(null);
                return;
            }

            // interrupt this chunk's execution
            server_.interruptChunk(editingTarget_.getId(), chunkId, new ServerRequestCallback<Void>() {
                @Override
                public void onResponseReceived(Void response) {
                    RStudioGinjector.INSTANCE.getApplicationInterrupt().interruptR(null);
                }

                @Override
                public void onError(ServerError error) {
                    Debug.logError(error);
                    RStudioGinjector.INSTANCE.getApplicationInterrupt().interruptR(null);
                }
            });
        }
    }));
}

From source file:org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTarget.java

License:Open Source License

public void initialize(SourceDocument document, FileSystemContext fileContext, FileType type,
        Provider<String> defaultNameProvider) {
    id_ = document.getId();//  w w  w.j  a  va 2 s. c o  m
    fileContext_ = fileContext;
    fileType_ = (TextFileType) type;

    extendedType_ = document.getExtendedType();
    extendedType_ = rmarkdownHelper_.detectExtendedType(document.getContents(), extendedType_, fileType_);

    view_ = new TextEditingTargetWidget(commands_, prefs_, fileTypeRegistry_, docDisplay_, fileType_,
            extendedType_, events_, session_);
    docUpdateSentinel_ = new DocUpdateSentinel(server_, docDisplay_, document,
            globalDisplay_.getProgressIndicator("Save File"), dirtyState_, events_);

    roxygenHelper_ = new RoxygenHelper(docDisplay_, view_);

    // ensure that Makefile and Makevars always use tabs
    name_.addValueChangeHandler(new ValueChangeHandler<String>() {
        @Override
        public void onValueChange(ValueChangeEvent<String> event) {
            if ("Makefile".equals(event.getValue()) || "Makevars".equals(event.getValue())
                    || "Makevars.win".equals(event.getValue())) {
                docDisplay_.setUseSoftTabs(false);
            }
        }
    });

    name_.setValue(getNameFromDocument(document, defaultNameProvider), true);
    docDisplay_.setCode(document.getContents(), false);

    final ArrayList<Fold> folds = Fold.decode(document.getFoldSpec());
    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
        @Override
        public void execute() {
            for (Fold fold : folds)
                docDisplay_.addFold(fold.getRange());
        }
    });

    registerPrefs(releaseOnDismiss_, prefs_, docDisplay_, document);

    // Initialize sourceOnSave, and keep it in sync
    view_.getSourceOnSave().setValue(document.sourceOnSave(), false);
    view_.getSourceOnSave().addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        public void onValueChange(ValueChangeEvent<Boolean> event) {
            docUpdateSentinel_.setSourceOnSave(event.getValue(),
                    globalDisplay_.getProgressIndicator("Error Saving Setting"));
        }
    });

    if (document.isDirty())
        dirtyState_.markDirty(false);
    else
        dirtyState_.markClean();
    docDisplay_.addValueChangeHandler(new ValueChangeHandler<Void>() {
        public void onValueChange(ValueChangeEvent<Void> event) {
            dirtyState_.markDirty(true);
        }
    });

    docDisplay_.addFocusHandler(new FocusHandler() {
        public void onFocus(FocusEvent event) {
            Scheduler.get().scheduleFixedDelay(new RepeatingCommand() {
                public boolean execute() {
                    if (view_.isAttached())
                        checkForExternalEdit();
                    return false;
                }
            }, 500);
        }
    });

    if (fileType_.isR()) {
        docDisplay_.addBreakpointSetHandler(new BreakpointSetEvent.Handler() {
            @Override
            public void onBreakpointSet(BreakpointSetEvent event) {
                if (event.isSet()) {
                    Breakpoint breakpoint = null;

                    // don't try to set breakpoints in unsaved code
                    if (isNewDoc()) {
                        view_.showWarningBar("Breakpoints cannot be set until " + "the file is saved.");
                        return;
                    }

                    // don't try to set breakpoints if the R version is too old
                    if (!session_.getSessionInfo().getHaveSrcrefAttribute()) {
                        view_.showWarningBar("Editor breakpoints require R 2.14 " + "or newer.");
                        return;
                    }

                    Position breakpointPosition = Position.create(event.getLineNumber() - 1, 1);

                    // if we're not in function scope, set a top-level breakpoint
                    ScopeFunction innerFunction = docDisplay_.getFunctionAtPosition(breakpointPosition, false);
                    if (innerFunction == null || !innerFunction.isFunction()
                            || StringUtil.isNullOrEmpty(innerFunction.getFunctionName())) {
                        breakpoint = breakpointManager_.setTopLevelBreakpoint(getPath(), event.getLineNumber());
                    }

                    // the scope tree will find nested functions, but in R these
                    // are addressable only as substeps of the parent function.
                    // keep walking up the scope tree until we've reached the top
                    // level function.
                    else {
                        while (innerFunction.getParentScope() != null
                                && innerFunction.getParentScope().isFunction()) {
                            innerFunction = (ScopeFunction) innerFunction.getParentScope();
                        }

                        String functionName = innerFunction.getFunctionName();

                        breakpoint = breakpointManager_.setBreakpoint(getPath(), functionName,
                                event.getLineNumber(), dirtyState().getValue() == false);
                    }

                    docDisplay_.addOrUpdateBreakpoint(breakpoint);
                } else {
                    breakpointManager_.removeBreakpoint(event.getBreakpointId());
                }
                updateBreakpointWarningBar();
            }
        });

        docDisplay_.addBreakpointMoveHandler(new BreakpointMoveEvent.Handler() {
            @Override
            public void onBreakpointMove(BreakpointMoveEvent event) {
                breakpointManager_.moveBreakpoint(event.getBreakpointId());
            }
        });
    }

    // validate required components (e.g. Tex, knitr, C++ etc.)
    checkCompilePdfDependencies();
    rmarkdownHelper_.verifyPrerequisites(view_, fileType_);

    syncFontSize(releaseOnDismiss_, events_, view_, fontSizeManager_);

    final String rTypeId = FileTypeRegistry.R.getTypeId();
    releaseOnDismiss_.add(prefs_.softWrapRFiles().addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        public void onValueChange(ValueChangeEvent<Boolean> evt) {
            if (fileType_.getTypeId().equals(rTypeId))
                view_.adaptToFileType(fileType_);
        }
    }));

    releaseOnDismiss_.add(events_.addHandler(FileChangeEvent.TYPE, new FileChangeHandler() {
        @Override
        public void onFileChange(FileChangeEvent event) {
            // screen out adds and events that aren't for our path
            FileChange fileChange = event.getFileChange();
            if (fileChange.getType() == FileChange.ADD)
                return;
            else if (!fileChange.getFile().getPath().equals(getPath()))
                return;

            // always check for changes if this is the active editor
            if (commandHandlerReg_ != null) {
                checkForExternalEdit();
            }

            // also check for changes on modifications if we are not dirty
            // note that we don't check for changes on removed files because
            // this will show a confirmation dialog
            else if (event.getFileChange().getType() == FileChange.MODIFIED
                    && dirtyState().getValue() == false) {
                checkForExternalEdit();
            }
        }
    }));

    spelling_ = new TextEditingTargetSpelling(docDisplay_, docUpdateSentinel_);

    // show/hide the debug toolbar when the dirty state changes. (note:
    // this doesn't yet handle the case where the user saves the document,
    // in which case we should still show some sort of warning.)
    dirtyState().addValueChangeHandler(new ValueChangeHandler<Boolean>() {
        public void onValueChange(ValueChangeEvent<Boolean> evt) {
            updateDebugWarningBar();
        }
    });

    // find all of the debug breakpoints set in this document and replay them
    // onto the edit surface
    ArrayList<Breakpoint> breakpoints = breakpointManager_.getBreakpointsInFile(getPath());
    for (Breakpoint breakpoint : breakpoints) {
        docDisplay_.addOrUpdateBreakpoint(breakpoint);
    }

    // for R Markdown docs, populate the popup menu with a list of available
    // formats
    if (extendedType_.equals("rmarkdown"))
        updateRmdFormatList();

    view_.addRmdFormatChangedHandler(new RmdOutputFormatChangedEvent.Handler() {
        @Override
        public void onRmdOutputFormatChanged(RmdOutputFormatChangedEvent event) {
            setRmdFormat(event.getFormat());
        }
    });

    initStatusBar();
}

From source file:org.rstudio.studio.client.workbench.views.source.editors.text.TextEditingTargetFindReplace.java

License:Open Source License

public TextEditingTargetFindReplace(Container container, boolean showReplace) {
    container_ = container;// w w w  .  jav a  2 s  .  c o m
    showReplace_ = showReplace;

    container_.getEditor().addEditorFocusHandler(new FocusHandler() {
        @Override
        public void onFocus(FocusEvent event) {
            if (findReplace_ != null)
                findReplace_.notifyEditorFocused();
        }
    });
}

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   w w  w.j  a  v a2 s. c  om*/
    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());
        }
    });
}