Ubuntu 源安装Oracle JAVA

1、增加源

sudo add-apt-repository “deb http://archive.canonical.com/ lucid partner”

2、更新源

sudo apt-get update
3、下载安装

sudo apt-get install sun-java6-bin sun-java6-jre

4、配置环境

4.1写入系统变量:
$sudo gedit /etc/environment

在文本编辑器里写入下面两行内容:
CLASSPATH=.:/usr/lib/jvm/java-6-sun/lib
JAVA_HOME=/usr/lib/jvm/java-6-sun

4.2将系统虚拟机的优先顺序也调整一下:
$sudo gedit /etc/jvm
在文本编辑器里将下面一句写在最顶部:
/usr/lib/jvm/java-6-sun

maven 发布项目到nexus服务器中

首先对Nexus服务器的Repositories中的类型有个了解,主要分为group、Hosted、Proxy和Virtual四种类型。
我们只能用Hosted作为发布的目标仓库。
1、配置.m2/settings.xml

<servers>
  <server>
    <id>nexus-releases</id>
     <username>admin</username>
     <password>****</password>
  </server>
   <server>
     <id>nexus-snapshots</id>
     <username>admin</username>
     <password>****</password>
   </server>
 </servers>

2.配置项目POM.xml



nexus-releases
public
http://localhost:8080/nexus/content/repositories/releases


nexus-snapshots
Snapshots
http://localhost:8080/nexus/content/repositories/snapshots


3.发布项目
进入项目目录执行mvn deploy结束后,构件就自动加入到服务器中,其他项目就可以进行关联引用。

参考:
Maven2部署构件到Nexus时出现的Failed to transfer file错误
Maven2中需要注意的问题
maven deploy到nexus私服出错问题

解决Spring Tool Suite和Maven2找不到JDK的问题

在运行Spring Tools Suite工具,创建Maven Project时,报eclipse找不到JDK环境,请配置Eclipse JDK环境。
打开E:\springsource\sts-2.3.0.RELEASE目录中的STS.ini文件,加入-vm参数,具体如下:
[color=Red][size=15]-vm
C:\Program Files\Java\jdk1.6.0_13\bin\javaw.exe[/size][/color]
-startup
plugins/org.eclipse.equinox.launcher_1.0.201.R35x_v20090715.jar
–launcher.library
plugins/org.eclipse.equinox.launcher.win32.win32.x86_1.0.200.v20090519
-product
com.springsource.sts.ide
–launcher.XXMaxPermSize
256M
-vmargs
-Dosgi.requiredJavaVersion=1.5
-Xms40m
-Xmx1G
-XX:MaxPermSize=256m

注:vm后面一定要加换行,也不知道是什么原因,不换行还是报错。

Maven2 常用命令

mvn archetype:create :创建 Maven 项目

mvn compile :编译源代码

mvn test-compile :编译测试代码

mvn test : 运行应用程序中的单元测试

mvn site : 生成项目相关信息的网站

mvn clean :清除目标目录中的生成结果

mvn package : 依据项目生成 jar 文件

mvn install :在本地 Repository 中安装 jar

mvn eclipse:eclipse :生成 Eclipse 项目文件

生成项目

建一个 JAVA 项目 : mvn archetype:create -DgroupId=com.demo -DartifactId=App

建一个 web 项目 : mvn archetype:create -DgroupId=com.demo -DartifactId=web-app -DarchetypeArtifactId=maven-archetype-webapp

生成 Eclipse 项目

普通 Eclipse 项目执行 : mvn eclipse:eclipse

Eclipse WTP 项目执行 : mvn eclipse:eclipse –Dwtpversion=1.0

( wtp1.0 以上版本均可用)

pom.xml 文件基本节点介绍

:文件的根节点 .
: pom.xml 使用的对象模型版本 .
:创建项目的组织或团体的唯一 Id.
:项目的唯一 Id, 可视为项目名 .

:打包物的扩展名,一般有 JAR,WAR,EAR 等
:产品的版本号 .
:项目的显示名,常用于 Maven 生成的文档。
:组织的站点,常用于 Maven 生成的文档。
:项目的描述,常用于 Maven 生成的文档。

在 POM 4 中, 中还引入了 ,它主要管理依赖的部署。

目前 可以使用 5 个值:

compile :缺省值,适用于所有阶段,会随着项目一起发布。

provided :类似 compile ,期望 JDK 、容器或使用者会提供这个依赖。如 servlet.jar 。

runtime :只在运行时使用,如 JDBC 驱动,适用运行和测试阶段。

test :只在测试时使用,用于编译和运行测试代码。不会随项目发布。

system :类似 provided ,需要显式提供包含依赖的 jar , Maven 不会在 Repository 中查找它。

定义自己的结构

新建一个 archetype 项目 :

mvn archetype:create\
-DgroupId=cn.prof\
-DartifactId=prof-archetype\
-DarchetypeArtifactId=maven-archetype-archetype

主要的模板文件 : archetype-resources/pom.xml

修改其中内容

修改 META-INF/maven/archetype.xml 中定义了相关的 sources

安装此项目 : mvn install

执行下面的命令创建新目录的项目:

mvn archetype:create -DgroupId=com.mergere.mvnbook \
-DartifactId=proficio-example\
-DarchetypeGroupId=com.xxx.mvn\
-DarchetypeArtifactId= prof-archetype \
-DarchetypeVersion=1.0-SNAPSHOT

收藏 悼念一个伟大的公司——Sun

     欧盟无条件批准 oracle公司对Sun收购案的消息,实际上宣告了一个伟大公司的离去。 Java之父James Gosling在自己的博客贴出了一幅画,应该代表了许多技术人的心情:

sun被收购,收购sun

     对了,他还写了一句话:So long, old friend…

     再见,Sun!

  这个曾经创造了众多神作的伟大公司。

  这个英雄辈出的伟大公司。

  这个多年前就提出过网络就是计算机宏大愿景的伟大公司。

  【在Sun公司工作的杰出科学家和工程师】

   Bill Joy(BSD和vi之父)

  Ivan Sutherland(图灵奖得主)

  Bryan Cantrill(DTrace之父)

  Steve Bourne(Bourne shell之父)

  Jeff Bonwick(ZFS之父)

  Joshua Bloch(Java教父)

  Guy L. Steele, Jr.(Scheme之父)

  James Duncan Davidson(Tomcat之父)

  Whitfield Diffie(公钥算法之父)

  Craig McClanahan(Struts之父)

  Ian Murdock(Debian之父)

  Jakob Nielsen(可用性权威)

  Radia Perlman(Internet之母)

  Marc Tremblay(UltraSPARC处理器)

  Marc Fleury(JBoss之父)

  Tim Bray(XML)

  Peter Norvig(google研发总监)

  John Ousterhout(Tcl之父)

  【在Sun公司工作过的杰出企业家】

  Eric Schmidt(google,lex)

  Andy Bechtolsheim(Sun创始人,Google的第一个投资者)

  庄思浩(BEA)

  Chris Malachowsky(NVIDIA)

Maven 2 JasperReports Plugin配置

在使用MAVEN来配置项目时,要用到JasperReports,可以在POM中加入链接。

