Package com.google.gwt.core.client

Examples of com.google.gwt.core.client.Duration


        Profiler.enter("LayoutManager phase init");

        FastStringMap<Integer> layoutCounts = FastStringMap.create();

        int passes = 0;
        Duration totalDuration = new Duration();

        ConnectorMap connectorMap = ConnectorMap.get(connection);

        JsArrayString dump = needsHorizontalLayout.dump();
        int dumpLength = dump.length();
        for (int i = 0; i < dumpLength; i++) {
            String layoutId = dump.get(i);
            currentDependencyTree.setNeedsHorizontalLayout(layoutId, true);
        }

        dump = needsVerticalLayout.dump();
        dumpLength = dump.length();
        for (int i = 0; i < dumpLength; i++) {
            String layoutId = dump.get(i);
            currentDependencyTree.setNeedsVerticalLayout(layoutId, true);
        }
        needsHorizontalLayout = FastStringSet.create();
        needsVerticalLayout = FastStringSet.create();

        dump = needsMeasure.dump();
        dumpLength = dump.length();
        for (int i = 0; i < dumpLength; i++) {
            String layoutId = dump.get(i);
            currentDependencyTree.setNeedsMeasure(layoutId, true);
        }
        needsMeasure = FastStringSet.create();

        measureNonConnectors();

        Profiler.leave("LayoutManager phase init");

        while (true) {
            Profiler.enter("Layout pass");
            passes++;

            performBrowserLayoutHacks();

            Profiler.enter("Layout measure connectors");
            int measuredConnectorCount = measureConnectors(
                    currentDependencyTree, everythingNeedsMeasure);
            Profiler.leave("Layout measure connectors");

            everythingNeedsMeasure = false;
            if (measuredConnectorCount == 0) {
                VConsole.log("No more changes in pass " + passes);
                Profiler.leave("Layout pass");
                break;
            }

            int firedListeners = 0;
            if (!listenersToFire.isEmpty()) {
                firedListeners = listenersToFire.size();
                Profiler.enter("Layout fire resize events");
                for (Element element : listenersToFire) {
                    Collection<ElementResizeListener> listeners = elementResizeListeners
                            .get(element);
                    if (listeners != null) {
                        Profiler.enter("Layout fire resize events - listeners not null");
                        Profiler.enter("ElementResizeListener.onElementResize copy list");
                        ElementResizeListener[] array = listeners
                                .toArray(new ElementResizeListener[listeners
                                        .size()]);
                        Profiler.leave("ElementResizeListener.onElementResize copy list");
                        ElementResizeEvent event = new ElementResizeEvent(this,
                                element);
                        for (ElementResizeListener listener : array) {
                            try {
                                String key = null;
                                if (Profiler.isEnabled()) {
                                    Profiler.enter("ElementResizeListener.onElementResize construct profiler key");
                                    key = "ElementResizeListener.onElementResize for "
                                            + Util.getSimpleName(listener);
                                    Profiler.leave("ElementResizeListener.onElementResize construct profiler key");
                                    Profiler.enter(key);
                                }

                                listener.onElementResize(event);
                                if (Profiler.isEnabled()) {
                                    Profiler.leave(key);
                                }
                            } catch (RuntimeException e) {
                                VConsole.error(e);
                            }
                        }
                        Profiler.leave("Layout fire resize events - listeners not null");
                    }
                }
                listenersToFire.clear();

                Profiler.leave("Layout fire resize events");
            }

            Profiler.enter("LayoutManager handle ManagedLayout");

            FastStringSet updatedSet = FastStringSet.create();

            int layoutCount = 0;
            while (currentDependencyTree.hasHorizontalConnectorToLayout()
                    || currentDependencyTree.hasVerticaConnectorToLayout()) {

                JsArrayString layoutTargets = currentDependencyTree
                        .getHorizontalLayoutTargetsJsArray();
                int length = layoutTargets.length();
                for (int i = 0; i < length; i++) {
                    ManagedLayout layout = (ManagedLayout) connectorMap
                            .getConnector(layoutTargets.get(i));
                    if (layout instanceof DirectionalManagedLayout) {
                        currentDependencyTree
                                .markAsHorizontallyLayouted(layout);
                        DirectionalManagedLayout cl = (DirectionalManagedLayout) layout;
                        try {
                            String key = null;
                            if (Profiler.isEnabled()) {
                                key = "layoutHorizontally() for "
                                        + Util.getSimpleName(cl);
                                Profiler.enter(key);
                            }

                            cl.layoutHorizontally();
                            layoutCount++;

                            if (Profiler.isEnabled()) {
                                Profiler.leave(key);
                            }
                        } catch (RuntimeException e) {
                            VConsole.error(e);
                        }
                        countLayout(layoutCounts, cl);
                    } else {
                        currentDependencyTree
                                .markAsHorizontallyLayouted(layout);
                        currentDependencyTree.markAsVerticallyLayouted(layout);
                        SimpleManagedLayout rr = (SimpleManagedLayout) layout;
                        try {
                            String key = null;
                            if (Profiler.isEnabled()) {
                                key = "layout() for " + Util.getSimpleName(rr);
                                Profiler.enter(key);
                            }

                            rr.layout();
                            layoutCount++;

                            if (Profiler.isEnabled()) {
                                Profiler.leave(key);
                            }
                        } catch (RuntimeException e) {
                            VConsole.error(e);
                        }
                        countLayout(layoutCounts, rr);
                    }
                    if (debugLogging) {
                        updatedSet.add(layout.getConnectorId());
                    }
                }

                layoutTargets = currentDependencyTree
                        .getVerticalLayoutTargetsJsArray();
                length = layoutTargets.length();
                for (int i = 0; i < length; i++) {
                    ManagedLayout layout = (ManagedLayout) connectorMap
                            .getConnector(layoutTargets.get(i));
                    if (layout instanceof DirectionalManagedLayout) {
                        currentDependencyTree.markAsVerticallyLayouted(layout);
                        DirectionalManagedLayout cl = (DirectionalManagedLayout) layout;
                        try {
                            String key = null;
                            if (Profiler.isEnabled()) {
                                key = "layoutHorizontally() for "
                                        + Util.getSimpleName(cl);
                                Profiler.enter(key);
                            }

                            cl.layoutVertically();
                            layoutCount++;

                            if (Profiler.isEnabled()) {
                                Profiler.leave(key);
                            }
                        } catch (RuntimeException e) {
                            VConsole.error(e);
                        }
                        countLayout(layoutCounts, cl);
                    } else {
                        currentDependencyTree
                                .markAsHorizontallyLayouted(layout);
                        currentDependencyTree.markAsVerticallyLayouted(layout);
                        SimpleManagedLayout rr = (SimpleManagedLayout) layout;
                        try {
                            String key = null;
                            if (Profiler.isEnabled()) {
                                key = "layout() for " + Util.getSimpleName(rr);
                                Profiler.enter(key);
                            }

                            rr.layout();
                            layoutCount++;

                            if (Profiler.isEnabled()) {
                                Profiler.leave(key);
                            }
                        } catch (RuntimeException e) {
                            VConsole.error(e);
                        }
                        countLayout(layoutCounts, rr);
                    }
                    if (debugLogging) {
                        updatedSet.add(layout.getConnectorId());
                    }
                }
            }

            Profiler.leave("LayoutManager handle ManagedLayout");

            if (debugLogging) {
                JsArrayString changedCids = updatedSet.dump();

                StringBuilder b = new StringBuilder("  ");
                b.append(changedCids.length());
                b.append(" requestLayout invocations ");
                if (changedCids.length() < 30) {
                    for (int i = 0; i < changedCids.length(); i++) {
                        if (i != 0) {
                            b.append(", ");
                        } else {
                            b.append(": ");
                        }
                        String connectorString = changedCids.get(i);
                        if (changedCids.length() < 10) {
                            ServerConnector connector = ConnectorMap.get(
                                    connection).getConnector(connectorString);
                            connectorString = Util
                                    .getConnectorString(connector);
                        }
                        b.append(connectorString);
                    }
                }
                VConsole.log(b.toString());
            }

            Profiler.leave("Layout pass");

            VConsole.log("Pass " + passes + " measured "
                    + measuredConnectorCount + " elements, fired "
                    + firedListeners + " listeners and did " + layoutCount
                    + " layouts.");

            if (passes > 100) {
                VConsole.log(LOOP_ABORT_MESSAGE);
                if (ApplicationConfiguration.isDebugMode()) {
                    VNotification.createNotification(
                            VNotification.DELAY_FOREVER,
                            connection.getUIConnector().getWidget())
                            .show(LOOP_ABORT_MESSAGE, VNotification.CENTERED,
                                    "error");
                }
                break;
            }
        }

        Profiler.enter("layout PostLayoutListener");
        JsArrayObject<ComponentConnector> componentConnectors = connectorMap
                .getComponentConnectorsAsJsArray();
        int size = componentConnectors.size();
        for (int i = 0; i < size; i++) {
            ComponentConnector connector = componentConnectors.get(i);
            if (connector instanceof PostLayoutListener) {
                String key = null;
                if (Profiler.isEnabled()) {
                    key = "layout PostLayoutListener for "
                            + Util.getSimpleName(connector);
                    Profiler.enter(key);
                }

                ((PostLayoutListener) connector).postLayout();

                if (Profiler.isEnabled()) {
                    Profiler.leave(key);
                }
            }
        }
        Profiler.leave("layout PostLayoutListener");

        cleanMeasuredSizes();

        VConsole.log("Total layout phase time: "
                + totalDuration.elapsedMillis() + "ms");
    }
