How do you get the namespace of a component? - actionscript-3

I'm trying to write CSS stylesheet dynamically but Flex 4 requires that you declare the namespace in the Style markup.
If I have a Spark Button or MX Button class or class instance how would I get the namespace of that button?
So far I've tried this:
var className:Object = getQualifiedClassName(myButton);
var ButtonClass:Object = ApplicationDomain.currentDomain.getDefinition(className);
var button:Object = new ButtonClass();
With that information I can write this:
<fx:Style>
myButton {
color: red;
}
</fx:Style>
I need to create this:
<fx:Style>
#namespace s "library://ns.adobe.com/flex/spark";
#namespace mx "library://ns.adobe.com/flex/mx";
s|Button {
color: red;
}
</fx:Style>
I would like to be able to get this information at runtime but design time may be acceptable as well.

It's the same format as the namespace in the MXML code. I.e., if you have components in com.xyzzy.components, the MXML namespace is something like
xmlns:components="com.xyzzy.components.*"
And the CSS namespace would be like
#namespace components "com.xyzzy.components.*";
components|myButton {...}

It looks like I can't get it at runtime but I can get it XML files from the SDK directory and create a table of classes and their namespace.
In $FlashBuilder/sdks/4.6.0/frameworks/flex-config.xml there is a node called namespaces that contain the URI of the namespace and then a reference to the XML file that contains a list of classes in that namespace.
<!-- Specify a URI to associate with a manifest of components for use as MXML -->
<!-- elements. -->
<namespace>
<uri>http://ns.adobe.com/mxml/2009</uri>
<manifest>mxml-2009-manifest.xml</manifest>
</namespace>
<namespace>
<uri>library://ns.adobe.com/flex/spark</uri>
<manifest>spark-manifest.xml</manifest>
</namespace>
<namespace>
<uri>library://ns.adobe.com/flex/mx</uri>
<manifest>mx-manifest.xml</manifest>
</namespace>
<namespace>
<uri>http://www.adobe.com/2006/mxml</uri>
<manifest>mxml-manifest.xml</manifest>
</namespace>
<namespace>
<uri>http://flex.apache.org/ns</uri>
<manifest>apache-manifest.xml</manifest>
</namespace>
<namespace>
<uri>http://flex.apache.org/experimental/ns</uri>
<manifest>experimental-manifest.xml</manifest>
</namespace>
</namespaces>
I can use that information and the MXML document to add the necessary namespace to each node.

Related

How to dynamically control what menu items are shown

In my Skyve application, I have a situation where - whether users see an application menu item in the responsive mode needs to be determined dynamically - based on some combination of preference settings etc - rather than merely what module role they have been assigned.
How can I dynamically add or remove items from the menu they access and where do I locate this code?
(NOTE: The usual Skyve no-code approach relies on access to menu items being controlled by the roles declared in the module, and so overriding the menu class is not usually required - this is definitely an advanced activity.)
The responsive mode in Skyve (which is using PrimeFaces) uses a the "Menu" session scoped faces view bean to generate what is seen by users, and this is referenced from the various template.xhtml page templates. You can extend this class to control what elements of the menu are see by users.
Your project includes the template.xhtml pages for whichever theme you have chosen to use in your project - for example if you are using the editorial (free) theme, then the corresponding template will be at:
src/main/webapp/WEB-INF/pages/editorial/template.xhtml
You'll find the reference to the Menu bean around line 155 (depending on your particular Skyve version) and it will be similar for other themes.
<p:panelMenu id="leftMenu" model="#{menu.menu}" />
Extend org.skyve.impl.web.faces.beans.Menu to customise the behaviour of the menu. Probably the simplest approach is to define all potential menus in the usual way - by declaring these in the "module.xml" file - and then adding or removing the items that are not applicable in your Menu class override.
For example, if your module has the following menu items declared:
<menu>
<edit document="MyDetail" name="My Details">
<role name="StaffUser"/>
</edit>
<edit document="OrganisationDashboard" name="Organisation Dashboard">
<role name="Manager"/>
<role name="Administrator"/>
</edit>
<list query="qAllStaff" name="All Staff">
<role name="Manager"/>
<role name="Administrator"/>
</list>
...
To conditionally hide the "Organisation Dashboard" menu item - then you can create your own Menu override class as follows:
package com.myOrg.faces;
import java.util.Iterator;
import java.util.List;
import javax.faces.bean.ManagedBean;
import org.primefaces.model.menu.DefaultMenuItem;
import org.primefaces.model.menu.DefaultMenuModel;
import org.primefaces.model.menu.DefaultSubMenu;
import org.primefaces.model.menu.MenuElement;
import org.primefaces.model.menu.MenuModel;
import org.skyve.impl.web.faces.beans.Menu;
#ManagedBean(name = "myCustomMenu")
public class MyCustomMenu extends Menu {
#Override
public MenuModel getMenu() {
DefaultMenuModel result = (DefaultMenuModel) super.getMenu(); // do the usual steps Skyve will do according to the no-code module declaration
List<MenuElement> subMenus = result.getElements();
if (! subMenus.isEmpty()) {
DefaultSubMenu mainMenu = (DefaultSubMenu) subMenus.get(0);
mainMenu.getElements().removeIf(e -> {
return ((e instanceof MenuItem) &&
"Organisation Dashboard".equals((MenuItem) e).getValue());
});
}
return result;
}
}
Then you can provide this bean name in the template.xhtml as follows:
<p:panelMenu id="leftMenu" model="#{myCustomMenu.menu}" />