POM dependencies片段:
  1. <dependency>  
  2.   <groupId>jasperreports</groupId>  
  3.   <artifactId>jasperreports</artifactId>  
  4.   <version>3.1.2</version>  
  5. </dependency>  

但是想在项目编译时,要将指定目录的*.jrxml进行编译的话需要加入Build插件。

POM build plugins片段:
  1. <plugin>  
  2.                 <groupId>org.codehaus.mojo</groupId>  
  3.                 <artifactId>jasperreports-maven-plugin</artifactId>  
  4.                 <executions>  
  5.                     <execution>  
  6.                         <goals>  
  7.                             <goal>compile-reports</goal>  
  8.                         </goals>  
  9.                     </execution>  
  10.                 </executions>  
  11.   
  12.                 <dependencies>  
  13.                     <!– 
  14.                         note this must be repeated here to pick up correct xml validation 
  15.                     –>  
  16.                     <dependency>  
  17.                         <groupId>jasperreports</groupId>  
  18.                         <artifactId>jasperreports</artifactId>  
  19.                         <version>3.1.2</version>  
  20.                     </dependency>  
  21.                 </dependencies>  
  22.   
  23.             </plugin>  

使用:mvn jasperreports:compile-reports -Ddetail=true

附上JasperReport Plugins的命令参数说明。

Optional Parameters

Name Type Since Description
additionalClasspath String - Any additional classpath entry you might want to add to the JasperReports compiler. Not recommended for general use, plugin dependencies should be used instead.
additionalProperties Map 1.0-beta-2 Additional JRProperties
classpathElements List - (no description)
compiler String - Uses the Javac compiler by default. This is different from the original JasperReports ant task, which uses the JDT compiler by default.
Default value is: net.sf.jasperreports.engine.design.JRJavacCompiler.
javaDirectory File - This is where the generated java sources are stored.
keepJava boolean - Deprecated. There seems to be an issue with the compiler plugin so don’t expect this to work yet – the dependencies will have disappeared.
Default value is: false.
keepSerializedObject boolean - Deprecated. Not implemented
Default value is: true.
outputDirectory File - This is where the .jasper files are written.
outputFileExt String - The extension of the compiled report files. Creates files with a .jasper extension by default.
Default value is: .jasper.
project MavenProject - (no description)
sourceDirectory File - This is where the xml report design files should be.
Default value is: src/main/jasperreports.
sourceFileExt String - The extension of the source files to look for. Finds files with a .jrxml extension by default.
Default value is: .jrxml.
xmlValidation boolean - Wether the xml design files must be validated.
Default value is: true.

FDT3.5正式版已经发布

今天下午还在用MyEclipse8中安装FDT 3.5 Beta2,晚上回家再重新安装时,发现FDT3.5已经releases.

 

With version 3.5 of FDT we are introducing great new features for both MXML and ActionScript editor. While we are focused on bringing you the best MXML editor for flex development at this time, we are continually improving FDT.

FDT 3.5  Presentation

The FDT 3.5 Update was recently released. Watch the new features of FDT 3.5 live in action! Michael Plank shows you what’s new in FDT 3.5 and how you can use the great features.

Features and Improvements of FDT 3.5

Full Autocompletion Support in MXML Editor

AS3 Autocompletion in CDATA, quotes and curly braces

Search in MXML Files

Wizard for creating Top Level Variables and Functions

New and improved Code Templates

Autocompletion for MXML Tags

Autocompletion for event types

Watch that feature in action

Improved Quick Outline

Autocompletion for constant convention

Watch that feature in action

Semantic Highlighting and Autocompletion for inline XML

Watch that feature in action

New Quick Fixes

Watch that feature in action

Brand new Debugger

Variable folding and XML Preview are the new features in the debugger


收藏-Flex Builder 3 on Eclipse 3.5

当我在机器上安装了flexbuilder3和STS(SpringSource Tool Suite )2.3后,将flexbuilder以插件的方式加入到STS,编译源文件和样式文件会出现编译出错,一开始是以为是上次编译产生的垃圾文件产生的问 题,采用项目文件清除后再编译,问题还是在。

ConfigurationProblem logging info

java.lang.IllegalArgumentException: "The attribute value type is com.adobe.flexbuilder.project.compiler.internal.ProblemManager and expected is one of java.lang.String, Boolean, Integer"
at org.eclipse.core.internal.resources.MarkerInfo.checkValidAttribute(MarkerInfo.java:84)
at org.eclipse.core.internal.resources.MarkerInfo.setAttributes(MarkerInfo.java:172)
at org.eclipse.core.internal.resources.Marker.setAttributes(Marker.java:304)
at com.adobe.flexbuilder.project.compiler.internal.ProblemManager.createMarker(Unknown Source)
at com.adobe.flexbuilder.project.compiler.internal.ProblemManager.createMarker(Unknown Source)
at com.adobe.flexbuilder.project.compiler.internal.ProblemManager.logProblem(Unknown Source)
at com.adobe.flexbuilder.project.compiler.internal.ProblemManager.logInternalProblem(Unknown Source)
at com.adobe.flexbuilder.project.compiler.internal.FlexProjectBuilder.buildItem(Unknown Source)
at com.adobe.flexbuilder.project.compiler.internal.FlexProjectBuilder.build(Unknown Source)
at com.adobe.flexbuilder.project.compiler.internal.FlexIncrementalBuilder.build(Unknown Source)
at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:627)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:170)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:201)
at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:253)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:256)
at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:309)
at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:341)
at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:140)
at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:238)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

后来在网上找到是因为flexbuilder3采用eclipse3.3作为平台开发,而我是用eclipse3.5,需要做如下修改:

 

  1. 下载包 ProblemManager patch
  2. 解压下载的文件
  3. 到 Flex Builder安装目录
  4. 用winrar打开/eclipse/plugins/com.adobe.flexbuilder.project_3.0.204732/zornproject.jar文件
  5. 将刚才下载解压的文件目录 com拖到winrar中完成压缩
  6. 启动STS
  7. 成功编译项目

 英文网址:http://www.jamesward.com/2009/09/29/flex-builder-3-on-eclipse-3-5/?utm_campaign=BackType&utm_medium=bt.io-twitter&utm_source=&utm_content=backtype-tweetcount

 

收藏Flexmojos Adding libraries to compilation

When developing with flex, it is very common to need 3rd party libraries to build more elaborate applications. For example: if an application uses charts, the project will require datavisualization.swc.  If an application needs an SHA1 algorithm, it will require as3corelib, and so on.

Using adobe’s command line compilers (mxmlc and compc) you will use parameters from this list:
-compiler.external-library-path
-compiler.include-libraries
-compiler.library-path
-runtime-shared-library-path

But on flex-mojos those options are not available. If there is no option available, how does one add these libraries?

Simple, following maven way =D

Each required library must be added as a dependency. If you need datavisualization you will add a dependency like this:

<dependency>
  <groupId>com.adobe.flex.sdk</groupId>
  <artifactId>datavisualization</artifactId>
  <version>3.0.0.477</version>
  <type>swc</type>
</dependency>

One big question: How do you discover the dependency’s groupId and artifactId?
As with any module in maven, those who created the module must define their groupId and artifactId. Since flex is not very popular with the maven world, it most likely will not be available in any maven repository. If this is the case, you will define your own groupId/artifactId and install on your own repository.

