/** The <code>which</code> parameter is used to support the deprecated API. */
  private static StyleElement flush(JavaScriptObject which) {
    StyleElement toReturn = null;
    StyleElement maybeReturn;

    if (toInjectAtStart.length() != 0) {
      String css = toInjectAtStart.join("");
      maybeReturn = StyleInjectorImpl.IMPL.injectStyleSheetAtStart(css);
      if (toInjectAtStart == which) {
        toReturn = maybeReturn;
      }
      toInjectAtStart.setLength(0);
    }

    if (toInject.length() != 0) {
      String css = toInject.join("");
      maybeReturn = StyleInjectorImpl.IMPL.injectStyleSheet(css);
      if (toInject == which) {
        toReturn = maybeReturn;
      }
      toInject.setLength(0);
    }

    if (toInjectAtEnd.length() != 0) {
      String css = toInjectAtEnd.join("");
      maybeReturn = StyleInjectorImpl.IMPL.injectStyleSheetAtEnd(css);
      if (toInjectAtEnd == which) {
        toReturn = maybeReturn;
      }
      toInjectAtEnd.setLength(0);
    }

    needsInjection = false;
    return toReturn;
  }
Esempio n. 2
0
 private final String[] getScopes() {
   JsArrayString jsa = getScopesNative();
   String[] arr = new String[jsa.length()];
   for (int i = 0; i < jsa.length(); i++) {
     arr[i] = jsa.get(i);
   }
   return arr;
 }
 @Override
 @SuppressWarnings("unchecked")
 public String getAddressPath(int n) {
   initArray(this, keyAddressPath);
   JsArrayString array = getPropertyAsObject(this, keyAddressPath).cast();
   if (n < 0) throw new IllegalArgumentException("index " + n + " < 0");
   if (array.length() <= n)
     throw new IllegalArgumentException("index " + n + ">= array length " + array.length());
   return array.get(n);
 }
Esempio n. 4
0
  public void addProjectIcon(Project project) {
    FlowPanel projectPanel = new FlowPanel();

    JsArrayString appStrings = project.getApps();
    String description = "";

    for (int i = 0; i < appStrings.length(); i++) {
      if (i == appStrings.length() - 1) description += appStrings.get(i);
      else description += appStrings.get(i) + ", ";
    }

    final String projectName = project.getName();
    final String appNames = description;

    Image projectImg = new Image(res.projectdefaulticon2().getUrl());
    projectImg.setPixelSize(64, 64);

    projectPanel.add(projectImg);
    projectPanel.add(new Label(projectName));

    final FocusPanel testLabel = new FocusPanel();
    testLabel.add(projectPanel);
    testLabel.setStyleName(style.projectIcon());
    testLabel.addMouseOverHandler(
        new MouseOverHandler() {
          public void onMouseOver(MouseOverEvent event) {
            testLabel.setStyleName(style.projectIconActive());
            desc.show();
            desc.setPopupPosition(
                testLabel.getAbsoluteLeft() + testLabel.getOffsetWidth(),
                testLabel.getAbsoluteTop() - 5);
            desc.setTitle("Applications");
            desc.setText(appNames);
          }
        });
    testLabel.addMouseOutHandler(
        new MouseOutHandler() {
          public void onMouseOut(MouseOutEvent event) {
            testLabel.setStyleName(style.projectIcon());
            desc.hide();
          }
        });
    testLabel.addClickHandler(
        new ClickHandler() {
          public void onClick(ClickEvent event) {
            testLabel.setStyleName(style.projectIcon());
            eventBus.fireEvent(
                new PanelTransitionEvent(
                    PanelTransitionEvent.TransitionTypes.DASHBOARD, projectName));
          }
        });

    projectIconsFlowPanel.add(testLabel);
    iconMap.put(project.getName(), projectIconsFlowPanel.getWidgetIndex(testLabel));
  }
 /**
  * Restricts the Place search results to Places with a type matching at least one of the specified
  * types in this array. Valid types are given <a href=
  * "https://developers.google.com/maps/documentation/places/supported_types" >here</a>.
  */
 public final AutocompleteType[] getTypes() {
   JsArrayString at = getTypesImpl();
   if (at == null) {
     return null;
   }
   AutocompleteType[] types = new AutocompleteType[at.length()];
   for (int i = 0; i < at.length(); i++) {
     types[i] = AutocompleteType.fromValue(at.get(i));
   }
   return types;
 }