How to pass document variable to ES6 Module during Jasmine testing

I want to test if a function in a module generated something in document but I am having trouble defining the document variable. I have simulated it jsdom but I am unable to define it in module.
In my actual project, I use the document, window and MathJax library globally and I don't want to pass it to classes through the constructor unless there is no other way.
Example of a class I want to test:
// example.mjs
export class Example {
createElement() {
document.createElement("div")
}
}
Test file:
import {Example} from './example.mjs';
import {JSDOM} from "jsdom";
describe("Example", function () {
it('should create div', function () {
const dom = new JSDOM(`<!DOCTYPE html><p>Hello world</p>`);
document = dom.window.document; //is it possible to make this defined in all modules
new Example().createElement() // document is not defined
});
})
My question is, is it possible to somehow make the document variable defined, so that it can be referenced in the Example class or do I have to pass it in the constructor?

CMake: Howto modify a variable from inside a function

What is the best practice to modify a caller's variable from inside a CMake-function.
Assume
function(MyFunction IN_OUT_NAME)
... what to do here ...
string(APPEND ${IN_OUT_NAME} " and that")
... what to do here ...
endfunction()
What needs to be done such that the following code fragment
set(MY_MESSAGE "this")
MyFunction(MY_MESSAGE)
message(${MY_MESSAGE})
delivers
this and that
Not-a-duplicate-remarks:
Modify a variable inside a function is about JavaScript not CMake
Is JavaScript a pass-by-reference or pass-by-value language? is about JavaScript not CMake
Just use PARENT_SCOPE to export the value to parent scope.
function(MyFunction IN_OUT_NAME)
string(APPEND ${IN_OUT_NAME} " and that")
set(${IN_OUT_NAME} "${${IN_OUT_NAME}}" PARENT_SCOPE)
endfunction()
set(MY_MESSAGE "this")
MyFunction(MY_MESSAGE)
message(${MY_MESSAGE})

VAADIN - Button | implement in HTML Layout-Script

is there any oportnunity to use a Vaadin Button in a HTML script?
Id like to use the following button
Button button_login = ew Button();
button_login.setID("buttonlogin");
and this button should be implement in the following script
<div data-location="buttonlogin"></div>
(Only an idea)
Have so. an idea to bind the button in the html script?
Thank!
I am quite unsure what you mean by html script. If it is something you can achieve using JavaScript then here is my try.
Generally to execute JavaScript on button click
Button js = new Button("Do JavaScript");
js.addClickListener( click -> {
com.vaadin.ui.JavaScript.getCurrent().execute("alert(´Hello´)");
});
When in need to use external .js files, for example hello.js, contents below
function hello() {
alert("Hello JavaScriptWorld!");
}
Assuming hello.js is directly under /VAADIN/ directory, add following annotation to your UI or relevant component class
#JavaScript({"vaadin://hello.js"}) // all paths must be relative to /VAADIN
Then in ClickListener you can refer to function hello() like
com.vaadin.ui.JavaScript.getCurrent().execute("hello()");
Java
#com.vaadin.annotations.JavaScript("vaadin://themes/paastheme/layouts/ui/donut/donut.js")
public class BrowsePeopleUI extends UI {}
I put JS file to:
src/main/resources/VAADIN/themes/paastheme/layouts/ui/donut/donut.js
My donut.js is:
Javascript
var util = util || {};
util.donut = () => {console.log(document.querySelectorAll("[data-svg]"))};