Maven Guide to installing 3rd party JARs

Often times you will have 3rd party JARs that you need to put in your local repository for use in your builds. The JARs must be placed in the local repository in the correct place in order for it to be correctly picked up by Maven. To make this easier, and then error prone, we have provide a goal in the install plug-in which should make this relatively painless. To install a JAR in the local repository use the following command:
mvn install:install-file -Dfile= -DgroupId= -DartifactId= -Dversion= -Dpackaging=

You can follow the same logic for swc libraries.

Example for installing the Data Visualization swc’s into Maven.

Download data visualization swc’s from here, you need to install them into your maven repo as follows:

  • extract the zip file and cd to the datavisualization_sdk3.3/frameworks/libs and issue the mvn install command.
    mvn install:install-file -DgroupId=com.adobe.flex.framework -DartifactId=datavisualization -Dversion=3.3.0.4852 -Dpackaging=swc -Dfile=datavisualization.swc
    

  • do the same for /frameworks/locale/en_US and run the following commands:
    mvn install:install-file -DgroupId=com.adobe.flex.framework -DartifactId=datavisualization -Dversion=3.3.0.4852 -Dclassifier=en_US -Dpackaging=rb.swc -Dfile=datavisualization_rb.swc
    

You will need the matching dependencies in your pom:

<dependency>
   <groupId>com.adobe.flex.framework</groupId>
   <artifactId>datavisualization</artifactId>
   <version>3.3.0.4852</version>
   <type>swc</type>
 </dependency>
 <dependency>
   <groupId>com.adobe.flex.framework</groupId>
   <artifactId>datavisualization</artifactId>
   <classifier>en_US</classifier>
   <version>3.3.0.4852</version>
   <type>rb.swc</type>
 </dependency>

 

How do you define how the dependency should be used? If it should be external, how do you get it?
Defining dependency scope:

<dependency>
  <groupId>com.adobe.flex.sdk</groupId>
  <artifactId>datavisualization</artifactId>
  <version>3.0.0.477</version>
  <type>swc</type>
  <scope>external</scope>
</dependency>

Flex-mojos supports 6 scopes:

  • merged: this is the default value, when not defined will assume merged. That means SWC/SWF file will be bigger and self sufficient. Same as -compiler.library-path
  • internal: all dependency content will be included on target SWC/SWF. Biggest compiled file. Same as -compiler.include-libraries
  • external: no dependency content will be included on target SWC/SWF. Smaller compiled file. Makes no sense to use this scope on SWF compilation. Same as -compiler.external-library-path
  • rsl: no dependency content will be inclued on SWC/SWF. But, SWF will have a reference to load it a runtime. Do not use on SWC compilation. Same as -runtime-shared-library-path
  • caching: same as RSL, but uses adobe signed SWZ files.
  • test: libraries required to run tests. Same as -compiler.include-libraries, but at test template only!

Ubuntu下搭建Java开发环境

http://www.javaeye.com/topic/158133

安装与设置JDK

Sun JDK的安装基本上有两种方式:

    1. 通过Ubuntu提供的包管理工具进行安装

      Ubuntu在其包仓库里都包括有JDK的安装,只要sources.list设置正确,通过apt-get, aptitude, Synaptic Package Manager等都能安装,而且相关的设置也容易得多;在Ubuntu的新  发布版本里都带了JDK5.0,和JDK6.0的安装支持,而且版本都比较高,和Sun官方的发布没有很大的 版本落差.以Ubuntu7.10来说,提供的JDK5的版本为:1.5.0.13,JDK6的版本是1.6.03,算是很新的版本了.

这种安装方式缺点是:对JDK具体版本的可选择性不是很灵活,你若是想安装最新的JDK版本,或由于特殊的原因必须安装特定的JDK版本,可能就比较费劲了。

     所以,若以此种方式安装JDK,请先通过apt-cache search, aptitude, Synaptic Package Manager等工具查询你的Ubuntu发行版本可安装的JDK版本是否能符合你的开发要求;具体安装 步骤请看参阅部分提供的文档。
 
  2. 通过Sun网站提供的自解压包进行手动的安装
  
       这种方式显然有它的好处: 可自由选择JDK版本,能进行灵活的配置。其实JDK的配置是很简单的:能让系统找到JDK所在的目录(JAVA_HOME),以便调用其目录中bin目录下的相关命令脚本。

      在此以Ubuntu7.10系统,Sun JDK 6.0 update 4为例说明一下具体的安装方式:

     2.1.  从Sun站点下载jdk 6.0.4的Linux自解压文件 jdk-6u4-linux-i586.bin;

      2.2. 安装配置

          cd /usr/local/lib
           sudo cp /home/jdk-6u4-linux-i586.bin ./
           sudo chmod +x jdk-6u4-linux-i586.bin
           sudo ./jdk-6u4-linux-i586.bin

           执行最后一步命令后便在当前目录下多了一个“jdk1.6.0_04“的目录,里面是jdk-6u4-linux-i586.bin解压后JDK的全部文件;
            由于Ununtu本身带了gij的JVM实现,所以当你在Terminal输入:  "java -version"时会显示:
           java version "1.5.0"
           gij (GNU libgcj) version 4.2.1 (Ubuntu 4.2.1-5ubuntu5)

           的相关信息。也就是系统中有两个JVM实现,而且gij JVM还被其它的Ubuntu工具或软件使用;所以这种情况下就得使用 Debian提供的“update-alternatives“工具来完成程序多版本实现的选择了:
           sudo update-alternatives –display java
          发现系统只列举了gij  JVM;因为jdk6是通过手动解压安装的。
          现在输入下面的两行命令:
           sudo update-alternatives –install /usr/bin/java java /usr/local/lib/jdk1.6.0_04/bin/java 60
          sudo  update-alternatives –install /usr/bin/java java /usr/bin/gij-4.2 40

          注意1,2行尾的60,40是优先级;现在把JDK6设为了首选;
          输入: ls -l /etc/alternatives/java 发现JVM已经指向了jdk6的解压目录:
         lrwxrwxrwx 1 root root 35 2008-01-25 17:55 /etc/alternatives/java -> /usr/local/lib/jdk1.6.0_04/bin/java
         
         cd /usr/bin
         sudo cp java java.bak
          sudo ln -sf /etc/alternatives/java .

    
          现在再执行:
          java -version

           java version "1.6.0_04"
          Java(TM) SE Runtime Environment (build 1.6.0_04-b12)
          Java HotSpot(TM) Client VM (build 10.0-b19, mixed mode, sharing)

           若想变更JVM实现,输入:
            sudo update-alternatives –config java
           进行配置;
       
      2. 3. 设置环境变量

          在/etc/profile中加入如下的内容:
         
          JAVA_HOME=/usr/local/lib/jdk1.6.0_04
          JRE_HOME=/usr/local/lib/jdk1.6.0_04/jre
          CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
          export JAVA_HOME JRE_HOME CLASSPATH
         

      okey, JDK安装配置完成。