Esempio n. 6
0
 private void redrawVocabularies(TaxonomyDto taxonomy, FlowPanel panelTaxonomy) {
   JsArrayString vocabularies = JsArrays.toSafeArray(taxonomy.getVocabulariesArray());
   if (vocabularies.length() > 0) {
     panelTaxonomy.add(new Heading(5, translations.vocabulariesLabel()));
     FlowPanel vocabulariesPanel = new FlowPanel();
     for (int i = 0; i < vocabularies.length(); i++) {
       vocabulariesPanel.add(getVocabularyLink(getUiHandlers(), taxonomy, vocabularies.get(i)));
     }
     panelTaxonomy.add(vocabulariesPanel);
   }
 }
Esempio n. 7
0
  private boolean sameElements(JsArrayString a, String[] b) {
    if (a.length() != b.length) return false;

    ArrayList<String> a1 = new ArrayList<String>();
    for (int i = 0; i < a.length(); i++) a1.add(a.get(i));
    Collections.sort(a1);

    Arrays.sort(b);

    for (int i = 0; i < b.length; i++) if (!a1.get(i).equals(b[i])) return false;

    return true;
  }
  public void addComponentMappings(ValueMap valueMap, WidgetSet widgetSet) {
    JsArrayString keyArray = valueMap.getKeyArray();
    for (int i = 0; i < keyArray.length(); i++) {
      String key = keyArray.get(i).intern();
      int value = valueMap.getInt(key);
      tagToServerSideClassName.put(value, key);
    }

    for (int i = 0; i < keyArray.length(); i++) {
      String key = keyArray.get(i).intern();
      int value = valueMap.getInt(key);
      widgetSet.ensureConnectorLoaded(value, this);
    }
  }
  protected void onReceiving(int statusCode, String responseText, boolean connected) {
    if (statusCode != Response.SC_OK) {
      if (!connected) {
        expectingDisconnection = true;
        listener.onError(new StatusCodeException(statusCode, responseText), connected);
      }
    } else {
      int index = responseText.lastIndexOf(SEPARATOR);
      if (index > read) {
        List<Serializable> messages = new ArrayList<Serializable>();
        JsArrayString data = AtmosphereClient.split(responseText.substring(read, index), SEPARATOR);
        int length = data.length();
        for (int i = 0; i < length; i++) {
          if (aborted) {
            return;
          }
          parse(data.get(i), messages);
        }
        read = index + 1;
        if (!messages.isEmpty()) {
          listener.onMessage(messages);
        }
      }

      if (!connected) {
        if (expectingDisconnection) {
          listener.onDisconnected();
        } else {
          listener.onError(new AtmosphereClientException("Unexpected disconnection"), false);
        }
      }
    }
  }
Esempio n. 10
0
 // Given an array of tabs, replace any obsolete entries with their
 // replacements
 public static void replaceObsoleteTabs(JsArrayString tabs) {
   for (int idx = 0; idx < tabs.length(); idx++) {
     if (indexOfReplacedTab(tabs.get(idx)) >= 0) {
       tabs.set(idx, getReplacementTabs()[idx]);
     }
   }
 }
Esempio n. 11
0
 public List<String> getCategoryList() {
   final List<String> categories = new ArrayList<String>();
   final JsArrayString jsCategories = getCategories();
   for (int i = 0; i < jsCategories.length(); i++) {
     categories.add(jsCategories.get(i));
   }
   return categories;
 }
 public void addComponentInheritanceInfo(ValueMap valueMap) {
   JsArrayString keyArray = valueMap.getKeyArray();
   for (int i = 0; i < keyArray.length(); i++) {
     String key = keyArray.get(i);
     int value = valueMap.getInt(key);
     componentInheritanceMap.put(Integer.parseInt(key), value);
   }
 }
Esempio n. 13
0
 /** IDs of map types to show in the control. */
 public final ArrayList<MapTypeId> getMapTypeIds() {
   ArrayList<MapTypeId> ids = new ArrayList<MapTypeId>();
   JsArrayString values = _getMapTypeIds();
   for (int index = 0; index < values.length(); index++) {
     ids.add(MapTypeId.fromValue(values.get(index)));
   }
   return ids;
 }
Esempio n. 14
0
 public List<String> getTextPropertyNames() {
   final JsArrayString nativeNames = getNativePropertyNames(getJSObject());
   final List<String> names = new ArrayList<String>();
   for (int i = 0; i < nativeNames.length(); i++) {
     names.add(nativeNames.get(i));
   }
   return names;
 }