How to use an external actionscript file with flex

I'm building a Flash 4 Builder project and want to use an external actionscript file. Here is the structure I used...
http://img704.imageshack.us/img704/794/schermafbeelding2010121b.png
So, I want to be able to connect "actionscript.as" to the "OrderApp.mxml" file.
I add this <fx:Script source="assets/actionscript/actionscript.as"/> to my OrderAp.mxml file and a function in actionscript.as looks for example like this:
public function checkCode():void{
if (txtToegangscode.text == "moia") {
lblFeedback.text = "ok";
txtToegangscode.enabled = false;
btnGaNaarPersonen.visible = true;
btnGaVerder.visible = false;
} else {
lblFeedback.text = "wrong";
}
}
When I want to add some components, like "Toegangscode.mxml" I keep getting errors like "1120: Acces of undefined property lblFeedback". When I try to call the function checkCode() What do I do wrong?
You probably already found the answer you were looking for, however, there is this link to Adobe's site that has all the info you or other readers need.
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf61c8a-7ff4.html
Problem solved... Apparently, you have to use a different .as file for every component! Nevertheless thanks to everyone who helped me out!
Looks like you are missing the double quote at the start of the string?
lblFeedback.text = wrong";
should be...
lblFeedback.text = "wrong";
Why not put this code into a class then you can detect any compile errors?
EDITED:
Sorry I did not look carefully at your question.
Your problem is that the *.as file does not know what your components are:
You need to pass the components to the function like so:
public function checkCode(txtToegangscode:TextInput, lblFeedback:Label):void{
if (txtToegangscode.text == "moia") {
lblFeedback.text = "ok";
txtToegangscode.enabled = false;
btnGaNaarPersonen.visible = true;
btnGaVerder.visible = false;
} else {
lblFeedback.text = "wrong";
}
This will allow your *.as file to access the properties in those components.
OLD:
Here is the documentation: http://livedocs.adobe.com/flex/3/html/help.html?content=usingas_4.html
You use the source attribute of the tag to include external ActionScript files in your Flex applications. This provides a way to make your MXML files less cluttered and promotes code reuse across different applications.
Do not give the script file the same name as the application file. This causes a compiler error.
The following example shows the contents of the IncludedFile.as file:
// usingas/includes/IncludedFile.as
public function computeSum(a:Number, b:Number):Number {
return a + b;
}
The following example imports the contents of the IncludedFile.as file. This file is located in the includes subdirectory.
<?xml version="1.0"?>
<!-- usingas/SourceInclude.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script source="includes/IncludedFile.as"/>
<mx:TextInput id="ta1st" text="3" width="40" x="170" y="24" textAlign="right"/>
<mx:TextInput id="ta2nd" text="3" width="40" x="170" y="52" textAlign="right"/>
<mx:TextArea id="taMain" height="25" width="78" x="132" y="82" textAlign="right"/>
<mx:Button id="b1" label="Compute Sum"
click="taMain.text=String(computeSum(Number(ta1st.text), Number(ta2nd.text)));"
x="105"
y="115"
/>
<mx:Label x="148" y="52" text="+" fontWeight="bold" fontSize="17" width="23"/>
</mx:Application>
The source attribute of the tag supports both relative and absolute paths.
The source attribute of the tag and the include directive refer to files in different ways.
The following are the valid paths to external files that are referenced in an tag's source attribute:
Relative URLs, such as ../myscript.as. A relative URL that does not start with a slash is resolved relative to the file that uses it. If the tag is included in "mysite/myfiles/myapp.mxml," the system searches for "mysite/IncludedFile.as".
For an ActionScript include directive, you can reference only relative URLs. Flex searches the source path for imported classes and packages. Flex does not search the source path for files that are included using the include directive or the source attribute of the tag.