安装与配置IDE

  1. Eclipse的安装与配置

   1.1 从eclise.org下载Eclipse开发平台
         如类似以下的文件:eclipse-java-europa-fall2-linux-gtk.tar.gz.

    1.2 解压文件
         sudo mkdir /usr/local/dev
         sudo mkdir /usr/src/dev
         sudo cp eclipse-java-europa-fall2-linux-gtk.tar.gz /usr/src/dev/
         cd /usr/src/dev
         tar zxvf eclipse-java-europa-fall2-linux-gtk.tar.gz  -C /usr/local/dev

    1.3 建立一个Eclipse可执行文件
          sudo touch /usr/bin/eclipse
          sudo chmod 755 /usr/bin/eclipse
          sudoedit /usr/bin/eclipse

          内容如下:
         #!/bin/sh
          export ECLIPSE_HOME="/usr/local/dev/eclipse"
          $ECLIPSE_HOME/eclipse $*

          现在打开Terminal,执行"eclipse"应该能打开Eclipse了。

    1.4 添加Eclipse到Gnome菜单中
         sudoedit /usr/share/applications/eclipse.desktop
         内容如下:
         [Desktop Entry]
         Encoding=UTF-8
         Name=Eclipse
         Comment=Eclipse IDE
         Exec=eclipse
         Icon=/usr/local/dev/eclipse/icon.xpm
         Terminal=false
         Type=Application
         Categories=GNOME;Application;Development;
         StartupNotify=true

  2. Netbeans的安装与配置   

2.1 从netbeans.org下载Netbeans开发平台
         如类似以下的文件: netbeans-6.0-javase-linux.sh.

    2.2 安装文件
         sudo cp netbeans-6.0-javase-linux.sh /usr/src/dev/
         cd /usr/src/dev
         sudo chmod 755 netbeans-6.0-javase-linux.sh
         sudo ./netbeans-6.0-javase-linux.sh

         执行最后一步后,出现安装界面,选择安装目录和JDK的位置,确定后完成安装,在当前目录生成了“netbeans-6.0"目录,里面是Netbeans的内容。

    2.3 建立一个Netbeans可执行文件
          sudo touch /usr/local/bin/netbeans
          sudo chmod 755 /usr/local/bin/netbeans
          sudoedit /usr/local/bin/netbeans

          内容如下:
         #!/bin/sh
          #!/bin/sh
          export NETNEANS_PATH="/usr/local/dev/netbeans-6.0/bin"
          $NETNEANS_PATH/netbeans $*

    2.4 添加Netbeans到Gnome菜单中
         sudoedit /usr/share/applications/netbeans.desktop
         内容如下:
         [Desktop Entry]
         Encoding=UTF-8
         Name=NetBeans6.0
         Comment=Sun Netbeans IDE
         Exec=netbeans
         Icon=/usr/local/dev/netbeans-6.0/nb6.0/netbeans.png
         Terminal=false
         Type=Application
         Categories=GNOME;Application;Development;
         StartupNotify=true
 
  
  3. IntelliJ Idea的安装与配置 

   3.1 从jetbrains.com下载IntelliJ开发平台
         如类似以下的文件:idea-7.0.2.tar.gz.

    3.2 解压文件
          sudo cp idea-7.0.2.tar.gz  /usr/src/dev/
         cd /usr/src/dev
         sudo tar zxvf idea-7.0.2.tar.gz   -C  /usr/local/dev
         sudo mv idea-7590 idea

    3.3 更改/etc/profile
        IntelliJ Idea启动将JAVA_HOME命名为"IDEA_JDK"  或"JDK_HOME",所以需在/etc/profile中添加JDK_HOME设置,更改后的/etc/profile为:
         
          JAVA_HOME=/usr/local/lib/jdk1.6.0_04
          JDK_HOME=/usr/local/lib/jdk1.6.0_04
          JRE_HOME=/usr/local/lib/jdk1.6.0_04/jre
          CLASSPATH=.:$JAVA_HOME/lib:$JRE_HOME/lib
          export JAVA_HOME JDK_HOME JRE_HOME CLASSPATH
         
      
         之后重启系统;

    3.4 建立一个Idea可执行文件
          sudo touch /usr/bin/idea
          sudo chmod 755  /usr/local/bin/idea
          sudoedit  /usr/local/bin/idea

          内容如下:
         #!/bin/sh
         export IDEA_PATH="/usr/local/dev/idea/bin"
         $IDEA_PATH/idea.sh$*

    3.5 添加IntelliJ Idea到Gnome菜单中
         sudoedit /usr/share/applications/eclipse.desktop
         内容如下:
         [Desktop Entry]
         Encoding=UTF-8
         Name=Idea
         Comment=IntelliJ Idea 7
         Exec=idea
         Icon=/usr/local/dev/idea/bin/idea32.png
         Terminal=false
         Type=Application
         Categories=GNOME;Application;Development;
         StartupNotify=true

  4. Emacs下的配置 
           请参考我写的另一篇文章: Emacs下配置Java开发环境

    参阅资料:

    1.  到Sun java站点下载JDK实现。

    2. 请参考Ubuntu Java文档中通过包管理工具的实现。

    3. serios.net中有关于Debian, Ubuntu下安装配置JRE,JDK的精彩说明。

   4. 参考How to Install Sun Java on Debian的另外一种安装方式。

   5. 参考update-alternatives的文档,看相关命令的操作。

   6. 到Eclipse站点下载Eclipse IDE for Java Developers.

   7. 看Ivar Abrahamsen关于Ubuntu下配置Elipse的精彩说明.

   8. 到Netbeans站点下载Netbeans IDE.

   9. 到Jetbrains站点下载IntelliJ IDEA.

ubuntu环境下安装tomcat6

If you are running Ubuntu and want to use the Tomcat servlet container, you should not use the version from the repositories as it just doesn’t work correctly. Instead you’ll need to use the manual installation process that I’m outlining here.

Before you install Tomcat you’ll want to make sure that you’ve installed Java. I would assume if you are trying to install Tomcat you’ve already installed java, but if you aren’t sure you can check with the dpkg command like so:

dpkg –get-selections | grep sun-java

This should give you this output if you already installed java:

sun-java6-bin install
sun-java6-jdk install
sun-java6-jre install

If that command has no results, you’ll want to install the latest version with this command:

sudo apt-get install sun-java6-jdk

Installation

Now we’ll download and extract Tomcat from the apache site. You should check to make sure there’s not another version and adjust accordingly.

wget http://labs.xiaonei.com/apache-mirror/tomcat/tomcat-6/v6.0.20/bin/apache-tomcat-6.0.20.tar.gz

tar xvzf apache-tomcat-6.0.20.tar.gz

The best thing to do is move the tomcat folder to a permanent location. I chose /usr/local/tomcat, but you could move it somewhere else if you wanted to.

sudo mv apache-tomcat-6.0.20 /usr/local/tomcat

Tomcat requires setting the JAVA_HOME variable. The best way to do this is to set it in your .bashrc file. You could also edit your startup.sh file if you so chose.

The better method is editing your .bashrc file and adding the bolded line there. You’ll have to logout of the shell for the change to take effect.

vi ~/.bashrc

Add the following line:

export JAVA_HOME=/usr/lib/jvm/java-6-sun

At this point you can start tomcat by just executing the startup.sh script in the tomcat/bin folder.

Automatic Starting

To make tomcat automatically start when we boot up the computer, you can add a script to make it auto-start and shutdown.