Esempio n. 15
0
 @Deprecated
 public final Set<String> keySet() {
   JsArrayString array = keys();
   Set<String> set = new HashSet<String>();
   for (int i = 0; i < array.length(); i++) {
     set.add(array.get(i));
   }
   return set;
 }
Esempio n. 16
0
 public String getCategoriesAsString() {
   final StringBuilder catBuilder = new StringBuilder();
   final JsArrayString categories = getCategories();
   if (categories.length() > 0) {
     if (categories.length() == 1) {
       catBuilder.append("Category: ");
     } else {
       catBuilder.append("Categories: ");
     }
     for (int i = 0; i < categories.length(); i++) {
       catBuilder.append(categories.get(i));
       if (i != (categories.length() - 1)) {
         catBuilder.append(", ");
       }
     }
   }
   return catBuilder.toString();
 }
Esempio n. 17
0
  public final boolean validateAndAutoCorrect() {
    JsArrayString panes = getPanes();
    if (panes == null) return false;
    if (!sameElements(panes, new String[] {SOURCE, CONSOLE, "TabSet1", "TabSet2"})) return false;

    JsArrayString ts1 = getTabSet1();
    JsArrayString ts2 = getTabSet2();
    if (ts1.length() == 0 || ts2.length() == 0) return false;

    // Replace any obsoleted tabs in the config
    replaceObsoleteTabs(ts1);
    replaceObsoleteTabs(ts2);

    // If any of these tabs are missing, then they can be added
    Set<String> addableTabs = makeSet(getAddableTabs());

    // If any of these tabs are missing, then the whole config is invalid
    Set<String> baseTabs = makeSet(getAllTabs());
    baseTabs.removeAll(addableTabs);

    for (String tab : JsUtil.asIterable(concat(ts1, ts2))) {
      if (!baseTabs.remove(tab) && !addableTabs.remove(tab)) return false; // unknown tab
    }

    // If any baseTabs are still present, they weren't part of the tabsets
    if (baseTabs.size() > 0) return false;

    // Were any addable tabs missing? Add them the appropriate tabset
    // (Iterate over original array instead of addableTabs set so that order
    // is well-defined)
    for (String tab : getAddableTabs())
      if (addableTabs.contains(tab))
        if (tab.equals("Viewer")) ts2.push(tab);
        else ts1.push(tab);

    // These tabs can be hidden sometimes; they can't stand alone in a tabset
    Set<String> hideableTabs = makeSet(getHideableTabs());
    if (isSubset(hideableTabs, JsUtil.asIterable(ts1))
        || isSubset(hideableTabs, JsUtil.asIterable(ts2))) {
      return false;
    }

    return true;
  }
  private void init() {
    Map<String, Element> containers = contentContainerFactory.list();
    for (String containerName : containers.keySet()) {
      List<String> containerStyles = new ArrayList<String>();
      styles.put(containerName, containerStyles);
      Element element = containers.get(containerName);
      List<JavaScriptRegExp> matchers = new ArrayList<JavaScriptRegExp>();
      if (element.hasAttribute("id")) {
        matchers.add(
            JavaScriptRegExp.create(
                "^\\s*#" + element.getAttribute("id") + "\\s+>?\\s*([^\\s,]+)"));
      }
      String[] cssClasseNames = element.getClassName().trim().split("\\s+");
      for (String cssClassName : cssClasseNames) {
        matchers.add(JavaScriptRegExp.create("^\\s*." + cssClassName + "\\s+>?\\s*([^\\s,]+)"));
      }

      JsArray<StyleSheet> styleSheets = StyleSheet.getAll();
      for (int i = 0; i < styleSheets.length(); i++) {
        StyleSheet styleSheet = styleSheets.get(i);
        if (styleSheet == null) continue;

        // In Chrome, if stylesheet originates from a different domain,
        // ss.cssRules simply won't exist. I believe the same is true for IE, but
        // I haven't tested it.
        //
        // In Firefox, if stylesheet originates from a different domain, trying
        // to access ss.cssRules will throw a SecurityError. Hence, we must use
        // try/catch to detect this condition in Firefox.
        JsArray<CSSStyleRule> cssRules;
        try {
          cssRules = styleSheet.cssRules();
        } catch (JavaScriptException e) {
          cssRules = null;
        }
        if (cssRules == null) continue;
        for (int j = 0; j < cssRules.length(); j++) {
          CSSStyleRule rule = cssRules.get(j);
          if (rule == null) continue;
          if (rule.selectorText() == null) continue;
          String[] selectors = rule.selectorText().split(",");
          for (String selector : selectors) {
            for (JavaScriptRegExp matcher : matchers) {
              JsArrayString matches = matcher.match(selector);
              if (matches != null
                  && matches.length() == 2
                  && !containerStyles.contains(matches.get(1))) {
                containerStyles.add(matches.get(1));
              }
            }
          }
        }
      }
    }
  }
 private boolean modePresent(final String modeName) {
   if (modeName == null) {
     return false;
   }
   final JsArrayString modeNames = this.codeMirror.modeNames();
   for (int i = 0; i < modeNames.length(); i++) {
     if (modeName.equals(modeNames.get(i))) {
       return true;
     }
   }
   return false;
 }
