/* (non-Javadoc)
   * @see org.jboss.tools.vpe.editor.template.VpeTemplate#create(org.jboss.tools.vpe.editor.context.VpePageContext, org.w3c.dom.Node, org.mozilla.interfaces.nsIDOMDocument)
   */
  public VpeCreationData create(
      VpePageContext pageContext, Node sourceNode, nsIDOMDocument visualDocument) {
    Element sourceElement = (Element) sourceNode;
    nsIDOMElement select = visualDocument.createElement(HTML.TAG_SELECT);

    VisualDomUtil.copyAttributes(sourceElement, select, COMMON_SPRING_FORM_ATTRIBUTES_MAP);

    if (SpringConstant.VALUE_TRUE.equals(
        sourceElement.getAttribute(SpringConstant.ATTR_DISABLED))) {
      select.setAttribute(HTML.ATTR_DISABLED, HTML.ATTR_DISABLED);
    }

    if (!SpringConstant.VALUE_FALSE.equals(
        sourceElement.getAttribute(SpringConstant.ATTR_MULTIPLE))) {
      select.setAttribute(HTML.ATTR_MULTIPLE, HTML.ATTR_MULTIPLE);
    }

    if (sourceElement.hasAttribute(SpringConstant.ATTR_ITEMS)) {
      // an inner 'option' tag has to be generated
      String optionBody = sourceElement.getAttribute(SpringConstant.ATTR_ITEMS);
      if (sourceElement.hasAttribute(SpringConstant.ATTR_ITEM_LABEL)) {
        optionBody += '.' + sourceElement.getAttribute(SpringConstant.ATTR_ITEM_LABEL);
      }

      nsIDOMElement option = visualDocument.createElement(HTML.TAG_OPTION);
      option.appendChild(visualDocument.createTextNode(optionBody));
      select.appendChild(option);
    }

    return new VpeCreationData(select);
  }
  public void testNoDefaultLocaleForChangeAndRefresh() throws Throwable {
    VpeController controller =
        openInVpe(JsfAllTests.IMPORT_JSF_LOCALES_PROJECT_NAME, NO_DEFLOC_CHANGE_REFRESH_PAGE);
    nsIDOMDocument doc = controller.getXulRunnerEditor().getDOMDocument();

    nsIDOMElement localeText = doc.getElementById(LOCALE_TEXT_ID);
    String localizedText = getLocalizedText(localeText);
    assertTrue(
        "Text is '" + localizedText + "', but should be in 'de' locale",
        HELLO2_DE.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$
    /*
     * Change the locale
     */
    Element fViewElement =
        controller.getSourceBuilder().getSourceDocument().getElementById(FVIEW_ID);
    int offset = controller.getSourceBuilder().getPosition(fViewElement, 0, false);
    assertTrue(
        "Previous locale should be 'de'",
        "de"
            .equalsIgnoreCase(
                fViewElement.getAttribute("locale"))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    IRegion reg =
        new FindReplaceDocumentAdapter(
                controller.getSourceBuilder().getStructuredTextViewer().getDocument())
            .find(offset, "de", true, true, false, false);
    controller
        .getSourceBuilder()
        .getStructuredTextViewer()
        .getDocument()
        .replace(reg.getOffset(), reg.getLength(), "en_GB");
    /*
     * Wait until new value is applied and children are refreshed.
     * Wait while all deferred events are processed
     */
    while (Display.getCurrent().readAndDispatch()) ;
    /*
     * Wait while all jobs including started through deferred events are ended
     */
    JobUtils.delay(VpeController.DEFAULT_UPDATE_DELAY_TIME * 4);
    TestUtil.waitForIdle();
    fViewElement = controller.getSourceBuilder().getSourceDocument().getElementById(FVIEW_ID);
    assertTrue(
        "Current locale should be 'en_GB'",
        "en_GB"
            .equalsIgnoreCase(
                fViewElement.getAttribute("locale"))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$

    doc = controller.getXulRunnerEditor().getDOMDocument();
    localeText = doc.getElementById(LOCALE_TEXT_ID);
    localizedText = getLocalizedText(localeText);

    /*
     * Check the new localized message.
     */
    assertTrue(
        "Text is '" + localizedText + "', but should be in 'en_GB' locale",
        HELLO_EN_GB.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$
    closeEditors();
  }
 /**
  * Tests that the dafault locale is applied by default, f:view has no locale attribute in this
  * case.
  *
  * @throws Throwable
  */
 public void testDefaultLocale() throws Throwable {
   VpeController controller = openInVpe(JsfAllTests.IMPORT_I18N_PROJECT_NAME, DEFAULT_LOCALE_PAGE);
   nsIDOMDocument doc = controller.getXulRunnerEditor().getDOMDocument();
   nsIDOMElement localeText = doc.getElementById(LOCALE_TEXT_ID);
   String localizedText = getLocalizedText(localeText);
   assertTrue(
       "Text is '" + localizedText + "', but should be in 'de' locale",
       HELLO_DE.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$
   closeEditors();
 }
  public void testJbide() throws Throwable {

    // get test page path
    IFile file =
        (IFile) TestUtil.getComponentPath(TEST_PAGE_NAME, RichFacesAllTests.IMPORT_PROJECT_NAME);

    assertNotNull(
        "Could not open specified file. componentPage = "
            + TEST_PAGE_NAME
            + ";projectName = "
            + RichFacesAllTests.IMPORT_PROJECT_NAME,
        file); //$NON-NLS-1$

    IEditorInput input = new FileEditorInput(file);

    assertNotNull("Editor input is null", input);
    // open and get editor
    JSPMultiPageEditor part = openEditor(input);

    // get dom document
    nsIDOMDocument document = TestUtil.getVpeVisualDocument(part);
    nsIDOMElement element = document.getDocumentElement();

    assertNotNull(element);

    // get root node
    nsIDOMNode node = queryInterface(element, nsIDOMNode.class);

    List<nsIDOMNode> elements = new ArrayList<nsIDOMNode>();

    // find "table" elements
    TestUtil.findElementsByName(node, elements, HTML.TAG_TABLE);

    assertEquals(2, elements.size());

    // get first table. It has default attributes (minValue=0, maxValue=100)
    nsIDOMNode defaultInputSlider = elements.get(0);
    // check min-,max- values
    checkMinMaxValue(defaultInputSlider, 0, 100);

    // get first table. It has edited attributes (minValue=-10,
    // maxValue=200)
    nsIDOMNode editedInputSlider = elements.get(1);
    // check min-,max- values
    checkMinMaxValue(editedInputSlider, -10, 200);

    // check exception
    if (getException() != null) {
      throw getException();
    }
  }
Exemplo n.º 5
0
 /** @see com.aptana.ide.editors.unified.ContributedBrowser#execute(java.lang.String) */
 public boolean execute(String script) {
   nsIDOMDocument document = internalGetDocument();
   if (document != null) {
     nsIDOMElement se = document.createElement("script"); // $NON-NLS-1$
     nsIDOMHTMLScriptElement scriptBlock =
         (nsIDOMHTMLScriptElement)
             se.queryInterface(nsIDOMHTMLScriptElement.NS_IDOMHTMLSCRIPTELEMENT_IID);
     String s2 =
         "if("
             + script
             + "){"
             + "document.getElementById('execute').setAttribute('text','success');}"; //$NON-NLS-1$
                                                                                      // //$NON-NLS-2$ //$NON-NLS-3$
     scriptBlock.setText(s2);
     nsIDOMElement executeBlock = document.getElementById("execute"); // $NON-NLS-1$
     if (executeBlock == null) {
       executeBlock = document.createElement("div"); // $NON-NLS-1$
       executeBlock.setAttribute("id", "execute"); // $NON-NLS-1$ //$NON-NLS-2$
       nsIDOMNode body = document.getElementsByTagName("body").item(0); // $NON-NLS-1$
       body.appendChild(executeBlock);
     }
     executeBlock.setAttribute("text", ""); // $NON-NLS-1$ //$NON-NLS-2$
     nsIDOMNode head = document.getElementsByTagName("head").item(0); // $NON-NLS-1$
     head.appendChild(scriptBlock);
     executeBlock = document.getElementById("execute"); // $NON-NLS-1$
     return "success".equals(executeBlock.getAttribute("text")); // $NON-NLS-1$ //$NON-NLS-2$
   } else {
     return false;
   }
 }
  /**
   * If there are several f:views on the page. Only the last f:view one should be applied on server,
   * but each f:view should have its own locale.
   *
   * @throws Throwable
   */
  public void testSeveralFViewsWithLocales() throws Throwable {

    IFile file =
        (IFile)
            TestUtil.getComponentPath(SEVERAL_FVIEWS_PAGE, JsfAllTests.IMPORT_JSF_20_PROJECT_NAME);
    assertNotNull(
        "Could not open specified file." //$NON-NLS-1$
            + " componentPage = "
            + SEVERAL_FVIEWS_PAGE //$NON-NLS-1$
            + ";projectName = "
            + JsfAllTests.IMPORT_JSF_20_PROJECT_NAME,
        file); //$NON-NLS-1$
    IEditorInput input = new FileEditorInput(file);
    assertNotNull("Editor input is null", input); // $NON-NLS-1$
    /*
     * open and get the editor
     */
    JSPMultiPageEditor part = openEditor(input);
    VpeController controller = TestUtil.getVpeController(part);

    javaSources = EclipseResourceUtil.getJavaProjectSrcLocations(file.getProject());
    nsIDOMDocument doc = controller.getXulRunnerEditor().getDOMDocument();
    nsIDOMElement localeText = doc.getElementById(LOCALE_TEXT0_ID);
    String localizedText = getLocalizedText(localeText);
    checkLocaleStrings(file, "en", localizedText); // $NON-NLS-1$

    localeText = doc.getElementById(LOCALE_TEXT1_ID);
    localizedText = getLocalizedText(localeText);
    checkLocaleStrings(file, "de", localizedText); // $NON-NLS-1$

    localeText = doc.getElementById(LOCALE_TEXT2_ID);
    localizedText = getLocalizedText(localeText);
    /*
     * f:view will use default locale if nothing is specified.
     */
    checkLocaleStrings(file, "en_US", localizedText); // $NON-NLS-1$

    localeText = doc.getElementById(LOCALE_TEXT_ID);
    localizedText = getLocalizedText(localeText);
    checkLocaleStrings(file, "en_GB", localizedText); // $NON-NLS-1$

    closeEditors();
  }
 /**
  * After the locale attribute value has been changed and Refresh button is clicked - the correct
  * locale should be applied, bundle messages should be updated and showed in the correct locale.
  *
  * @throws Throwable
  */
 public void testChangeLocaleAndRefresh() throws Throwable {
   VpeController controller =
       openInVpe(JsfAllTests.IMPORT_JSF_20_PROJECT_NAME, CHANGE_LOCALE_AND_REFRESH_PAGE);
   nsIDOMDocument doc = controller.getXulRunnerEditor().getDOMDocument();
   nsIDOMElement localeText = doc.getElementById(LOCALE_TEXT_ID);
   String localizedText = getLocalizedText(localeText);
   assertTrue(
       "Text is '" + localizedText + "', but should be in 'de' locale",
       HELLO2_DE.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$
   /*
    * Change the locale
    */
   Element fViewElement =
       controller.getSourceBuilder().getSourceDocument().getElementById(FVIEW_ID);
   assertTrue(
       "Previous locale should be 'de'",
       "de"
           .equalsIgnoreCase(
               fViewElement.getAttribute("locale"))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
   fViewElement.setAttribute("locale", "en_GB"); // $NON-NLS-1$ //$NON-NLS-2$
   /*
    * Wait until new value is applied and children are refreshed.
    */
   TestUtil.delay(500);
   TestUtil.waitForIdle();
   assertTrue(
       "Current locale should be 'en_GB'",
       "en_GB"
           .equalsIgnoreCase(
               fViewElement.getAttribute("locale"))); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
   doc = controller.getXulRunnerEditor().getDOMDocument();
   localeText = doc.getElementById(LOCALE_TEXT_ID);
   localizedText = getLocalizedText(localeText);
   /*
    * Check the new localized message.
    */
   assertTrue(
       "Text is '" + localizedText + "', but should be in 'en_GB' locale",
       HELLO_EN_GB.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$
   closeEditors();
 }
Exemplo n.º 8
0
  /** @see com.aptana.ide.editors.unified.ContributedBrowser#displaySource() */
  public void displaySource() {
    if (document != null) {
      nsIDOMSerializer serializer =
          (nsIDOMSerializer)
              Mozilla.getInstance()
                  .getComponentManager()
                  .createInstanceByContractID(
                      "@mozilla.org/xmlextras/xmlserializer;1",
                      null, //$NON-NLS-1$
                      nsIDOMSerializer.NS_IDOMSERIALIZER_IID);
      String source = serializer.serializeToString(document.getDocumentElement());
      try {
        final String newFileName =
            FileUtils.getRandomFileName("source", ".html"); // $NON-NLS-1$ //$NON-NLS-2$
        final File temp = new File(FileUtils.systemTempDir + File.separator + newFileName);
        FileUtils.writeStringToFile(source, temp);
        UIJob openJob =
            new UIJob(Messages.getString("FirefoxBrowser.Open_Source_Editor")) // $NON-NLS-1$
            {

              public IStatus runInUIThread(IProgressMonitor monitor) {
                IEditorInput input = CoreUIUtils.createJavaFileEditorInput(temp);
                try {
                  IDE.openEditor(
                      Activator.getDefault()
                          .getWorkbench()
                          .getActiveWorkbenchWindow()
                          .getActivePage(),
                      input,
                      IDE.getEditorDescriptor(newFileName).getId());
                } catch (PartInitException e) {
                  e.printStackTrace();
                }
                return Status.OK_STATUS;
              }
            };
        openJob.schedule();
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
  }
  /**
   * Creates a node of the visual tree on the node of the source tree. This visual node should not
   * have the parent node This visual node can have child nodes.
   *
   * @param pageContext Contains the information on edited page.
   * @param sourceNode The current node of the source tree.
   * @param visualDocument The document of the visual tree.
   * @return The information on the created node of the visual tree.
   */
  public VpeCreationData create(
      VpePageContext pageContext, Node sourceNode, nsIDOMDocument visualDocument) {
    ComponentUtil.setCSSLink(pageContext, SPACER_CSS_FILE, "spacer"); // $NON-NLS-1$
    // convert to Element
    Element sourceElement = (Element) sourceNode;

    nsIDOMElement img = visualDocument.createElement(HTML.TAG_IMG);
    ComponentUtil.setImg(img, IMAGE_NAME);

    // set STYLE attributes
    String attrValue = ComponentUtil.getAttribute(sourceElement, RichFaces.ATTR_STYLE);
    if (attrValue.length() != 0) {
      img.setAttribute(HTML.ATTR_STYLE, attrValue);
    }
    // set CLASS attribute
    attrValue = ComponentUtil.getAttribute(sourceElement, RichFaces.ATTR_STYLE_CLASS);
    String styleClass = RICH_SPACER_STYLE;
    if (attrValue.length() != 0) {
      styleClass += Constants.WHITE_SPACE + attrValue;
    }
    img.setAttribute(HTML.ATTR_CLASS, styleClass);
    // set WIDTH attribute
    String width = ComponentUtil.getAttribute(sourceElement, HTML.ATTR_WIDTH, DEFAULT_SIZE);
    img.setAttribute(HTML.ATTR_WIDTH, width);
    // set HEIGHT attribute
    String height = ComponentUtil.getAttribute(sourceElement, HTML.ATTR_HEIGHT, DEFAULT_SIZE);
    img.setAttribute(HTML.ATTR_HEIGHT, height);

    /*
     * https://jira.jboss.org/jira/browse/JBIDE-3225
     * Component should render its children.
     */
    VpeCreationData creationData =
        VisualDomUtil.createTemplateWithTextContainer(
            sourceElement, img, HTML.TAG_SPAN, visualDocument);

    return creationData;
  }
  public void testNoDefaultLocaleForSingleFLoadBundle() throws Throwable {
    VpeController controller =
        openInVpe(JsfAllTests.IMPORT_JSF_LOCALES_PROJECT_NAME, NO_DEFLOC_ONE_LOAD_BUNDLE_PAGE);
    nsIDOMDocument doc = controller.getXulRunnerEditor().getDOMDocument();

    nsIDOMElement localeText = doc.getElementById(LOCALE_TEXT0_ID);
    String localizedText = getLocalizedText(localeText);
    assertTrue(
        "Text is '" + localizedText + "', but should be in 'en_US' locale",
        HELLO_EN_US.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$

    localeText = doc.getElementById(LOCALE_TEXT1_ID);
    localizedText = getLocalizedText(localeText);
    assertTrue(
        "Text is '" + localizedText + "', but should be in 'en_US' locale",
        HELLO_EN_US.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$

    localeText = doc.getElementById(LOCALE_TEXT2_ID);
    localizedText = getLocalizedText(localeText);
    assertTrue(
        "Text is '" + localizedText + "', but should be in 'en_US' locale",
        HELLO_EN_US.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$

    localeText = doc.getElementById(LOCALE_TEXT3_ID);
    localizedText = getLocalizedText(localeText);
    assertTrue(
        "Text is '" + localizedText + "', but should be in 'en_US' locale",
        HELLO_EN_US.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$

    localeText = doc.getElementById(LOCALE_TEXT_ID);
    localizedText = getLocalizedText(localeText);
    assertTrue(
        "Text is '" + localizedText + "', but should be in 'en_US' locale",
        HELLO_EN_US.equalsIgnoreCase(localizedText)); // $NON-NLS-1$ //$NON-NLS-2$

    closeEditors();
  }