sudo vi /etc/init.d/tomcat

Now paste in the following:

# Tomcat auto-start
#
# description: Auto-starts tomcat
# processname: tomcat
# pidfile: /var/run/tomcat.pid

export JAVA_HOME=/usr/lib/jvm/java-6-sun

case $1 in
start)
        sh /usr/local/tomcat/bin/startup.sh
        ;;
stop)  
        sh /usr/local/tomcat/bin/shutdown.sh
        ;;
restart)
        sh /usr/local/tomcat/bin/shutdown.sh
        sh /usr/local/tomcat/bin/startup.sh
        ;;
esac   
exit 0

You’ll need to make the script executable by running the chmod command:

sudo chmod 755 /etc/init.d/tomcat

The last step is actually linking this script to the startup folders with a symbolic link. Execute these two commands and we should be on our way.

sudo ln -s /etc/init.d/tomcat /etc/rc1.d/K99tomcat
sudo ln -s /etc/init.d/tomcat /etc/rc2.d/S99tomcat

Tomcat should now be fully installed and operational. Enjoy!

lastend,start tomcat server by this command:

/etc/init.d/tomcat start

/etc/init.d/tomcat stop

/etc/init.d/tomcat restart

loading Flex Modules dynamically

收藏自:lowpitch.com/blog

When you’re working with flex Modules, most of the time the ModuleLoader component will be enough to get you up and running. It will quickly and easily let you load your Modules and add them to the display list, it’ll even dispatch an event to let you know when the Module is ready. Lovely stuff. It’s very similar to the SWFLoader component with some added Module-related goodness thrown in.

However, there may be times when the ModuleLoader component may not be appropriate for your needs, and you’ll have to get your hands dirty and get involved with the lower-level ModuleManager class. Some examples of when ModuleLoader might not be suitable include:

  • Your Module is entirely non-visual, and therefore shouldn’t be added to the display list
  • Performance is really important to your application, and the extra overhead of the ModuleLoader container is something you need to remove to try and speed things up. (ModuleLoader essentially wraps your Module’s content in an extra container, incurring a slight performance hit).
  • You need greater control over how and when your modules are loaded and unloaded.

How does ModuleManager work?

ModuleManager maintains a map of modules, indexed by each module’s URL. Information about the module is stored as an object implementing IModuleInfo, and is retrieved by calling the ModuleManager.getModule method, passing in the module’s URL as the method’s only parameter. Once you’ve retrieved the IModuleInfo object, you can call its load method to starting loading in the module. While the module is loading, you can monitor the load progress using a variety of different events (of type ModuleEvent). Finally, when the module is loaded and available, you can create an instance of that module using someModuleInfo.factory.create ().

 

IModuleInfo in more detail

As mentioned above, ModuleManager maintains a mapping of URLs to modules. When you call ModuleManager’s static getModule method, it returns an object of type IModuleInfo. If you dig around within the ModuleManager class, you’ll see that this interface is implemented internally. It’s useful to know a little bit more about how you can interact with the ModuleInfo, what methods it exposes, and what events it dispatches.

There are four read-only public Boolean properties which offer information about the current state of the module. They can briefly be described:

  • IModuleInfo.error – This’ll be true if there was an error during loaded. You’re also notified of such an error by the ModuleEvent.ERROR event.
  • IModuleInfo.loaded – This will be true if you’ve previously called the IModuleInfo.load method. Note: It does not necessarily signify that the module has been loaded, just that the module load has begun.
  • IModuleInfo.setup – When enough of the module has loaded to be able to call the factory.info () method, this flag will be true. When this point in the load has been reached, a ModuleEvent.SETUP event will be dispatched.
  • IModuleInfo.ready – When enough of the module has been loaded for you to be able to instantiate an instance of the module using the factory.create () method, this flag will be true. At this stage, a ModuleEvent.READY event will be dispatched. This property will typically become true at some point after the IModuleInfo.setup becomes true.

There are some additional properties which can also be useful:

  • IModuleInfo.url fairly obviously returns the URL associated with the IModuleInfo object. This could be useful if you’re using one event handler to listen out for the events from multiple modules – the event.currentTarget.url property could be used to identify which module had sent out the event.
  • IModuleInfo.data is an object which you can use to associate data with a particular module. The data will be shared across all instances of a particular module, so this property comes in handy if you want to share state, or user information between multiple instances of the same dynamically loaded module.
  • IModuleInfo.factory is pretty important. Once the the module is ‘ready’ (after the ModuleEvent.READY event has been dispatched, or when IModuleInfo.ready returns true), you can create an instance of your module by calling the IflexModuleFactory.create method. Additionally, once the module has been ’setup’ (after ModuleEvent.SETUP has fired, or when IModuleInfo.setup returns true), you can query the IFlexModuleFactory.info method to find out a little more about the module that has been loaded.

Next we should look at some of the methods exposed by an IModuleInfo:

  • IModuleInfo.load – This is the method you’ll call to start loading a module. You can optionally pass in information about the current ApplicationDomain and SecurityDomain if necessary. When the module is loading, events will be dispatched along the way as detailed below. Quite a nice feature here is that if the module has already been loaded, and you attempt to reload it, it’ll still dispatch the “setup” and “ready” events, meaning that you can use one set of event listener methods without needing to worry about whether the module is loading for the first time, or if it already exists in local memory. Snazzy…
  • IModuleInfo.release – This method will release the current reference to the module. Internally, when this method is called, a reference counter will be decremented. If no references to the module exist after this method has been called, it will automatically be unloaded.
  • IModuleInfo.unload – This triggers the unload of the module. It’s worth noting that if any references to the module exist, it will not be garbage collected. Also, calling this method won’t remove your module from the display list, you’ll have to do that too.

Lastly, let’s look at the events dispatched… All the events listed here are instances of ModuleEvent, and for some of the events you’ll be able to access information about the load progress through the event’s bytesLoaded and bytesTotal properties.

  • ModuleEvent.ERROR – Rather obviously, this is dispatched when an error occurs during loading. This will also be indicated by the IModuleInfo.error property returning true.
  • ModuleEvent.PROGRESS – This event is dispatched periodically during the load, giving you the chance to display a visual indication of load progress if you want. This is one of the events where the bytesLoaded and bytesTotal properties will be set.
  • ModuleEvent.SETUP – This event is dispatched when enough of the module has downloaded for you to call the IModuleInfo.factory.info method. At this point, IModuleInfo.setup will also return true. This event does not allow you to access load progress through the bytesLoaded and bytesTotal properties.
  • ModuleEvent.READY – This event is dispatched when enough of the module has downloaded for you to create an instance of the module through the IModuleInfo.factory.create method. From then on, IModuleInfo.ready will also return true. Apparently, this event is one where the bytesLoaded and bytesTotal properties should be set, although I’ve noticed that this isn’t always the case. I reckon it’s safer just to use the ModuleEvent.PROGRESS information for displaying progress information.
  • ModuleEvent.UNLOAD – This event is dispatched when the module has been unloaded. No progress information is available through the event object with this event.

A simple example

First, a basic module, SimpleModule, which does nothing more than display a label within a panel.