Esempio n. 20
0
    private String getUri() {
      UriBuilder uriBuilder =
          tableIsView()
              ? UriBuilders.DATASOURCE_VIEW_VARIABLES.create()
              : UriBuilders.DATASOURCE_TABLE_VARIABLES.create();

      for (int i = nb_deleted, added = 0;
          i < variableNames.length() && added < BATCH_SIZE;
          i++, added++) {
        uriBuilder.query("variable", variableNames.get(i));
      }

      return uriBuilder.build(table.getDatasourceName(), table.getName());
    }
  private RmdFrontMatterOutputOptions transferOptions(
      RmdFrontMatter frontMatter, RmdTemplate template, String format) {
    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;
  }
  /** Just make sure that reentrant behavior doesn't fail. */
  public static void testReentrantCalls() {
    if (!GWT.isScript()) {
      // sample is useless in Development Mode
      return;
    }

    JsArrayString start = sample();

    JsArrayString stack = countDown(5);
    assertNotNull(stack);
    assertTrue(stack.length() > 0);

    JsArrayString end = sample();
    assertEquals(start, end);
  }
Esempio n. 23
0
    public boolean isEquals(BucketsOverlay other) {
      if (super.equals(other)) return true;

      final JsArrayString keys = getKeysNative();
      final JsArrayString otherKeys = other.getKeysNative();
      if (arraysEquals(keys, otherKeys)) {
        for (int i = 0; i < keys.length(); i++) {
          if (!arraysEquals(getNative(keys.get(i)), other.getNative(otherKeys.get(i)))) {
            return false;
          }
        }
        return true;
      }

      return false;
    }
Esempio n. 24
0
  @Override
  public void onDeleteVariables(List<VariableDto> variableDtos) {
    if (variableDtos.isEmpty()) {
      fireEvent(NotificationEvent.newBuilder().error("DeleteVariableSelectAtLeastOne").build());
    } else {
      JsArrayString variableNames = JsArrays.create().cast();
      for (VariableDto variable : variableDtos) {
        variableNames.push(variable.getName());
      }

      deleteVariablesConfirmation = new RemoveVariablesRunnable(variableNames);

      fireEvent(
          ConfirmationRequiredEvent.createWithMessages(
              deleteVariablesConfirmation,
              translationMessages.removeVariables(),
              translationMessages.confirmRemoveVariables(variableNames.length())));
    }
  }
Esempio n. 25
0
 private ArrayList<String> convertList(JsArrayString jsList) {
   ArrayList<String> list = new ArrayList<String>();
   for (int i = 0; i < jsList.length(); i++) list.add(jsList.get(i));
   return list;
 }
Esempio n. 26
0
  public final int getConsoleIndex() {
    JsArrayString panes = getPanes();
    for (int i = 0; i < panes.length(); i++) if (panes.get(i).equals("Console")) return i;

    throw new IllegalStateException();
  }
 private static void assertEquals(JsArrayString start, JsArrayString end) {
   assertEquals("length", start.length(), end.length());
   for (int i = 0, j = start.length(); i < j; i++) {
     assertEquals("frame " + i, start.get(i), end.get(i));
   }
 }
Esempio n. 28
0
 private void setHistory(JsArrayString history) {
   ArrayList<String> historyList = new ArrayList<String>(history.length());
   for (int i = 0; i < history.length(); i++) historyList.add(history.get(i));
   historyManager_.setHistory(historyList);
   browseHistoryManager_.resetPosition();
 }