View Full Code Here


     *
     * @return Milliseconds elapsed since the timer was last reset.
     */
    static int resetTimer() {
        int sinceLast = lastReset.elapsedMillis();
        lastReset = new Duration();
        return sinceLast;
    }
View Full Code Here

            if (BrowserInfo.get().isSafari()) {
                // Safari doesn't fire any events for link elements
                // See http://www.phpied.com/when-is-a-stylesheet-really-loaded/
                Scheduler.get().scheduleFixedPeriod(new RepeatingCommand() {
                    private final Duration duration = new Duration();

                    @Override
                    public boolean execute() {
                        int styleSheetLength = getStyleSheetLength(url);
                        if (getStyleSheetLength(url) > 0) {
                            fireLoad(event);
                            return false; // Stop repeating
                        } else if (styleSheetLength == 0) {
                            // "Loaded" empty sheet -> most likely 404 error
                            fireError(event);
                            return true;
                        } else if (duration.elapsedMillis() > 60 * 1000) {
                            fireError(event);
                            return false;
                        } else {
                            return true; // Continue repeating
                        }
View Full Code Here

    /**
     * This will cause re-layouting of all components. Mainly used for
     * development. Published to JavaScript.
     */
    public void forceLayout() {
        Duration duration = new Duration();

        layoutManager.forceLayout();

        VConsole.log("forceLayout in " + duration.elapsedMillis() + " ms");
    }
View Full Code Here

  @Override
  public void moveTo(double location) {
    startLocation = getViewport().getStart();
    endLocation = location;
    counter = new Duration();
    execute();
    scheduler.scheduleDelayed(this, 0);
  }
View Full Code Here

  /**
   * {@inheritDoc}
   */
  public void onJavaScriptEvent(String name, Event rawEvent) {
    double processTiming = 0;
    Duration instrumentedDuration = null;
    // These events should never be stopped by the editor since other handlers
    // rely on getting to handle them.
    // TODO(danilatos): clean this mess up.
    boolean hackEditorNeverConsumes = name.equals("contextmenu") || name.equals("click")
        || name.equals("mousedown");

    try {
      EditorEvent event = SignalEventImpl.create(EditorEventImpl.FACTORY,
          rawEvent, !hackEditorNeverConsumes);

      try {
        if (UserAgent.isMac() &&
            rawEvent.getCtrlKey() && rawEvent.getAltKey()
            && rawEvent.getTypeInt() == Event.ONKEYPRESS) {
          // In mac safari, Ctrl+Alt+something often inserts weird invisible
          // characters in the dom!!! Always cancel the event, no matter what
          // (We can still handle it programmatically if we wish)

          // Cancel for FF as well just in case - but if this causes an issue
          // it should be OK to enable for FF. We get keypress events, but
          // no dom munge.

          // Don't cancel it on Windows, because that prevents AltGr combos
          // from working in european languages

          EditorStaticDeps.logger.trace().log("Cancelling dangerous: " + rawEvent.getType());

          rawEvent.preventDefault();
        }
      } catch (JavaScriptException e) {
        // If this fails, swallow it. Seems to cause issues with dom mutation
        // events when setting contentEditable with JUnit tests.
      }

      if (event == null) {
        if (!hackEditorNeverConsumes) {
          try {
            rawEvent.stopPropagation();
          } catch (JavaScriptException e) {
            // If this fails, swallow it. Seems to cause issues with dom mutation
            // events when setting contentEditable with JUnit tests.
          }
        }
        return;
      }

      boolean cancel = false;

      if (!hackEditorNeverConsumes) {
        if (editorRelevantEvent(event)) {
          try {
            event.stopPropagation();
          } catch (JavaScriptException e) {
            // If this fails, swallow it. Seems to cause issues with dom mutation
            // events when setting contentEditable with JUnit tests.
          }
        } else {
          return;
        }
      }

      boolean isMutationEvent = event.isMutationEvent();

      if (!isMutationEvent || !EditorStaticDeps.shouldIgnoreMutations()) {
        EditorStaticDeps.startIgnoreMutations();
        try {
          if (debugDisabled) {
            cancel = false;
          } else if (!canHandleBrowserEvents()) {
            // If we're too busy for it to be safe to do anything at all,
            // we cancel the event altogether
            EditorStaticDeps.logger.trace().log("Too busy to handle: ", event);
            cancel = true;
          } else {
            // Cache the selection across multiple calls to Selection.get(), for the
            // duration of this event handler. We turn caching off again in the finally
            // block below.
            NativeSelectionUtil.cacheOn();

            // Normal event handling
            responsibility.startDirectSequence();
            try {
              if (settings.getInstrumentor().shouldInstrument(event)) {
                Duration timer = new Duration();
                cancel = eventHandler.handleEvent(event);
                processTiming = timer.elapsedMillis();
                instrumentedDuration = new Duration();
              } else {
                cancel = eventHandler.handleEvent(event);
              }
            } finally {
              responsibility.endDirectSequence();
View Full Code Here

    private void doDeleteBundleVersion() {
        String deleteSubmittedMessage = MSG.view_bundle_version_deleteSubmitted(version.getVersion(), version
            .getBundle().getName());
        getMessageCenter().notify(new Message(deleteSubmittedMessage, Message.Severity.Info));
        final Duration duration = new Duration();
        bundleManager.deleteBundleVersion(version.getId(), false, new AsyncCallback<Void>() {
            @Override
            public void onFailure(final Throwable caught) {
                Timer timer = new Timer() {
                    @Override
                    public void run() {
                        String message = MSG.view_bundle_version_deleteFailure(version.getVersion());
                        getErrorHandler().handleError(message, caught);
                    }
                };
                // Delay the showing of the result to give the user some time to see the deleteSubmitted notif
                timer.schedule(Math.max(0, 3 * 1000 - duration.elapsedMillis()));
            }

            @Override
            public void onSuccess(Void result) {
                Timer timer = new Timer() {
                    @Override
                    public void run() {
                        String message = MSG.view_bundle_version_deleteSuccessful(version.getVersion());
                        getMessageCenter().notify(new Message(message, Message.Severity.Info));
                        // Bundle version is deleted, go back to main bundle view
                        goToView(LinkManager.getBundleVersionLink(version.getBundle().getId(), 0), true);
                    }
                };
                // Delay the showing of the result to give the user some time to see the deleteSubmitted notif
                timer.schedule(Math.max(0, 3 * 1000 - duration.elapsedMillis()));
            }
        });
    }
View Full Code Here

    private void doDeleteBundleDestination() {
        String deleteSubmittedMessage = MSG.view_bundle_dest_deleteSubmitted(destination.getName(), destination
            .getBundle().getName());
        getMessageCenter().notify(new Message(deleteSubmittedMessage, Message.Severity.Info));
        final Duration duration = new Duration();
        BundleGWTServiceAsync bundleService = GWTServiceLookup.getBundleService();
        bundleService.deleteBundleDestination(destination.getId(), new AsyncCallback<Void>() {
            @Override
            public void onFailure(final Throwable caught) {
                Timer timer = new Timer() {
                    @Override
                    public void run() {
                        String message = MSG.view_bundle_dest_deleteFailure(destination.getName());
                        getErrorHandler().handleError(message, caught);
                    }
                };
                // Delay the showing of the result to give the user some time to see the deleteSubmitted notif
                timer.schedule(Math.max(0, 3 * 1000 - duration.elapsedMillis()));
            }

            @Override
            public void onSuccess(Void result) {
                Timer timer = new Timer() {
                    @Override
                    public void run() {
                        String message = MSG.view_bundle_dest_deleteSuccessful(destination.getName());
                        getMessageCenter().notify(new Message(message, Message.Severity.Info));
                        // Bundle destination is deleted, go back to bundle destinations root view
                        goToView(LinkManager.getBundleDestinationLink(bundle.getId(), 0), true);
                    }
                };
                // Delay the showing of the result to give the user some time to see the deleteSubmitted notif
                timer.schedule(Math.max(0, 3 * 1000 - duration.elapsedMillis()));
            }
        });
    }
View Full Code Here

    }

    private void doDeleteBundle() {
        String deleteSubmittedMessage = MSG.view_bundle_deleteSubmitted(bundle.getName());
        getMessageCenter().notify(new Message(deleteSubmittedMessage, Message.Severity.Info));
        final Duration duration = new Duration();
        bundleManager.deleteBundle(bundleBeingViewed, new AsyncCallback<Void>() {
            @Override
            public void onFailure(final Throwable caught) {
                Timer timer = new Timer() {
                    @Override
                    public void run() {
                        String message = MSG.view_bundle_list_deleteFailure(bundle.getName());
                        getErrorHandler().handleError(message, caught);
                    }
                };
                // Delay the showing of the result to give the user some time to see the deleteSubmitted notif
                timer.schedule(Math.max(0, 3 * 1000 - duration.elapsedMillis()));
            }

            @Override
            public void onSuccess(Void result) {
                Timer timer = new Timer() {
                    @Override
                    public void run() {
                        String conciseMessage = MSG.view_bundle_list_deleteSuccessful(bundle.getName());
                        getMessageCenter().notify(new Message(conciseMessage, Message.Severity.Info));
                        goToView("Bundles", true); // Bundle is deleted, go back to all bundles view
                    }
                };
                // Delay the showing of the result to give the user some time to see the deleteSubmitted notif
                timer.schedule(Math.max(0, 3 * 1000 - duration.elapsedMillis()));
            }
        });
    }
View Full Code Here

        ImportResourceRequest request = new ImportResourceRequest(getChildType().getId(), getParentResource().getId(),
            getNewResourceConfiguration());

        ResourceGWTServiceAsync resourceService = GWTServiceLookup.getResourceService(300000);
        final Duration duration = new Duration();
        resourceService.manuallyAddResource(request, new AsyncCallback<ImportResourceResponse>() {
            @Override
            public void onFailure(final Throwable caught) {
                Timer timer = new Timer() {
                    @Override
                    public void run() {
                        if (caught instanceof CannotConnectToAgentException) {
                            getMessageCenter().notify(
                                new Message(MSG.widget_resourceFactoryWizard_importFailure2(), Severity.Warning));
                        } else {
                            getErrorHandler().handleError(MSG.widget_resourceFactoryWizard_importFailure(), caught);
                        }
                    }
                };
                // Delay the showing of the result to give the user some time to see the importSubmitted notif
                timer.schedule(Math.max(0, 3 * 1000 - duration.elapsedMillis()));
            }

            @Override
            public void onSuccess(final ImportResourceResponse result) {
                Timer timer = new Timer() {
                    @Override
                    public void run() {
                        boolean resourceAlreadyExisted = result.isResourceAlreadyExisted();
                        Resource resource = result.getResource();
                        String resourceTypeName = resource.getResourceType().getName();
                        String resourceKey = resource.getResourceKey();

                        String conciseMessage;
                        String detailedMessage;
                        Severity severity;
                        if (!resourceAlreadyExisted) {
                            conciseMessage = MSG.widget_resourceFactoryWizard_importSuccess(resourceTypeName,
                                resourceKey);
                            detailedMessage = null;
                            severity = Severity.Info;
                        } else {

                            severity = Severity.Warning;
                            conciseMessage = MSG.widget_resourceFactoryWizard_importFailureResource(resourceTypeName,
                                resourceKey);

                            switch (resource.getInventoryStatus()) {
                            case NEW:
                                detailedMessage = MSG
                                    .widget_resourceFactoryWizard_importFailureResourceInDiscoveryQueue();
                                break;
                            case IGNORED:
                                detailedMessage = MSG.widget_resourceFactoryWizard_importFailureResourceIgnored();
                                break;
                            case COMMITTED:
                                detailedMessage = MSG
                                    .widget_resourceFactoryWizard_importFailureResourceAlreadyInInventory();
                                break;
                            default:
                                detailedMessage = MSG
                                    .widget_resourceFactoryWizard_importFailureResourceWaitingForPurge();
                            }
                        }

                        getMessageCenter().notify(new Message(conciseMessage, detailedMessage, severity));
                    }
                };
                // Delay the showing of the result to give the user some time to see the importSubmitted notif
                timer.schedule(Math.max(0, 3 * 1000 - duration.elapsedMillis()));
            }
        });
    }
View Full Code Here

TOP

Related Classes of com.google.gwt.core.client.Duration

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.