SimpleModule.mxml
XML/HTML代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <mx:Module xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">  
  3.     <mx:TitleWindow x="10" y="10" width="120" height="100" layout="absolute">  
  4.         <mx:Text text="SimpleModule!" />  
  5.     </mx:TitleWindow>  
  6. </mx:Module>  

The the main application, which will load in this module and attach instances to a Tile control.

Shell.mxml

XML/HTML代码
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  
  3.     applicationComplete="initApp()">  
  4.     <mx:Script>  
  5.         <![CDATA[ 
  6.             import mx.modules.Module; 
  7.             import mx.events.ModuleEvent; 
  8.             import mx.modules.ModuleManager; 
  9.             import mx.modules.IModuleInfo; 
  10.   
  11.           protected var _moduleInfo:IModuleInfo; 
  12.              
  13.             private function initApp():void { 
  14.                addToLog ("Application initialised"); 
  15.                // create the module - note, we're not loading it yet 
  16.                 _moduleInfo = ModuleManager.getModule("SimpleModule.swf"); 
  17.                // add some listeners 
  18.                _moduleInfo.addEventListener(ModuleEvent.READY, onModuleReady); 
  19.                _moduleInfo.addEventListener(ModuleEvent.SETUP, onModuleSetup); 
  20.                _moduleInfo.addEventListener(ModuleEvent.UNLOAD, onModuleUnload); 
  21.                _moduleInfo.addEventListener(ModuleEvent.PROGRESS, onModuleProgress); 
  22.             } 
  23.             
  24.             protected function getModuleInfo () : IModuleInfo { 
  25.                // return the module info 
  26.                return _moduleInfo; 
  27.             } 
  28.             
  29.             /** 
  30.              * Adds output to the log 
  31.              **/ 
  32.             protected function addToLog (msg:String) : void { 
  33.                 log.text += msg + "\n"; 
  34.                 // scroll to the bottom on the next frame 
  35.                 callLater(scrollToBottom); 
  36.                 
  37.             } 
  38.             
  39.             protected function scrollToBottom () : void { 
  40.                 // scroll to the bottom 
  41.                 log.verticalScrollPosition = log.maxVerticalScrollPosition; 
  42.             } 
  43.             
  44.             /** 
  45.             * Called when the "load" button is pressed 
  46.             * 
  47.             * Starts loading the module - when the module has been 
  48.             * loaded, an instance of the module will be created 
  49.             * and added to the tile control 
  50.             * 
  51.             **/ 
  52.             private function loadModule () : void { 
  53.                 addToLog ("Loading module"); 
  54.                 // load the module 
  55.                 getModuleInfo().load(); 
  56.             } 
  57.     
  58.             /** 
  59.              * Called when the "unload" button is pressed 
  60.              * 
  61.              * Removes all the instances of the module from the 
  62.              * tile control, then unloads the module 
  63.              * 
  64.              */ 
  65.             private function unloadModule () : void { 
  66.                 addToLog ("Unloading module"); 
  67.                 // clear out all the the instances 
  68.                 // of the module from the tile 
  69.                 tile.removeAllChildren(); 
  70.                 // unload the module 
  71.                 getModuleInfo().release(); 
  72.                 //getModuleInfo().un 
  73.             } 
  74.              
  75.             /** 
  76.             * Handler for the ModuleEvent.PROGRESS event 
  77.             **/ 
  78.             protected function onModuleProgress (e:ModuleEvent) : void { 
  79.                 addToLog ("ModuleEvent.PROGRESS received: " + e.bytesLoaded + " of " + e.bytesTotal + " loaded."); 
  80.             } 
  81.              
  82.             /** 
  83.             * Handler for the ModuleEvent.SETUP event 
  84.             **/ 
  85.             private function onModuleSetup (e:ModuleEvent) : void { 
  86.                 addToLog ("ModuleEvent.SETUP received"); 
  87.                 // cast the currentTarget 
  88.                 var moduleInfo:IModuleInfo = e.currentTarget as IModuleInfo; 
  89.                 addToLog ("Calling IModuleInfo.factory.info ()"); 
  90.                 // grab the info and display information about it 
  91.                 var info:Object = moduleInfo.factory.info(); 
  92.                 for (var each:String in info) { 
  93.                     addToLog ("     " + each + " = " + info[each]); 
  94.                 } 
  95.                 
  96.             } 
  97.              
  98.             /** 
  99.             * Handler for the ModuleEvent.READY event 
  100.             **/ 
  101.             private function onModuleReady (e:ModuleEvent):void { 
  102.                 addToLog ("ModuleEvent.READY received"); 
  103.                 // cast the currentTarget 
  104.                 var moduleInfo:IModuleInfo = e.currentTarget as IModuleInfo; 
  105.                 // Add an instance of the module’s class to the 
  106.                 // display list. 
  107.                 addToLog ("Calling IModuleInfo.factory.create ()"); 
  108.                 tile.addChild( moduleInfo.factory.create () as SomeModule); 
  109.                 addToLog ("SomeModule instance created and added to Display List"); 
  110.             } 
  111.              
  112.             /** 
  113.             * Handler for the ModuleEvent.UNLOAD event 
  114.             **/ 
  115.             public function onModuleUnload (e:ModuleEvent) : void { 
  116.                 addToLog ("ModuleEvent.UNLOAD received"); 
  117.             } 
  118.              
  119.         ]]>  
  120.     </mx:Script>  
  121.      
  122.     <mx:HBox width="100%" height="100%">  
  123.         <mx:Tile id="tile" width="100%" height="100%" />  
  124.            <mx:TextArea id="log" width="100%" height="100%"/>  
  125.     </mx:HBox>  
  126.      
  127.      
  128.     <mx:ApplicationControlBar>  
  129.         <mx:Button label="Load" click="loadModule ()" />  
  130.         <mx:Button label="Unload" click="unloadModule ()"/>  
  131.     </mx:ApplicationControlBar>  
  132.      
  133. </mx:Application>  

What’s going on here? Well… when the app is created, initApp is called and the IModuleInfo object is created, and various event listeners are setup. When the user clicks the load button, the module is loaded. It doesn’t matter whether this is the first time the module is loaded, or if the module is already loaded and ready, the ModuleEvent.READY event will be dispatched to let us know that the module is ready, and that we can now create an instance of it. Within the handler for the ModuleEvent.READY event, we call IModuleInfo.factory.create () and add the instance of the module to our Tile control.

When the user clicks the unload button, all instances of the Module that we’ve added to the Tile control are removed, and we call IModuleInfo.unload to unload the module. A log message from within the handler for ModuleEvent.UNLOAD demonstrates that this is happening.

Additionally, within the event handler for ModuleEvent.SETUP we show an example of the IModuleInfo.factory.info method – this’ll give you an example of the kind of information you can retrieve about the module, and from looking at the log messages you’ll be able to see the order in which these events are dispatched.

Lastly, here’s the finished example:

 (Update: I’ve explained the IFlexModuleFactory class in a little more detail here.)

myeclipse 7.5 keygen 源代码

转自http://blog.csdn.net/shadowkiss/archive/2009/07/30/4393610.aspx

 

Java代码
  1. import java.text.DecimalFormat;  
  2. import java.text.NumberFormat;  
  3. import java.text.SimpleDateFormat;  
  4. import java.util.Calendar;  
  5.   
  6. /** 
  7.  * myeclipse blue 7.5 keygen 
  8.  *  
  9.  * @author bona shen 
  10.  *  
  11.  */  
  12. public class Crack {  
  13.     public static final void main(String[] args) {  
  14.         String id = "bona"// 可更给为您的名字  
  15.         String num = "999";// 许可证数量  
  16.         System.out.println(getSerial(id, "100", num, false));  
  17.     }  
  18.   
  19.     public static String getSerial(String userId, String version,  
  20.             String licenseNum, boolean selected) {  
  21.         Calendar cal = Calendar.getInstance();  
  22.         cal.add(110);  
  23.         cal.add(6, -1);  
  24.         NumberFormat nf = new DecimalFormat("000");  
  25.         licenseNum = nf.format(Integer.valueOf(licenseNum));  
  26.         String verTime = selected ? (new StringBuffer("-")).append(  
  27.                 (new SimpleDateFormat("yyMMdd")).format(cal.getTime())).append(  
  28.                 "0").toString() : "-1012310";  
  29.         String type = "YE3MB-";  
  30.         String need = (new StringBuffer(String.valueOf(userId.substring(01))))  
  31.                 .append(type).append(version).append(licenseNum)  
  32.                 .append(verTime).toString();  
  33.         String dx = (new StringBuffer(String.valueOf(need)))  
  34.                 .append(  
  35.                         "Decompiling this copyrighted software is a violation of both your license agreement and the Digital Millenium Copyright Act of 1998 (http://www.loc.gov/copyright/legislation/dmca.pdf). Under section 1204 of the DMCA, penalties range up to a $500,000 fine or up to five years imprisonment for a first offense. Think about it; pay for a license, avoid prosecution, and feel better about yourself.")  
  36.                 .append(userId).toString();  
  37.         int suf = decode(dx);  
  38.         String code = (new StringBuffer(String.valueOf(need))).append(  
  39.                 String.valueOf(suf)).toString();  
  40.         return change(code);  
  41.     }  
  42.   
  43.     private static int decode(String s) {  
  44.         int i = 0;  
  45.         char ac[] = s.toCharArray();  
  46.         int j = 0;  
  47.         for (int k = ac.length; j < k; j++)  
  48.             i = 31 * i + ac[j];  
  49.         return Math.abs(i);  
  50.     }  
  51.   
  52.     private static String change(String s) {  
  53.         byte abyte0[] = s.getBytes();  
  54.         char ac[] = new char[s.length()];  
  55.         int i = 0;  
  56.         for (int k = abyte0.length; i < k; i++) {  
  57.             int j = abyte0[i];  
  58.             if (j >= 48 && j <= 57)  
  59.                 j = ((j - 48) + 5) % 10 + 48;  
  60.             else if (j >= 65 && j <= 90)  
  61.                 j = ((j - 65) + 13) % 26 + 65;  
  62.             else if (j >= 97 && j <= 122)  
  63.                 j = ((j - 97) + 13) % 26 + 97;  
  64.             ac[i] = (char) j;  
  65.         }  
  66.         return String.valueOf(ac);  
  67.     }  
  68. }  

运行就产生序列号。

如果不想动手可以用这个。

Subscriber: bona

Subscription:oLR8ZO-655444-65678656903184204

Subscription Detail:

Subscriber: bona
Product ID: E3MB (MyEclipse Blue Subscription)
License version: 1.0
Full Maintenance Included
Subscription expiration date (YYYYMMDD): 20101231
Number of licenses: 999

自定义 Tree Data descriptor

在做开源供应链管理系统的时候,会用到很多树形的描述,需要用到mx.controls.Tree来展现,而数据库表定义时,表内有相关联如下:

SQL代码

create table "materialStock"."dbo"."MaterialType"(
"autoId" _autoId not null,
"parentId" _autoId null,
"unit" _unit(20) null,
"name" _name(20) null,
constraint "XPKMaterialType" primary key ("autoId")
)
go

alter table "materialStock"."dbo"."MaterialType"
add constraint "R_6"
foreign key ("parentId")
references "materialStock"."dbo"."MaterialType"("autoId")
go
create unique index "XPKMaterialType" on "materialStock"."dbo"."MaterialType"("autoId")
go

通过JPA就自动生成如下JAVA代码:
Java代码

package com.csgjs.mm.model.domain;

import …

/**
* AbstractMaterialType entity provides the base persistence definition of the
* MaterialType entity.
*
* @author MyEclipse Persistence Tools
*/
@MappedSuperclass
public abstract class AbstractMaterialType implements java.io.Serializable {

// Fields

private Integer autoId;
private MaterialType materialType;
private String unit;
private String name;
private Set<MaterialType> materialTypes = new HashSet<MaterialType>(0);

// Constructors

…

public void setMaterialType(MaterialType materialType) {
this.materialType = materialType;
}

…

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "materialType")
public Set<MaterialCatalog> getMaterialCatalogs() {
return this.materialCatalogs;
}

@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "materialType")
public Set<MaterialType> getMaterialTypes() {
return this.materialTypes;
}

public void setMaterialTypes(Set<MaterialType> materialTypes) {
this.materialTypes = materialTypes;
}

}

再由granite data service自动生成如下AS3类:

ActionScript代码

public class AbstractMaterialTypeBase implements IExternalizable {

private var __initialized:Boolean = true;
private var __detachedState:String = null;

private var _autoId:Number;
private var _materialType:MaterialType;
private var _materialTypes:ListCollectionView;
private var _name:String;
private var _unit:String;

meta function isInitialized(name:String = null):Boolean {
if (!name)
return __initialized;

var property:* = this[name];
return (
(!(property is AbstractMaterialType) || (property as AbstractMaterialType).meta::isInitialized()) &&
(!(property is IPersistentCollection) || (property as IPersistentCollection).isInitialized())
);
}

public function set autoId(value:Number):void {
_autoId = value;
}
public function get autoId():Number {
return _autoId;
}

public function set materialType(value:MaterialType):void {
_materialType = value;
}
public function get materialType():MaterialType {
return _materialType;
}

public function set materialTypes(value:ListCollectionView):void {
_materialTypes = value;
}
public function get materialTypes():ListCollectionView {
return _materialTypes;
}

public function set name(value:String):void {
_name = value;
}
public function get name():String {
return _name;
}

public function set unit(value:String):void {
_unit = value;
}
public function get unit():String {
return _unit;
}

public function readExternal(input:IDataInput):void {
__initialized = input.readObject() as Boolean;
__detachedState = input.readObject() as String;
if (meta::isInitialized()) {
_autoId = function(o:*):Number { return (o is Number ? o as Number : Number.NaN) } (input.readObject());
_materialType = input.readObject() as MaterialType;
_materialTypes = input.readObject() as ListCollectionView;
_name = input.readObject() as String;
_unit = input.readObject() as String;
}
else {
_autoId = function(o:*):Number { return (o is Number ? o as Number : Number.NaN) } (input.readObject());
}
}

public function writeExternal(output:IDataOutput):void {
output.writeObject(__initialized);
output.writeObject(__detachedState);
if (meta::isInitialized()) {
output.writeObject(_autoId);
output.writeObject(_materialType);
output.writeObject(_materialTypes);
output.writeObject(_name);
output.writeObject(_unit);
}
else {
output.writeObject(_autoId);
}
}
}
}

当调用远程服务返回的数据是一个ArrayCollection,包含所有的MaterialType的数据集合。

但是Tree的默认的dataDescriptor是查找children属性,可是MaterialType中没有,只有 materialTypes包含子node.

所以在mx.controls.treeClasses.DefaultDataDescriptor继承新类重载getChildren和 isBranch两个方法。

代码如下:

ActionScript代码

package org.bona.controls
{
import flash.utils.Dictionary;

import mx.collections.ArrayCollection;
import mx.collections.ICollectionView;
import mx.collections.XMLListCollection;
import mx.controls.treeClasses.DefaultDataDescriptor;
import mx.controls.treeClasses.ITreeDataDescriptor;

public class TreeDataDescriptor extends DefaultDataDescriptor implements ITreeDataDescriptor
{
/**
*  Constructor.
*/
public function TreeDataDescriptor(children:String=null)
{
super();
childrenField=children;
//trace(‘TreeDataDescriptor Constructor, ’ + childrenField);
}

/**
*  @private
*/
private var ChildCollectionCache:Dictionary=new Dictionary(true);

[Bindable]
public var childrenField:String=null;

override public function getChildren(node:Object, model:Object=null):ICollectionView
{
//          trace(node);
var childrenCollection:ICollectionView=super.getChildren(node, model);
var children:*;
if (childrenCollection != null)
{
//              trace(’super.getChildren =’, childrenCollection);
return childrenCollection;
}
children=node[childrenField];
//          trace(children);

//then wrap children in ICollectionView if necessary
if (children is ICollectionView)
{
childrenCollection=ICollectionView(children);
}
else if (children is Array)
{
var oldArrayCollection:ArrayCollection=ChildCollectionCache[node];
if (!oldArrayCollection)
{
childrenCollection=new ArrayCollection(children);
ChildCollectionCache[node]=childrenCollection;
}
else
{
childrenCollection=oldArrayCollection;
//ArrayCollection(childrenCollection).mx_internal::dispatchResetEvent=false;
ArrayCollection(childrenCollection).source=children;
}

}
else if (children is XMLList)
{
var oldXMLCollection:XMLListCollection=ChildCollectionCache[node];
if (!oldXMLCollection)
{
// double check since XML as dictionary keys is inconsistent
for (var p:*in ChildCollectionCache)
{
if (p === node)
{
oldXMLCollection=ChildCollectionCache[p];
break;
}
}
}

if (!oldXMLCollection)
{
childrenCollection=new XMLListCollection(children);
ChildCollectionCache[node]=childrenCollection;
}
else
{
childrenCollection=oldXMLCollection;

//We don’t want to send a RESET type of collectionChange event in this case.
//XMLListCollection(childrenCollection).mx_internal::dispatchResetEvent=false;
XMLListCollection(childrenCollection).source=children;
}
}
else
{
var childArray:Array=new Array(children);
if (childArray != null)
{
childrenCollection=new ArrayCollection(childArray);
}
}
return childrenCollection;
}

/**
*  Tests a node for termination.
*  Branches are non-terminating but are not required to have any leaf nodes.
*  If the node is XML, returns <code>true</code> if the node has children
*  or a <code>true isBranch</code> attribute.
*  If the node is an object, returns <code>true</code> if the node has a
*  (possibly empty) <code>children</code> field.
*
*  @param node The node object currently being evaluated.
*  @param model The collection that contains the node; ignored by this class.
*
*  @return <code>true</code> if this node is non-terminating.
*/
override public function isBranch(node:Object, model:Object=null):Boolean
{
var branch:Boolean = super.isBranch(node,model);
if (branch)return branch;
if (node == null)
return false;
if (node is Object)
{
try
{
if (node[childrenField] != undefined)
{
branch=true;
}
}
catch (e:Error)
{
}
}
return branch;
}

}

}

在应用程序模块中如下应用:

MXML代码


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" xmlns:tdd="org.bona.controls.*" creationComplete="{initData();}" viewSourceURL="srcview/index.html">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
[Bindable]
private var datas:ArrayCollection = new ArrayCollection();
[Bindable]
private var selectedItem:MaterialType;

private function initData():void{
var mt:MaterialType = generateMaterialType(‘level top -1′);
generateMaterialType(‘level 2-1′,mt);
generateMaterialType(‘level 2-2′,mt);
generateMaterialType(‘level 2-3′,mt);
datas.addItem(mt);
mt = generateMaterialType(‘level top -2′);
datas.addItem(mt);
}

private function generateMaterialType(name:String,parent:MaterialType=null):MaterialType{
var mt :MaterialType = new MaterialType();
mt.name = name;
if(parent !=null){
if(parent.materialTypes==null){
parent.materialTypes = new ArrayCollection();
}
parent.materialTypes.addItem(mt);
}
return mt;
}

private function selected(e:Event):void{
selectedItem = Tree(e.target).selectedItem as MaterialType;
}

]]>
</mx:Script>
<mx:HDividedBox width="100%" height="100%">
<mx:Tree dataProvider="{datas}" labelField="name" height="100%" width="100%" change="selected(event);">
<mx:dataDescriptor>
<tdd:TreeDataDescriptor childrenField="materialTypes"/>
</mx:dataDescriptor>
</mx:Tree>
<mx:VBox width="100%" height="100%">
<mx:Label text="selected material type:"/>
<mx:TextArea width="100%" height="100%" text="{selectedItem.name}"/>
</mx:VBox>

</mx:HDividedBox>

</mx:Application>

这样就可以自定义childrenField来描述自己的结构。

查看在线Demo

自己写的AIR小程序 for Adoble workflowlab(WL)

如题,下载了adobe workflowLab AIR软件,做系统开发流程的设计规划,还是挺有意思的,后来看了看他的tool列表全是adobe公司自己的产品,你想在任务中标识产品工具就是不行,找到他的安装目录发现有个XML文件.

一般是这个路径:C:\Program Files\WorkflowLab\assets\tools\adobe\tools_en_US.xml.

内容大致如下:

XML/HTML代码
  1. <tools>  
  2.   <tool name="Adobe Media Encoder CS4" type="Adobe" version="CS4" icon="media_encoder_16.png" link=""/>  
  3.   <tool name="Adobe Reader 9" type="Adobe" version="9" icon="acrobatReader_16.png" link="http://www.adobe.com/go/EN_US-H-GET-READER"/>  
  4.   <tool name="Adobe Photoshop CS4" type="Adobe" version="CS4" icon="photoshop_16.png" link="http://www.adobe.com/go/tryphotoshop"/>  
  5.   <tool name="Adobe Illustrator CS4" type="Adobe" version="CS4" icon="illustrator_16.png" link="http://www.adobe.com/go/tryillustrator"/>  
  6.   <tool name="Adobe Fireworks CS4" type="Adobe" version="CS4" icon="fireworks_16.png" link="http://www.adobe.com/go/tryfireworks"/>  
  7.  。。。。  

 

所以就写了一个小工具实现对该文件的编辑。

保存后再打开ADOBE WL程序:

To install this application you will need the Adobe Flash Player