<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    posts - 36, comments - 30, trackbacks - 0, articles - 3

    2008年4月23日

    這部分介紹如何分視圖顯示前面講的表格內容,Backbone中視圖可以嵌套顯示,例如前面例子中整個頁面可以用一個視圖來渲染,table表格可以用一個視圖來渲染,表格中的一行可以用一個視圖來渲染,這樣就用三層視圖,只要在以前的例子上稍作修改就可以實現這效果。

     
    首先定義最里層的視圖,表格中的行。通過tagName成員變量指定該視圖對應的html元素,render方法中指定tr元素中顯示的內容。當然也可以指定成員變量className的值,來指定tr元素顯示的式樣。

         var StudentView = Backbone.View.extend({
             
             tagName: 'tr',
             
             render: function() {
                 $(this.el).html(_.map([
                     this.model.get('id'),
                    this.model.get('name'),
                    this.model.get('age')
                 ],function(val, key){
                     return '<td>' + val + '</td>';
                 }))
                
                return this;
             }
         })

    其次顯示表格的視圖。
         var StudnetCollectionView = Backbone.View.extend({
             
             tagName: 'table',
             
             render: function() {
                $(this.el).empty();
                
                  $(this.el).append($('<tr></tr>')).html(_.map([
                      '學號','姓名','年齡'
                  ],function(val, key){
                      return '<th>' + val + '</th>';
                  }));
                
                  $(this.el).append(_.map(this.collection.models,
                    function(model, key){
                          return new StudentView({
                              model: model
                          }).render().el;
                  }));
                
                return this;
             }
         });

    最后顯示整個頁面的視圖。
         var StudnetPageView = Backbone.View.extend({
             render: function() {
                 $(this.el).html(new StudnetCollectionView({
                     collection: this.collection
                 }).render().el);
             }
         })

    同時修改一下顯示部分的代碼。

        var studentPageView = new StudnetPageView({
                 collection: studentCollection,
                 el: 'body'
             });
     
             studentPageView.render();

    整個main.js的代碼如下:

      (function($){
          $(document).ready(function(){
              
              var student1 = new Student({
                  id: 10000,
                  name: '王小二',
                  age: 30
              });
              
             var student2 = new Student({
                 id: 20000,
                 name: '姚敏',
                 age: 26
             });
             
             var student3 = new Student({
                 id: 30000,
                 name: '科比',
                 age: 24
             });
             
             var studentCollection = new StudentCollection([
                 student1,
                 student2,
                 student3
             ]);
             
             var studentPageView = new StudnetPageView({
                 collection: studentCollection,
                 el: 'body'
             });
     
             studentPageView.render();
             
         });
         
         //set model
         var Student = Backbone.Model.extend({
             //set default values.
             defaults: {
                 id: 0,
                 name: '',
                 age: 0
             }
         });
         
         var StudentCollection = Backbone.Collection.extend({
             model: Student
         });
         
         var StudentView = Backbone.View.extend({
             
             tagName: 'tr',
             
             render: function() {
                 $(this.el).html(_.map([
                     this.model.get('id'),
                    this.model.get('name'),
                    this.model.get('age')
                 ],function(val, key){
                     return '<td>' + val + '</td>';
                 }))
                
                return this;
             }
         })

         //set view
         var StudnetCollectionView = Backbone.View.extend({
             
             tagName: 'table',
             
             render: function() {
                $(this.el).empty();
                
                  $(this.el).append($('<tr></tr>')).html(_.map([
                      '學號','姓名','年齡'
                  ],function(val, key){
                      return '<th>' + val + '</th>';
                  }));
                
                  $(this.el).append(_.map(this.collection.models,
                    function(model, key){
                          return new StudentView({
                              model: model
                          }).render().el;
                  }));
                
                return this;
             }
         });
         
         var StudnetPageView = Backbone.View.extend({
             render: function() {
                 $(this.el).html(new StudnetCollectionView({
                     collection: this.collection
                 }).render().el);
             }
         })
         
     })(jQuery);

    posted @ 2016-04-04 17:40 笑看人生 閱讀(172) | 評論 (0)編輯 收藏

    @import url(http://m.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); 在學習筆記一中,一個視圖渲染一個Sudent對象,如果存在多個Student對象怎么辦,
    在java中可以通過ArrayList來保存,比如List<Student> students = new ArrayList<>();
    在Backbone中,也有類似于ArrayList的實現,只需要新建一個類,繼承Collection就可以了,實現代碼如下:
    成員變量model指定集合中存放對象的類型,類似于java中范型。

    1     var StudentCollection = Backbone.Collection.extend({
    2         model: Student
    3     });

    對學習筆記一種代碼稍加修改,修改代碼如下:
    新建三個Student對象,把這三個對象加入studentCollection對象中。

     1         var student1 = new Student({
     2             id: 10000,
     3             name: '王小二',
     4             age: 30
     5         });
     6         
     7         var student2 = new Student({
     8             id: 20000,
     9             name: '姚敏',
    10             age: 26
    11         });
    12         
    13         var student3 = new Student({
    14             id: 30000,
    15             name: '科比',
    16             age: 24
    17         });
    18         
    19         var studentCollection = new StudentCollection([
    20             student1,
    21             student2,
    22             student3
    23         ]);

    至此集合模型已經新建完畢,那么如何通過視圖來顯示這個集合模型。

    學習筆記一中新建的StudentView類的render方法做修改,同時在構建這個類對象時,稍作修改,修改如下:
    把原來綁定model的代碼改成綁定collection。

    1 var studentCollectionView = new StudnetCollectionView ({
    2             collection: studentCollection
    3  });

     1     var StudnetCollectionView = Backbone.View.extend({
     2         
     3         el: 'body',
     4         
     5         render:function(){
     6             var html = '';
     7             _.each(this.collection.models,function(model,index,obj){
     8                 var tmp = '學號: ' + model.get('id') + '.' +
     9                           '姓名: ' + model.get('name') + '.' +
    10                           '年齡: ' + model.get('age');
    11                 
    12                 html = html + '<li>' + tmp + '</li>'; 
    13             });
    14             
    15             html = '<ul>' + html + '</ul>';
    16             $(this.el).html(html);
    17         }
    18     });

    完整的main.js內容如下:
     1 (function($){
     2     $(document).ready(function(){
     3         
     4         var student1 = new Student({
     5             id: 10000,
     6             name: '王小二',
     7             age: 30
     8         });
     9         
    10         var student2 = new Student({
    11             id: 20000,
    12             name: '姚敏',
    13             age: 26
    14         });
    15         
    16         var student3 = new Student({
    17             id: 30000,
    18             name: '科比',
    19             age: 24
    20         });
    21         
    22         var studentCollection = new StudentCollection([
    23             student1,
    24             student2,
    25             student3
    26         ]);
    27         
    28         var studentCollectionView = new StudnetCollectionView({
    29             collection: studentCollection
    30         });
    31 
    32         studentCollectionView.render();
    33         
    34     });
    35     
    36     //set model
    37     var Student = Backbone.Model.extend({
    38         //set default values.
    39         defaults: {
    40             id: 0,
    41             name: '',
    42             age: 0
    43         }
    44     });
    45     
    46     var StudentCollection = Backbone.Collection.extend({
    47         model: Student
    48     });
    49     
    50     //set view
    51     var StudnetCollectionView = Backbone.View.extend({
    52         
    53         el: 'body',
    54         
    55         render:function(){
    56             var html = "<table border='1'><tr><th>學號</th><th>姓名</th><th>年齡</th></tr>";
    57             _.each(this.collection.models, function(model,index,obj){
    58                 var tmp = '<tr><td>' + model.get('id') + '</td>' +
    59                           '<td>' + model.get('name') + '</td>' +
    60                           '<td> ' + model.get('age') + '</td></tr>';
    61                           
    62                           
    63                 html = html = html + tmp;
    64             });
    65             
    66             html = html + '</table>';
    67             $(this.el).html(html);
    68         }
    69     });
    70     
    71 })(jQuery);
    72 


    posted @ 2016-04-02 12:06 笑看人生 閱讀(851) | 評論 (0)編輯 收藏

    項目里用到Backbone+marionet框架,由于以前沒有接觸過這些技術,經過一段時間的學習,覺得這技術還是很強大的,現把
    學習體會總結一下,以便后面查詢。

    Backbone是一個基于MVC模式的前端JavaScript框架,用于前端頁面開發。
    可以從http://backbone.js上下載對應的版本。

    使用Backbone,需要依賴其他一些js庫。
    jQuery  http://jquery.com
    Underscore http://underscorejs.org

    頁面的head元素內容大體如下:
    1 <script src="lib/jquery-2.2.2.js"></script>
    2 <script src="lib/underscore-2.js"></script>
    3 <script src="lib/backbone.js"></script>

    Backbone是一個MVC框架,通過V來展示M的內容,C接受用戶的請求,更新模型,然后刷新V。

    下面以一個例子,來說明怎么建立一個簡單的Backbone應用。

    首先定義一個Model類Student, 需要繼承Backbone.Model,這個類有三個成員變量,id,name,age,套用java中的叫法,其實可能
    不應該這么稱呼。

    1     var Student = Backbone.Model.extend({
    2         //set default values.
    3         defaults: {
    4             id: 0,
    5             name: '',
    6             age: 0
    7         }
    8     });


    然后定義一個View類StudentView,需要繼承Backbone.View, 給這個類的成員變量el賦值 body,指明在頁面的body元素中渲染視圖,
    同時重寫了渲染方法render,指明如何渲染,以下代碼應用jQuery的語法,在el指定的元素內,顯示指定的內容。
    每個視圖綁定一個Model,在View的所有方法中可以直接調用this.model獲取當前View綁定的Model對象,如下例子
    this.model.get('id'),注意獲取model屬性值時,不能直接使用thi.model.id

     1     var StudnetView = Backbone.View.extend({
     2         
     3         el: 'body',
     4         
     5         render:function(){
     6             var html = '學號: ' + this.model.get('id') + '.' +
     7                        '姓名: ' + this.model.get('name') + '.' +
     8                        '年齡: ' + this.model.get('age');
     9     
    10             $(this.el).html(html);
    11         }
    12     });

    定義完模型和視圖類之類,接下來就是創建模型類和視圖類對象,創建方法類似于java中創建對象。
    新建一個model對象student,給對象屬性指定值。
    新建一個view對象,并且指定該view綁定的model對象。
    調用view的渲染方法。

     1     var student = new Student({
     2             id: 10000,
     3             name: '王小二',
     4             age: 30
     5      });
     6         
     7         
     8     var studnetView = new StudnetView({
     9             model: student
    10     });
    11 
    12     studnetView.render();

    至此Backbone的代碼就全部寫完了,只要把這些新建Model和View的代碼放到自定義的js文件中,
    在頁面加載時調用即可,這里自定義js文件名為main.js,內容如下:

     1 (function($){
     2     $(document).ready(function(){
     3         
     4         var student = new Student({
     5             id: 10000,
     6             name: '王小二',
     7             age: 30
     8         });
     9         
    10         
    11         var studnetView = new StudnetView({
    12             model: student
    13         });
    14 
    15         studnetView.render();
    16         
    17     });
    18     
    19     //set model
    20     var Student = Backbone.Model.extend({
    21         //set default values.
    22         defaults: {
    23             id: 0,
    24             name: '',
    25             age: 0
    26         }
    27     });
    28     
    29     //set view
    30     var StudnetView = Backbone.View.extend({
    31         
    32         el: 'body',
    33         
    34         render:function(){
    35             var html = '學號: ' + this.model.id + '.'
    36                        '姓名: ' + this.model.name + '.'
    37                        '年齡: ' + this.model.age;
    38     
    39             $(this.el).html(html);
    40         }
    41     });
    42     
    43 })(jQuery);

    然后再新建一個index.html,內容如下:

     1 <!DOCTYPE html>
     2 <html>
     3     <head>
     4         <meta charset="utf-8">
     5         <title>Backbone.js 1</title>
     6         <script src="lib/jquery-2.2.2.js"></script>
     7         <script src="lib/underscore-2.js"></script>
     8         <script src="lib/backbone.js"></script>
     9         <script src="js/main.js"></script>
    10     </head>
    11     <body>
    12         
    13     </body>
    14 </html>

    最后,在瀏覽器中打開這個文件,就可以看到效果了。

    posted @ 2016-04-02 10:06 笑看人生 閱讀(2553) | 評論 (0)編輯 收藏

    @import url(http://m.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); @import url(http://m.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);

    參照以下網址,在CentOS上安裝Nginx
    http://m.tkk7.com/jacky9881/archive/2016/02/19/429375.html

    1.首先新建以下兩個目錄,用于存放緩存文件;
       [root@localhost nginx]# mkdir -p /data/nginx/proxy_temp_path
       [root@localhost nginx]# mkdir -p /data/nginx/proxy_cache_path

    2.編輯nginx.conf文件
      在http模塊增加如下內容,指定緩存文件的存放路徑:
      proxy_temp_path /data/nginx/proxy_temp_path;
      proxy_cache_path /data/nginx/proxy_cache_path levels=1:2 keys_zone=cache_one:20m inactive=1d max_size=3g ;  

    注:通過keys_zone來指定緩存區的名字,在接下來的location模塊配置中需要用到;
          20m是指定用于緩存的內存大小(由于本人虛擬機內存原因,設置了20M,生產環境中可以設置大一些,比如1G);
          inactive=1d,代表緩存的數據如果超過一天沒有被訪問的話,則自動清除;
          max_size=3g是指定用于緩存的硬盤大小(由于本人虛擬機內存原因,設置了3g,生產環境中可以設置大一些,比如50G);
          levels=1:2 指定該緩存目錄中有兩層hash目錄,第一層目錄為1個字母,第二層為2個字母,其中第一層目錄名為緩存數據MD5編碼的倒數第一個
         字母,第二層目錄名為緩存數據MD5編碼的倒數2,3兩個字母;

     upstream local_tomcats {
           server 192.168.8.132:8080;
           server 192.168.8.130:8080;
    }

     修改location模塊
      location ~ \.(jsp|do)$ {
                proxy_pass http://local_tomcats;
     }        
            
      location / {

                proxy_cache cache_one;
                #定義http返回值為200和304,緩存時間12小時,如果12小時后,沒有被訪問,則自動被刪除;
                #200表示 服務器已成功處理了請求,304表示 自從上次請求后,請求的網頁未修改過
                proxy_cache_valid 200 304 12h ;
                proxy_cache_valid 301 302 1m ;
                proxy_cache_valid any 10m ;
                proxy_cache_key $host$uri$is_args$args;

                proxy_ignore_headers X-Accel-Expires Expires  Set-Cookie Cache-Control;
                proxy_hide_header Cache-Control;
                proxy_hide_header Set-Cookie;               
                proxy_pass http://local_tomcats; #這個要設定,否則好像生成不了緩存文件

        }
    #用于清除緩存
     location ~ /purge(/.*) {
                allow 127.0.0.1;
                allow 192.168.8.132;
                deny all ;
                proxy_cache_purge cache_one $host$1$is_args$args ;
       }  

    在瀏覽器地址欄輸入:http://www.hw.com/tomcat.png
    查看緩存目錄
    [root@localhost nginx]# ls /data/nginx/proxy_cache_path/7/8a
    b12ee1366ed4307aa6408a16286658a7

    可以看到,緩存文件已經生成,注意緩存文件名最后三位和緩存文件夾的關系。

    在瀏覽器地址欄輸入:http://www.hw.com/purge/tomcat.png
    頁面顯示如下信息,提示緩存文件已經被清除。

    Successful purge

    Key : www.hw.com/tomcat.png
    Path: /data/nginx/proxy_cache_path/7/8a/b12ee1366ed4307aa6408a16286658a7 

    注意這里的Key,就是配置文件中定義 proxy_cache_key 

    查看緩存命中率
    location / 模塊,增加如下代碼
    add_header  Nginx-Cache "$upstream_cache_status"

    同時在http模塊打開ngnix的日志功能,默認是關閉狀態。

        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"'
                           '"$upstream_cache_status"';
        access_log  logs/access.log  main;
     

    [root@localhost nginx]# ./sbin/nginx -s reload

    在瀏覽器地址欄輸入:http://www.hw.com/tomcat.png
    重復刷新幾次,打開日志文件 logs/access.log,可以看到HIT的字樣,意味著緩存命中。

    192.168.8.132 - - [08/Mar/2016:20:48:38 +0800] "GET /tomcat.png HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0" "-""HIT"
    192.168.8.132 - - [08/Mar/2016:20:48:40 +0800] "GET /tomcat.png HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0" "-""HIT"
    192.168.8.132 - - [08/Mar/2016:20:48:42 +0800] "GET /tomcat.png HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Firefox/38.0" "-""HIT"


    posted @ 2016-03-08 20:29 笑看人生 閱讀(2919) | 評論 (1)編輯 收藏

         摘要: 不講原理,直接上步驟: 1.下載MyCat,Mycat-server-1.4-release-20151019230038-linux.tar 2. 解壓到/usr/mycat目錄下:     [root@localhost mycat]# tar -xvf  Mycat-server-1.4-release-20151019230038-linux.t...  閱讀全文

    posted @ 2016-02-27 15:28 笑看人生 閱讀(3965) | 評論 (1)編輯 收藏

    @import url(http://m.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); @import url(http://m.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); @import url(http://m.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); @import url(http://m.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); @import url(http://m.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); @import url(http://m.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
     主服務器  OS:CentOS   IP:192.168.8.130
     從服務器  OS:CentOS   IP:192.168.8.131

    在主,從服務器上安裝MySQL,安裝方法如下:
    [root@localhost Desktop]$ rpm -qa | grep mysql
       mysql-libs-5.1.73-5.el6_6.x86_64
    [root@localhost Desktop]# rpm -e mysql-libs-5.1.73-5.el6_6.x86_64 --nodeps
    [root@localhost Desktop]# yum -y install mysql-server mysql mysql-devel

    啟動MySQL
    [root@localhost Desktop]# service mysqld start

    ??梢栽O置MySQL開機啟動,運行命令chkconfig mysqld on

    #給root賬號設置密碼
    [root@localhost Desktop]# mysqladmin -u root password 'root'
    [root@localhost Desktopps]# mysql -u root -p
    給從服務器(192.168.8.131)授權,并且給從服務器創建訪問主服務器的賬號和密碼 admin
    mysql> grant replication slave on *.* to 'admin'@'192.168.8.131' identified by 'admin';
    創建數據庫contract
    mysql> create database contract;
    mysql>quit;

    復制MySQL數據庫配置模版覆蓋/etc/my.cnf
    [root@localhost Desktopps]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf   
    [root@localhost Desktopps]#vi /etc/my.cnf
    設置以下三個值

    log-bin=mysql-bin   #指定從服務器讀取的日志文件
    server-id = 1        #主服務器必須設定為1,從服務器的值>1
    binlog-do-db=contract #對contract數據庫的操作日志會記錄到mysql-bin

    #原理:MySQL主從復制的原理是主服務器把對指定數據庫操作的日志寫到指定的日志文件中,從服務器
                讀取這個日志文件,寫到從服務器的指定日志文件中,然后在從服務器重新執行日志文件。

    配置完之后,重啟MySQL
    [root@localhost Desktopps]#service mysqld restart
    Stopping mysqld:                                          [  OK  ]
    Starting mysqld:                                           [  OK  ]

    [root@localhost Desktopps]# mysql -u root -p
    查看主服務器的狀態
    mysql> show master status\G;
    *************************** 1. row ***************************
                        File: mysql-bin.000005
                  Position: 106
         Binlog_Do_DB: contract
    Binlog_Ignore_DB: 
    1 row in set (0.00 sec)

    這里記好File和Position的值,配置從服務器的時候需要用到。File就是從服務器需要讀取的日志文件,Position表示從日志文件的什么位置開始讀起。

     下面開始配置從服務器
    [root@localhost Desktop]# mysqladmin -u root password 'root'
    [root@localhost Desktopps]# mysql -u root -p
    創建數據庫contract
    mysql> create database contract;
    mysql>quit;
    [root@localhost Desktopps]# cp /usr/share/mysql/my-medium.cnf /etc/my.cnf   
    [root@localhost Desktopps]#vi /etc/my.cnf
    設置以下兩個值

    log-bin=mysql-bin   #指定主服務器讀取的日志文件
    server-id = 2       #主服務器必須設定為1,從服務器的值>1

    [root@localhost Desktopps]# mysql -u root -p
    mysql> CHANGE MASTER TO MASTER_HOST='192.168.8.130', MASTER_PORT=3306,
                MASTER_USER='admin', MASTER_PASSWORD='admin',
                MASTER_LOG_FILE='mysql-bin.000005'MASTER_LOG_POS=106; 
    啟動從服務器同步
    mysql>start slave;
    mysql>show slave status\G;

    Slave_IO_Running: YES
    Slave_SQL_Running: YES

    如果輸出以上內容,則表示MySQL主從復制配置成功。

    驗證
    在主服務器上運行 
    [root@localhost Desktopps]# mysql -u root -p
    mysql> use contract;
    Database changed
    mysql> show tables;
    Empty set (0.04 sec)

    在從服務器上運行
    [root@localhost Desktopps]# mysql -u root -p
    mysql> use contract;
    Database changed
    mysql> show tables;
    Empty set (0.04 sec)

    確定主從服務器的數據庫contract的下面都沒有表。
    在主服務器上運行建表命令,并往表里插入一條記錄:
     mysql> create table `user` (`id` int not null auto_increment,`name` varchar (60),`password` varchar (20),`role` int not null,`email` varchar (30),`alertday` int,primary key (`id`));
    Query OK, 0 rows affected (0.36 sec)
     mysql> insert into `user` (`name`,`password`,`role`,`email`,`alertday`) values('admin','admin',0,'xxxx@xxx.com',30);
    Query OK, 1 row affected (0.08 sec)

    在從服務器上運行查詢語句。
    mysql> select * from user;
    +----+-------+----------+------+--------------+----------+
    | id | name  | password | role | email        | alertday |
    +----+-------+----------+------+--------------+----------+
    |  1 | admin | admin    | 0    | xxxx@xxx.com |       30 |
    +----+-------+----------+------+--------------+----------+
    1 row in set (0.01 sec)

    從輸出結果可以看出,主服務器上的數據被同步到從服務器上了。

    通過搭建MySQL主從復制結構,可以提高數據的安全性,同時可以實現讀寫分離,讓寫操作在主服務器上進行,
    讀操作在從服務器上進行,可以分擔主服務器的負擔。但是如果當主服務器宕機之后,數據庫就只能提供
    讀操作了,不能做到故障轉移,這時候,主主復制就應運而生了,有時間整理一下主主復制的配置。




    @import url(http://m.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);

    posted @ 2016-02-23 20:41 笑看人生 閱讀(365) | 評論 (0)編輯 收藏

    @import url(http://m.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);
    在CentOS上安裝JDK7,Tomcat7和Nginx1.9手順

    1.下載 jdk-7u79-linux-x64.rpm,下載地址如下:
      http://www.oracle.com/technetwork/cn/java/javase/downloads/jdk7-downloads-1880260.html

      [root@localhost java]#rpm -qa | grep jdk
      [root@localhost java]#cp /home/huangwei/Downloads/jdk-7u79-linux-x64.rpm .
      [root@localhost java]# chmod 755 jdk-7u79-linux-x64.rpm 
      [root@localhost java]# rpm -ivh jdk-7u79-linux-x64.rpm 
      [root@localhost java]# vi /etc/profile

           #set java enviromet
           JAVA_HOME=/usr/java/jdk1.7.0_79
           PATH=$PATH:$JAVA_HOME/bin
           CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
           export JAVA_HOME PATH CLASSPATH
      [root@localhost java]# source /etc/profile
      [root@localhost java]# java -version
           java version "1.7.0_79"
           Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
           Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
      [root@localhost lib]# rpm -qa | grep jdk
           jdk-1.7.0_79-fcs.x86_64



    2.下載 apache-tomcat-7.0.68.zip,下載地址如下:
      http://tomcat.apache.org/download-70.cgi
      unzip apache-tomcat-7.0.68.zip to /usr/
      [root@localhost bin]# cd /usr/apache-tomcat-7.0.68/bin
      [root@localhost bin]# chmod +x *.sh
      [root@localhost bin]# ./startup.sh 
    Using CATALINA_BASE:   /usr/apache-tomcat-7.0.68
    Using CATALINA_HOME:   /usr/apache-tomcat-7.0.68
    Using CATALINA_TMPDIR: /usr/apache-tomcat-7.0.68/temp
    Using JRE_HOME:        /usr/java/jdk1.7.0_79
    Using CLASSPATH:       /usr/apache-tomcat-7.0.68/bin/bootstrap.jar:/usr/apache-tomcat-7.0.68/bin/tomcat-juli.jar
    Tomcat started.

      在瀏覽器中輸入http://localhost:8080/ ,如果能正常打開Tomcat的主頁,說明Tomcat安裝成功。

    3.下載 nginx-1.9.11.tar.gz,下載地址如下:
      http://nginx.org/en/download.html
      [root@localhost usr]# rpm -qa | grep gcc
    gcc-4.4.7-16.el6.x86_64
    libgcc-4.4.7-16.el6.x86_64
      [root@localhost usr]# rpm -qa | grep openssl
    openssl-1.0.1e-42.el6.x86_64
      [root@localhost usr]# rpm -qa | grep zlib
    zlib-1.2.3-29.el6.x86_64
      [root@localhost usr]# rpm -qa | grep pcre
    pcre-7.8-7.el6.x86_64
      [root@localhost usr]# tar -zxvf nginx-1.9.11.tar.gz 
      [root@localhost usr]# cd nginx-1.9.11/
      [root@localhost nginx-1.9.11]# yum -y install pcre-devel
      [root@localhost nginx-1.9.11]# yum -y install zlib-devel
      [root@localhost nginx-1.9.11]# ./configure --prefix=/usr/nginx
      [root@localhost nginx-1.9.11]# make && make install
      [root@localhost nginx-1.9.11]# cd /usr/nginx/sbin/
      [root@localhost sbin]# ./nginx -t
    nginx: the configuration file /usr/nginx/conf/nginx.conf syntax is ok
    nginx: configuration file /usr/nginx/conf/nginx.conf test is successful
      [root@localhost sbin]# ./nginx

      
    在瀏覽器中輸入http://localhost/ ,如果能正常打開Nginx的主頁,說明Nginx安裝成功。
    @import url(http://m.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css);

    posted @ 2016-02-19 19:43 笑看人生 閱讀(299) | 評論 (0)編輯 收藏

         摘要: @import url(http://m.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); Normal 0 10 pt 0 2 false ...  閱讀全文

    posted @ 2016-01-31 13:10 笑看人生 閱讀(4599) | 評論 (0)編輯 收藏

         摘要: @import url(http://m.tkk7.com/CuteSoft_Client/CuteEditor/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/css/cuteeditor.css); 參照一下地址,搭建nginx tomcat的負載均衡環境 Nor...  閱讀全文

    posted @ 2016-01-28 20:13 笑看人生 閱讀(3283) | 評論 (0)編輯 收藏

         摘要: 搭建nginx和 tomcat環境,實現負載均衡  閱讀全文

    posted @ 2016-01-28 19:45 笑看人生 閱讀(3272) | 評論 (0)編輯 收藏

    擴展點:
    org.eclipse.ui.ide.resourceFilters
    org.eclipse.jdt.ui.javaElementFilters

    org.eclipse.ui.ide.resourceFilters擴展點可以給Naivgator視圖的過濾器列表增加過濾項,要使用該擴展點需要在插件依賴項中追加
    對插件項目org.eclipse.ui.ide的依賴。

    擴展清單如下:

    <extension
               
    point="org.eclipse.ui.ide.resourceFilters">
            
    <filter
                  
    pattern="*.classpath"
                  selected
    ="true">
            
    </filter>
    </extension>
    上述代碼的作用就是給Navigator視圖,增加過濾器,過濾后綴名為classpath的文件,該過濾項默認為選中狀態。

    org.eclipse.jdt.ui.javaElementFilters擴展點可以給Java透視圖中相應視圖的過濾器列表增加過濾項,要使用該擴展點需要在插件依賴項中追加
    對插件項目org.eclipse.jdt.ui的依賴。

    擴展清單如下:

    <extension
               
    point="org.eclipse.jdt.ui.javaElementFilters">
            
    <filter
                  
    description="TestFilter Des"
                  enabled
    ="true"
                  id
    ="aaaa"
                  name
    ="TestFilter"
                  pattern
    ="*.properties"
                  targetId
    ="org.eclipse.jdt.ui.PackageExplorer">
            
    </filter>
     
    </extension>

    上述代碼的作用就是給Package視圖,增加過濾器,過濾點后綴名為properties的文件,該過濾項默認為選中狀態。

    posted @ 2010-07-09 20:59 笑看人生 閱讀(2299) | 評論 (0)編輯 收藏

    擴展點:
    org.eclipse.ui.bindings
    org.eclipse.ui.contexts

    擴展點org.eclipse.ui.bindings是給command增加快捷鍵,結合(介紹二),給命令com.xxxx.test.command1增加快捷鍵,
    示例代碼如下:

    <extension
             
    point="org.eclipse.ui.bindings">
          
    <key
                
    commandId="com.xxxx.test.command1"
                contextId
    ="org.eclipse.ui.contexts.window"
                schemeId
    ="org.eclipse.ui.defaultAcceleratorConfiguration"
                sequence
    ="M2+F7">
          
    </key>  
    </extension>

    這樣快捷鍵Shift+F7在Eclipse工作臺上都會起作用,但是如果想讓命令的快捷鍵只對特定的視圖或者編輯器起作用,那么可以通過org.eclipse.ui.contexts擴展點來自定義上下文。

    <extension
               
    point="org.eclipse.ui.contexts">
            
    <context
                  
    id="viewmenu.testcontext"
                  name
    ="ViewContext"
                  parentId
    ="org.eclipse.ui.contexts.window">
            
    </context>
    </extension>

    擴展之后,需要修改org.eclipse.ui.bindings擴展中的contextId屬性為viewmenu.testcontext。

    另外還需要在需要增加該快捷鍵的編輯器或者視圖對應類中增加如下代碼(視圖類在代碼的createControl方法,編輯器類在代碼的init方法):

    IContextService contextService = 
    (IContextService) getSite().getService(IContextService.
    class);
    contextService.activateContext(
    "viewmenu.testcontext");

    posted @ 2010-07-09 20:52 笑看人生 閱讀(2732) | 評論 (0)編輯 收藏

    原文地址:http://www.fengfly.com/plus/view-179398-1.html

    菜單是各種軟件及開發平臺會提供的必備功能,Eclipse 也不例外,提供了豐富的菜單,包括主菜單(Main Menu),視圖 / 編輯器菜單(ViewPart/Editor Menu)和上下文菜單(Context Menu)。在 Eclipse 中,幾乎所有的 Workbench Part 提供了人性化的菜單,大大方便了用戶的操作。因此,如何擴展 Eclipse 的菜單功能,并實現特定于我們自己插件的菜單,是插件開發者必須掌握的重要技能,同時,Eclipse 提供了豐富的擴展點供開發人員使用。本文將首先介紹 Eclipse 中的菜單,然后詳細說明如何進行擴展,最后以一個實例的形式引導讀者深入理解 Eclipse 的菜單功能。

      引言

      Eclipse 具有豐富的菜單功能,給開發人員提供了很好的用戶體驗??傮w而言,Eclipse 菜單種類包括視圖 / 編輯器菜單,主菜單(Main Menu),視圖 / 編輯器菜單(ViewPart/EditorPart Menu)和上下文菜單(Context Menu)。插件開發人員通過靈活應用這些菜單,可以給用戶提供很好的體驗。由于視圖和編輯器菜單功能類似,因此本文重點講述視圖菜單(視圖下拉菜單及其工具欄菜單),除此之外,還將講述主菜單和上下文菜單。

      如圖 1 所示為 Project Explorer 視圖的菜單,包括視圖下拉菜單和工具欄菜單(折疊樹節點)。通常而言,出現在視圖工具欄的菜單都會出現在視圖的下拉菜單,也就是說,比較常用的視圖菜單放在視圖的工具欄。

    圖 1. Project Explorer 視圖的菜單

     

     

      如圖 2 所示為 Project Explorer 視圖中的上下文菜單,只有當我們右鍵點擊時才會出現。通常而言,出現頻率較高的菜單項才會出現在菜單中。上下文菜單具有很強的靈活項,它可以隨著我們點擊的對象不同,彈出的菜單也會有相應的變化。

    圖 2. Project Explorer 視圖中的上下文菜單


      如圖 3 所示為 Eclipse 的主菜單,包括最上面的主菜單項(不可移動)及其下面的工具欄菜單(可以移動,并且 Eclipse 提供了顯示 / 不顯示這些菜單的功能),Eclipse 并不建議我們為每一個插件都添加新的主菜單,這樣容易造成冗余,而且不方便用戶操作。通常,我們可以把菜單項添加到 Eclipse 已有的菜單,如插件的查找功能可以添加一個查找菜單項到 Eclipse 的 Search 主菜單上。

    圖 3. Eclipse 的主菜單


      前面講到 Eclipse 的各種菜單,那么,如何在開發插件或 RCP 應用程序的時候添加這些菜單?本文下面的篇幅將詳細介紹如何擴展 Eclipse 的菜單功能,使讀者深入了解 Eclipse 的菜單功能,并能夠開發具有這些菜單的應用程序。因此,必須掌握三方面的內容:菜單種類,菜單的擴展點,菜單控制(顯示 / 隱藏或啟用 / 禁用菜單項)。下面從概念上介紹這三方面內容,下一小節將會進行詳細介紹。

      菜單種類

      正如前面所講到的,Eclipse 的菜單包括視圖菜單,主菜單及上下文菜單三個種類。

      菜單項的擴展點

      Eclipse 提供了兩種擴展點供用戶添加菜單項到相應的位置。這兩種擴展點為 org.eclipse.ui.commands(本文簡稱為 Commands 方式)和 org.eclipse.ui.actionSets(本文簡稱為 Actions 方式)。Actions 方式為界面上不同區域的表現方式提供了相應的擴展點,并且沒有分離其界面表現和內在實現。恰恰相反,Commands 方式通過三步有效的達到界面表現和內部實現的分離:首先,通過 org.eclipse.ui.commands 擴展點創建命令和類別(Category),并且可以把某些命令放在一個類別(Category)中;然后,通過 org.eclipse.ui.menus 指定命令出現在界面的哪個區域(視圖菜單 / 主菜單 / 上下文菜單);最后通過 org.eclipse.ui.handlers 指定命令的實現。因此,Eclipse 推薦新開發的插件使用 Commands 來創建您的界面菜單。當然,由于 Actions 在現有的插件中用得比較多,如果我們需要擴展或基于之前的插件開發,也需要對其進行了解。除此之外,針對上下文菜單,雖然 Commands 和 Actions 方式均可以創建上下文菜單,但是 Eclipse 還提供了另外一種創建上下文菜單的擴展點 org.eclipse.ui.popupMenus(本文簡稱為 popupMenus 方式),本文將就這三種擴展點做詳細的介紹。

      菜單控制

      菜單控制是一個非常常見的功能,例如,隨著選定的內容或當前窗口的不同,菜單中的菜單項會有相應的變化(顯示 / 隱藏或啟用 / 禁用菜單項),因此,如何控制菜單是插件開發人員必須掌握的知識。Eclipse 為菜單控制提供了兩種方法,一種是通過擴展點;另一種是通過 API 的方式編寫程序控制。

      Eclipse 菜單功能及其擴展點

      至此,我們對 Eclipse 菜單有了感觀的認識。由上一節我們可知,要深入理解 Eclipse 菜單功能,我們需要從三個方面去掌握:菜單種類,菜單的擴展點和菜單控制。下面將進行詳細講述。

      菜單種類

      針對各種菜單,Eclipse 提供了相應的擴展點,因此,開發人員可以通過這些擴展點把菜單放到界面的不同區域,詳細內容請參考 2.2 小節。

      菜單的擴展點

      視圖菜單的擴展點

      采用 Commands 方式創建視圖菜單,需要引入 org.eclipse.ui.menus 擴展點;而 Actions 方式需要引入 org.eclipse.ui.actionSets.

      1、視圖菜單(Commands 方式):

      MenuContribution locationURI = “[Scheme]:[id]?[argument-list]”

      其中,Scheme 為該菜單項出現的區域,menu 為視圖的下拉菜單,toolbar 為視圖的工具欄菜單;id 為菜單區域 ID;argument-list 為該菜單項出現在指定菜單的位置。

      例如:在 ProbelmView 的下拉菜單加一個菜單項,其 MenuContribution 的 locationURI 應為:menu:org.eclipse.ui.views.ProblemView?after=additions;在 ProblemView 的工具欄菜單中加入一個菜單項,其 locationURI 應為:toolbar:org.eclipse.ui.views.ProblemView?after=additions。

      2、視圖菜單(Actions 方式):

      采用 Actions 方式創建菜單,需要引入 org.eclipse.ui.actionSets 擴展點,并通過設定 action 的 menubarPath 指定下拉菜單 / 菜單項出現的位置;通過設定 action 的 toolbarPath 設定工具欄菜單 / 菜單項出現的位置。

      例如,添加一個下拉菜單項到 Problems 視圖中,其 menubarPath 應為:

      org.eclipse.ui.views.ProblemView/additions

      主菜單的擴展點

      1、主菜單(Commands 方式)

      通過 Commands 方式把菜單項添加到主菜單及其工具欄上,和視圖菜單一樣,也是通過擴展點 org.eclipse.ui.menus 實現,需要設定其 menuContribution 的 locationURI。

      例如,添加一個菜單(菜單可以包含若干個菜單項)到主菜單一欄中,其 locationURI 為:

      menu:org.eclipse.ui.main.menu?after=additions

      添加一個菜單到工具欄之中,其 locationURI 為:

      toolbar:org.eclipse.ui.main.toolbar?after=additions

      當然,我們也可以把菜單項添加到已經存在的菜單當中,例如添加一個菜單項到 Eclipse 的 Search 主菜單當中,其 locationURI 為:

      menu:org.eclipse.search.menu?dialogGroup

      2、主菜單(Actions 方式)

      通過 Actions 方式把菜單項添加到主菜單及其工具欄上,和視圖菜單一樣,也是通過擴展點 org.eclipse.ui.actionSets 實現,需要設定 action 的 menubarPath 和 toolbarPath 實現。

      例如,添加一個菜單項到 Eclipse 的 Search 主菜單中,其 menubarPath 應為:

      org.eclipse.search.menu/dialogGroup

      注意:如果采用上述方式添加一個菜單項到 Search 主菜單,當我們運行時并沒有出現添加的菜單項,這時候需要換一個 workspace,其原因是 Eclipse 緩存了與其相關的某些信息在 workspace 當中。

      上下文菜單的擴展點

      上下文菜單除了通過 Commands 和 Actions 方式添加,還可以使用擴展點 org.eclipse.ui.popupMenus 方式添加,下面分別進行介紹。

      1、上下文菜單(Commands 方式)

      Commands 方式與添加視圖菜單和主菜單的方式一樣,通過設定其 menuContribution 的 locationURI 來實現。

      例如,添加一個上下文菜單到 Problems 視圖中,其 locationURI 為:

      popup:org.eclipse.ui.views.ProblemView?after=additions。

      如果我們想讓某個上下文菜單項出現在任何區域,則可以使用下面的 locationURI:

      popup:org.eclipse.ui.popup.any?after=additions

      2、上下文菜單(Actions 方式)

      Actions 方式沒有直接提供擴展點添加上下文菜單,但是我們可以通過編程的方式實現,如下代碼清單 1 為 TreeViewer 添加上下文菜單,通過 IMenuManager 的 add 方法添加 actions。

    清單 1. 通過 Actions 方式編程實現添加上下文菜單

     private void hookContextMenu() { 
      IMenuManager fMenuMgr = new MenuManager(“#PopupMenu”); 
      fMenuMgr.setRemoveAllWhenShown(true); 
      // 添加 Actions 
      fMenuMgr.add(action … ) 
      fMenuMgr.createContextMenu(treeViewer.getControl()); 
      treeViewer.getControl().setMenu(fMenu); 
      getSite().registerContextMenu(fMenuMgr, treeViewer); 
     } 

      3、上下文菜單(popupMenus 方式)

      通過 popupMenus 擴展點實現上下文菜單,需要設定 objectContribution 的 objectClass 屬性把上下文菜單添加到相應的區域。

      例如,如果我們想當用戶點擊 Eclipse 中的資源時,彈出的上下文菜單包括某個菜單項,我們可以設定 objectClass 屬性為:

      org.eclipse.core.resources.IResource

      通過 Commands 方式創建菜單項

      通過 Commands 方式創建菜單項,首先需要創建 Command,通過擴展點 org.eclipse.ui.commands,然后我們可以把這個 Command 放到任何區域,上一小節已經講到,通過 org.eclipse.ui.menus 擴展點確定菜單創建的區域,最后通過擴展點 org.eclipse.ui.handlers 定義這個 command 的具體行為。

      在創建 Command 時,我們可以先創建一個 Category,并把相關的一些命令放到這個 Category 中,這樣有利于管理。代碼清單 2 創建一個 Command(“Show in Glossary Explorer”),并放到一個 Category 中,然后把該 Command 放到 BGSearchResultView 視圖的上下文菜單中,最后通過擴展 org.eclipse.ui.handlers 定義該 Command 的實現類。

    清單 2. 通過 Commands 方式添加菜單項

     <!-- 添加 command --> 
     <extension 
       point="org.eclipse.ui.commands"> 
      <category 
       description="Business Glossary" 
       id="com.ibm.bg.ui.commands.category" 
       name="%category.BusinessGlossary.name"> 
      </category> 
      <command 
       categoryId="com.ibm.bg.ui.commands.category" 
       description="Show in Glossary Explorer" 
       id="com.ibm.bg.ui.commands.BGShowInBrowser" 
       name="%command.ShowInGE.name"> 
      </command> 
     </extension> 
     <!-- 把 Command 放到界面的對應區域 --> 
     <extension 
        point="org.eclipse.ui.menus"> 
      <menuContribution locationURI= 
      "popup:com.ibm.bg.internal.ui.search.BGSearchResultView?after=additions"> 
       <command 
          commandId="com.ibm.bg.ui.commands.BGShowInBrowser" 
          style="push" 
          tooltip="%command.ShowInGE.tooltip"> 
       </command> 
      </menuContribution> 
     </extension> 
     <!-- 定義 command 的實現類 --> 
     <extension 
       point="org.eclipse.ui.handlers"> 
      <handler 
         class="com.ibm.bg.internal.ui.handlers.BGShowInBrowser" 
         commandId="com.ibm.bg.ui.commands.BGShowInBrowser"> 
      </handler> 
     </extension> 

      通過 Actions 方式創建菜單項

      正如前面講到,Actions 方式沒有分離界面的表現和內部實現,因此,所有這些均通過 action 來完成。如下代碼清單 3 為添加一個 Search 菜單項到 Eclipse 的 Search 主菜單(通過 action 的 menubarPath 指定)中,其中 class 對應的值為該 Action 的實現類,該類需要實現接口 IWorkbenchWindowActionDelegate。

    清單 3. 通過 Actions 方式添加菜單項

     <extension 
       point="org.eclipse.ui.actionSets"> 
      <actionSet 
         id="com.ibm.bg.ui.workbenchActionSet" 
         label="%category.name.0" 
         visible="true"> 
       <action 
          class="com.ibm.bg.internal.ui.handlers.BGSearchHandler" 
          definitionId="com.ibm.bg.ui.commands.BGSearch" 
          icon="icons/search.png" 
          id="com.ibm.bg.ui.commands.BGSearch" 
          label="%action.searchGlossayInMainMenu.label" 
          menubarPath="org.eclipse.search.menu/dialogGroup" 
          style="push"> 
       </action> 
      </actionSet> 
     </extension> 

      通過 popupMenus 方式創建菜單項

      popupMenus 方式創建上下文菜單項也是通過 action 來實現,下面例子為添加一個菜單項到用戶右擊 IGraphicalEditPart 對象時彈出的上下文菜單,通過 menubarPath 指定該 Action 出現的區域,通過 class 指定該 action 的實現類,該類需要實現接口 IObjectActionDelegate。

    清單 4. 通過 popupMenus 方式添加菜單項

     <extension 
       point="org.eclipse.ui.popupMenus"> 
      <objectContribution 
         adaptable="false" 
         id="com.ibm.bg.uml.objectContributions.BGAssignToGlossary" 
         objectClass="org.eclipse.gmf.runtime.diagram.ui.editparts.IGraphicalEditPart"> 
       <action 
          class="com.ibm.bg.internal.uml.actions.BGAssignToGlossary" 
          enablesFor="+" 
          icon="icons/assign.png" 
          id="com.ibm.bg.internal.uml.actions.BGAssignToGlossary" 
          label="%BGAssignToGlossary.item" 
          menubarPath="com.ibm.bg.uml.popupMenuGroup"> 
       </action> 
      </objectContribution> 
     </extension> 

      菜單控制

      視圖菜單的控制主要包括啟用 / 禁用,顯示 / 隱藏菜單。

      通過 Command 方式創建的菜單,可以通過 org.eclipse.ui.commands 的 visibleWhen 屬性控制菜單的隱藏和顯示,通過 org.eclipse.ui.handlers 的 activewhen 或 enabledWhen 控制菜單的啟用或禁用。

      通過 Actions 方式創建的菜單,可以通過 action 的 enablement 屬性控制菜單的啟用 / 禁用。

      通過 popupMenus 方式創建的菜單,可以通過 objectContribution 的 visibility 和 enablement 來設置該 objectContribution 下的 action 的顯示 / 隱藏和啟用 / 禁用,我們也可以設置 action 的 enablement 來控制該菜單的啟用 / 禁用。

      這里不詳細講述 enablement,visibleWhen 和 enabledWhen 的參數及如何設置,讀者可以參考第三節的例子和本文的參考文獻。

      編程實踐

      本文將結合前兩節講到的知識,以例子的形式說明如何創建并且控制菜單。首先創建一個視圖(Menu Example),然后分別通過 Commands,Actions 和 popupMenus 方式創建若干個菜單,并添加相應的菜單控制點。

      創建 Menu Example 視圖

      擴展 org.eclipse.views 創建“Menu Example”視圖,如下代碼清單 5 為創建視圖的 xml 代碼。

    清單 5. 擴展 org.eclipse.ui.views 創建視圖

     <extension 
       point="org.eclipse.ui.views"> 
      <category 
         id="com.free.menu.category" 
         name="Menu Example View"> 
      </category> 
      <view 
         category="com.free.menu.category" 
         class="com.free.menu.view.MenuExplorer" 
         id="com.free.menu.view.MenuExplorer" 
         name="Menu Explorer" 
         restorable="true"> 
      </view> 
     </extension> 

      創建 Commands

      采用 Command 方式創建“Menu Example”主菜單(包含 AngryCommand 和 JokeCommand 兩個菜單項),并且基于這兩個菜單項創建了 Menu Example 視圖的下拉菜單和工具欄菜單,及其 TreeViewer 的上下文菜單。

      如下代碼清單 6 為擴展 org.eclipse.ui.commands 創建 Menu Example 命令和類別,并且包含兩個命令:Joke Command 和 Angry Command。

    清單 6. 擴展 org.eclipse.ui.commands 創建命令

     <extension 
       point="org.eclipse.ui.commands"> 
      <category 
         id="com.free.menu.category" 
         name="Menu Example"> 
      </category> 
      <command 
         categoryId="com.free.menu.category" 
         id="com.free.menu.commands.jokeCommand" 
         name="Joke Command"> 
      </command> 
      <command 
         categoryId="com.free.menu.category" 
         id="com.free.menu.commands.angryCommand" 
         name="Angry Command"> 
      </command> 
     </extension> 

      關聯 Commands 到主菜單

      如下代碼清單 7 為擴展 org.eclipse.ui.menus,并基于前面創建的 Comands,添加一個主菜單 Menu Example,并且包含 Joke Command 和 Angry Command 菜單項。

    清單 7. 創建 Menu Example 主菜單

     <menuContribution 
       locationURI="menu:org.eclipse.ui.main.menu?after=additions"> 
      <menu 
       id="com.free.menu.MenuExample" 
         label="Menu Example"> 
       <command 
          commandId="com.free.menu.commands.jokeCommand" 
          style="push"> 
       </command> 
       <command 
          commandId="com.free.menu.commands.angryCommand" 
          style="push"> 
       </command> 
      </menu> 
     </menuContribution> 

      Commands 的實現類

      如下代碼清單 9 所示擴展 org.eclipse.ui.handlers 為 Joke Command 和 Angry Command 創建事件處理類,其中 Joke Command 通過 enabledWhen 屬性控制該菜單項是否啟用,當我們同時選擇了兩個對象時 Joke Command 處于啟用狀態,否則為禁用。

    清單 9. 擴展 org.eclipse.ui.handlers 為 Commands 創建實現類

     <extension 
       point="org.eclipse.ui.handlers"> 
      <handler 
         class="com.free.menu.actions.JokeCommand" 
         commandId="com.free.menu.commands.jokeCommand"> 
       <enabledWhen> 
         <count 
            value="2"> 
         </count> 
       </enabledWhen> 
      </handler> 
      <handler 
         class="com.free.menu.actions.AngryCommand" 
         commandId="com.free.menu.commands.angryCommand"> 
      </handler> 
     </extension> 

      創建 Action 并關聯到 Eclipse 的 Search 主菜單

      采用 Actions 方式在 Eclipse 的主菜單 Search 中添加創建菜單項 SmileAction。擴展 org.eclipse.ui.actionSets 在 Eclipse 的主菜單 Search 中添加一個菜單項 Smile Action。如下代碼清單 10 所示創建該 action 并添加到 search 主菜單,只有當我們選擇至少一個對象時(設置 enablesFor 屬性為“+”),該菜單項才處于啟用狀態。

    清單 10. 通過 Actions 方式創建菜單項

     <extension 
       point="org.eclipse.ui.actionSets"> 
      <actionSet 
         id="com.free.menu.actionSet.MenuExample" 
         label="Menu Example" 
         visible="true"> 
       <action 
          class="com.free.menu.actions.SmileAction" 
          enablesFor="+" 
          icon="icons/searchres.gif" 
          id="com.free.menu.actions.smileAction" 
          label="Smile Action" 
          menubarPath="org.eclipse.search.menu/dialogGroup" 
          style="push"> 
       </action> 
      </actionSet> 
     </extension> 

      pupupMenus 方式創建 Action 并關聯到 IResource 資源的上下文菜單

      擴展 org.eclipse.ui.popupMenus 創建菜單“Menu Example”,該菜單包含一個菜單項 HelloAction。當我們在 Eclipse 任何區域右擊 org.eclipse.core.resources.IResource 資源時彈出的上下文菜單中會出現“Menu Example”菜單。如下代碼清單 11 為創建該上下文菜單的 xml 代碼。

    清單 11. popupMenus 方式創建上下文菜單

     <extension 
       point="org.eclipse.ui.popupMenus"> 
      <objectContribution 
         adaptable="true" 
         id="com.free.menu.popupMenu" 
         objectClass="org.eclipse.core.resources.IResource"> 
       <menu 
          label="Menu Example" 
          path="additions" 
          id="com.free.menu.popupSubMenu"> 
         <separator 
            name="additions"> 
         </separator> 
       </menu> 
       <action 
          label="Hello Action" 
          class="com.free.menu.popup.actions.HelloAction" 
          menubarPath="com.free.menu.popupSubMenu/additions" 
          enablesFor="1" 
          id="com.free.menu.newAction"> 
       </action> 
      </objectContribution> 
     </extension> 

      pupupMenus 方式創建 Action 并關聯到 IResource 資源的上下文菜單

      擴展 org.eclipse.ui.popupMenus 創建菜單項 GreetAction 和 CryAction,當我們右擊 Menu Example 視圖中的 TreeViewer 節點時彈出。如下代碼清單 12 所示擴展 org.eclipse.ui.popupMenus 為 Menu Example 視圖創建 GreetAction 和 CryAction 上下文菜單項。使用 visiblity 的 objectState 屬性控制菜單項的可見狀態,使用該屬性要求其選擇的對象實現了 org.eclipse.ui.IActionFilter 接口,具體可參見 Person 類的實現。

    清單 12. 擴展 org.eclipse.ui.popupMenus 創建菜單

     <extension 
       point="org.eclipse.ui.popupMenus"> 
      <objectContribution 
         adaptable="false" 
         id="com.free.menu.views.popupMenu" 
         objectClass="com.free.menu.model.Person"> 
       <action 
          class="com.free.menu.actions.GreetAction" 
          enablesFor="+" 
          id="com.free.menu.actions.greetAction" 
          label="Greet Action" 
          menubarPath="additions"> 
       </action> 
       <visibility> 
         <objectState 
            name="firstName" 
            value="Dan"> 
         </objectState> 
       </visibility> 
      </objectContribution> 
     </extension> 
     <extension 
       point="org.eclipse.ui.popupMenus"> 
      <objectContribution 
         adaptable="false" 
         id="com.free.menu.views.popupMenu2" 
         objectClass="com.free.menu.model.Person"> 
       <action 
          class="com.free.menu.actions.CryAction" 
          enablesFor="+" 
          id="com.free.menu.actions.cryAction" 
          label="Cry Action" 
          menubarPath="additions"> 
         <enablement> 
          <objectState 
             name="firstName" 
             value="David"> 
          </objectState> 
         </enablement> 
       </action> 
       <visibility> 
         <objectState 
            name="lastName" 
            value="Rubel"> 
        </objectState> 
       </visibility> 
      </objectContribution> 
     </extension> 

      Menu Example 視圖的代碼實現類

      如下代碼清單 13 所示為 Menu Example 視圖的代碼,該視圖中有一個 TreeViewer,并通過函數 hookContextMenu 把上下文菜單關聯到 TreeViewer。其中函數 viewMenuAction 用于更新菜單的狀態,它首先獲取視圖菜單,然后調用 IMenuManager 的 update 方法更新對應菜單項的狀態,從而達到控制菜單的目的。

    清單 13. Menu Example 視圖代碼

     public class MenuExplorer extends ViewPart { 
      private TreeViewer treeViewer; 
      private MenuManager fMenuMgr; 
      private Menu fMenu; 
      private static MenuExplorer fInstance = null; 
      public MenuExplorer() { 
        fInstance = this; 
      } 
      public static MenuExplorer getInstance(){ 
        return fInstance; 
      } 
      public void createPartControl(Composite parent) { 
        treeViewer = new TreeViewer (parent, SWT.MULTI); 
        treeViewer.setLabelProvider(new PersonListLabelProvider()); 
        treeViewer.setContentProvider(new PersonTreeContentProvider()); 
        treeViewer.setInput(Person.example()); 
        this.getSite().setSelectionProvider(treeViewer); 
        hookContextMenu(); 
        fInstance = this; 
         
      } 
      public void setViewMenuActionState(boolean state){     
        JokeCommand.setState(state); 
        viewMenuAction(); 
      } 
      private void viewMenuAction() { 
        IActionBars bars= getViewSite().getActionBars(); 
        final IMenuManager menu= bars.getMenuManager();   
         
        UIOperation.asyncExecCommand(new Runnable(){ 
          public void run() { 
            menu.update("com.free.menu.commands.jokeAction"); 
          }       
        });     
      } 
      private void hookContextMenu() { 
        fMenuMgr = new MenuManager("#PopupMenu"); 
        fMenuMgr.setRemoveAllWhenShown(true); 
        fMenuMgr.addMenuListener(new IMenuListener() { 
          public void menuAboutToShow(IMenuManager manager) {         
          } 
        }); 
        fMenu = fMenuMgr.createContextMenu(treeViewer.getControl()); 
     
        treeViewer.getControl().setMenu(fMenu); 
        getSite().registerContextMenu(fMenuMgr, treeViewer);        
      }   
      public void setFocus() { 
        treeViewer.getTree().setFocus(); 
     
      } 
     } 

      Person 類的實現

      如下代碼清單 14 為 Person 類的實現,用于表示 MenuExample 視圖中 TreeViewer 的一個節點,它實現了 IActionFilter 接口,通過 testAttribute 來確定是否顯示 / 隱藏菜單(其中 target 表示用戶選擇的對象,name/value 對應于 plugin.xml 文件中 objectState 的 name/value).

    清單 14. Person 類實現

     public class Person implements IActionFilter { 
     
      private String firstName = "John"; 
      private String lastName = "Doe"; 
      protected int age = 37; 
      public Person[] children = new Person[0]; 
      public Person parent = null; 
      public Person(String firstName, String lastName, int age) { 
        this.firstName = firstName; 
        this.lastName = lastName; 
        this.age = age; 
      } 
      public Person(String firstName, String lastName, int age, Person[] children) { 
        this(firstName, lastName, age); 
        this.children = children; 
        for (int i = 0; i < children.length; i++) { 
          children[i].parent = this; 
        } 
      } 
      public String getFirstName() { 
        return this.firstName; 
      } 
      public String getLastName() { 
        return this.lastName; 
      } 
      public static Person[] example() { 
        return new Person[] { 
            new Person("Dan", "Rubel", 38, new Person[] { 
                new Person("Beth", "Rubel", 8), 
                new Person("David", "Rubel", 3) }), 
            new Person("Eric", "Clayberg", 39, new Person[] { 
                new Person("Lauren", "Clayberg", 6), 
                new Person("Lee", "Clayberg", 4) }), 
            new Person("Mike", "Taylor", 52) }; 
      } 
      public String toString() { 
        return firstName + " " + lastName; 
      } 
      public boolean testAttribute(Object target, String name, String value) { 
     
        if (target instanceof Person) { 
          Person person = (Person) target; 
          if (name.equals("firstName") && value.equals(person.getFirstName())) { 
            return true; 
          } 
     
          if (name.equals("lastName") && value.equals(person.getLastName())) { 
            return true; 
          } 
        } 
        return false; 
      } 
     } 

      總結

      至此為止,已經把 Eclipse 菜單功能及其擴展點涉及到的類 / 接口 /API 進行了詳細的說明,相信讀者已經有清晰的認識了。對于前面提到 popupMenus 方式創建上下文菜單,要求選擇的對象實現 IActionFilter 接口,但是,如果開發人員正在使用 gmf 進行開發,那么我們可以不必要求選擇的對象實現 IActionFilter,我們可以通過擴展 org.eclipse.gmf.runtime.common.ui.services.action.actionFilterProviders 對菜單項進行控制,如下代碼清單 15 為擴展該 extension point 的 xml 代碼,我們可以定義多個屬性(<Attribute> … </Attribute),其中 Attribute 的 name 和 value 對應于 visibility 的 objectState 中的 name 和 value。

    清單 15. 通過 actionFilterProviders 擴展點實現對菜單的控制

     <extension 
     point="org.eclipse.gmf.runtime.common.ui.services.action.actionFilterProviders"> 
       <ActionFilterProvider 
          class="com.free.menu.PopupActionFilterProvider"> 
        <Priority 
           name="Medium"> 
        </Priority> 
        <Attribute 
           name="com.ibm.bg.uml.search.isSupportedType" 
           value="supported"> 
        </Attribute> 
       </ActionFilterProvider> 
     </extension> 

      如下代碼清單 16 所示 PopupActionFilterProvider 的實現,它繼承 AbstractActionFilterProvider,只需要實現其中的 testAttribute 和 provides 方法,當 testAttribute 返回 true 時,那么該菜單項被啟用,否則禁用。其中 target 對應于我們選擇的對象,name 和 value 參數對應于 visiblity 中 objectState 的 name 和 value 的指定值 ( 與前面提到的 Person 類中的 testAttribute 方法類似 )。


    清單 16. actionFilterProviders 擴展點實現類

     public class PopupActionFilterProvider extends AbstractActionFilterProvider { 
     
     
      public PopupActionFilterProvider() { 
      } 
     
      public boolean testAttribute(Object target, String name, String value) { 
           
      } 
     
      public boolean provides(IOperation operation) { 
        return false; 
      } 
     
     }

     

     

     

    posted @ 2010-07-03 16:00 笑看人生 閱讀(1846) | 評論 (0)編輯 收藏

    擴展點:
    org.eclipse.ui.menus(確定菜單創建的區域)
    org.eclipse.ui.commands
    org.eclipse.ui.handlers(command的具體行為)
    org.eclipse.ui.commandImages(comand的圖片)

    擴展點org.eclipse.ui.menus用來對菜單進行擴展,可以對主菜單,工具欄,上下文菜單進行擴展。

    示例代碼如下:
    <extension
             
    point="org.eclipse.ui.menus">
          
    <menuContribution
                
    allPopups="false"
                locationURI
    ="menu:org.eclipse.ui.main.menu?after=additions">
             
    <command
                   
    commandId="com.xxxx.test.command1"
                   style
    ="push">
             
    </command>
          
    </menuContribution>
    </extension>

    其中locationURI屬性指定菜單擴展的位置,上述代碼是對主菜單進行擴展,如果要對工具欄和上下文菜單進行擴展,書寫格式如下:

    toolbar:org.eclipse.ui.main.toolbar?after=additions
    popup:org.eclipse.ui.popup.any?after=additions(上下文菜單在任何位置出現)
    popup:org.eclipse.ui.views.ProblemView?after=additions(上下文菜單在問題視圖中出現)

    commandId屬性指定該menu對應的command,一個menu可以對應多個command。

    command可以通過擴展點org.eclipse.ui.commands擴展,示例代碼如下:

    <extension
             
    point="org.eclipse.ui.commands">
    <category
                
    id="com.xxxx.test.category1"
                name
    ="MenuTest">
          
    </category>

          
    <command
    categoryId="="com.xxxx.test.category1"
                id
    ="com.xxxx.test.command1"
                name
    ="CommandA">
          
    </command>
     
    </extension>

    至于Command具體要做什么,需要通過擴展點org.eclipse.ui.handlers來指定,示例代碼如下:

    <extension
             
    point="org.eclipse.ui.handlers">
          
    <handler
                
    class="com.xxxx.test.SampleHandler"
                commandId
    ="com.xxxx.test.command1">
          
    </handler>
     
    </extension>

    還有擴展點org.eclipse.ui.commandImages,可以指定Command對應的圖標。

     <extension
             
    point="org.eclipse.ui.commandImages">
          
    <image
                
    commandId="com.xxxx.test.command1"
                icon
    ="icons/sample.gif">
          
    </image>
      
    </extension>

    posted @ 2010-07-03 15:55 笑看人生 閱讀(2783) | 評論 (0)編輯 收藏

    擴展點:org.eclipse.core.runtime.preferences
    功能:該擴展點主要用來設置首選項的初始值;

    擴展點示例:

    <extension
             
    point="org.eclipse.core.runtime.preferences">
          
    <initializer
                
    class="com.xxxx.test.AbstractPreferenceInitializer1">
          
    </initializer>
    </extension>

    initializer指定設置首選項初始值的類,示例代碼如下:

    public class AbstractPreferenceInitializer1 extends
            AbstractPreferenceInitializer 
    {    
        @Override
        
    public void initializeDefaultPreferences() {
            IPreferenceStore prefs 
    = Activator.getDefault().getPreferenceStore();
            prefs.setDefault(
    "MAX"1000);
        }

    }


    上述代碼設置屬性MAX的初始值為1000,這個屬性就可以被首選項使用了。

    使用擴展點org.eclipse.ui.preferencePages擴展首選項

    擴展點示例:

    <extension
             
    point="org.eclipse.ui.preferencePages">
          
    <page
                
    class="com.xxxx.test.WorkbenchPreferencePage1"
                id
    ="com.xxxx.test.page1"
                name
    ="testName">
          
    </page>
    </extension>

    這樣就可以在WorkbenchPreferencePage1類中使用剛才定義的屬性MAX了,示例代碼如下:

    public class WorkbenchPreferencePage1 extends FieldEditorPreferencePage implements
            IWorkbenchPreferencePage 
    {

        
    public void init(IWorkbench workbench) {
            setPreferenceStore(Activator.getDefault().getPreferenceStore());        
        }

        @Override
        
    protected void createFieldEditors() {
            
    int max = getPreferenceStore().getDefaultInt("MAX");    
            System.out.println(
    ""+max);
        }
        
    }


    posted @ 2010-07-03 15:22 笑看人生 閱讀(2608) | 評論 (0)編輯 收藏

    原址地址:http://hi.baidu.com/dangjun625/blog/item/a0732c0845181ddc63d98666.html

    MyEclipse has detected that less than 5% of the 64MB of Perm
    Gen (Non-heap memory) space remains. It is strongly recommended
    that you exit and restart MyEclipse with new virtual machine memory
    paramters to increase this memory.   Failure to do so can result in
    data loss. The recommended Eclipse memory parameters are:
    eclipse.exe -vmargs -Xms128M -Xmx512M -XX:PermSize=64M -XX:MaxPermSize=128M

    eclipse根目錄下面的 eclipse.ini 配置 從網上搜了些資料

    -vmargs:說明后面是VM的參數
    -Xms128m:虛擬機占用系統的最小內存
    -Xmx512m:虛擬機占用系統的最大內存的5%為25.6M,理論上要求-Xmx的數值與-XX:MaxPermSize必須大于25.6M
    -XX:PermSize:最小堆大小。一般報內存不足時,都是說這個太小, 堆空間剩余小于5%就會警告,建議把這個稍微設大一點,不過要視自己機器內存大小來設置
    -XX:MaxPermSize:最大堆大小。這個也適當大些

    把里面的參數改為
    -vmargs  
    -Xms128M  
    -Xmx512M  
    -XX:PermSize=128M  
    -XX:MaxPermSize=256M
    問題解決!

    從網上的資料看PermSize大一點肯定更好,而且最好是設置PermSize和MaxPermSize一樣大。理由如下:
    PermSize 和MaxPermSize如果設置為相同還可以在一定程度上提高性能,因為,PermSize在不斷的變化中會需要轉移其中的數據。如果固定了以后,則可以減少每次擴大PermSize帶來的性能損失。

    1、PermGen space簡介
      
      PermGen space的全稱是Permanent Generation space,是指內存的永久保存區域OutOfMemoryError: PermGen space從表面上看就是內存益出,解決方法也一定是加大內存。
      
      說說為什么會內存益出:
      (1)這一部分用于存放Class和Meta的信息,Class在被 Load的時候被放入PermGen space區域,它和和存放Instance的Heap區域不同。
     ?。?) GC(Garbage Collection)不會在主程序運行期對PermGen space進行清理,所以如果你的APP會LOAD很多CLASS 的話,就很可能出現PermGen space錯誤。這種錯誤常見在web服務器對JSP進行pre compile的時候。
      
      如果你的WEB APP下都用了大量的第三方jar,其大小超過了jvm默認的大小(4M)那么就會產生此錯誤信息了。

    解決方法: 手動設置MaxPermSize大小
      
      修改TOMCAT_HOME/bin/catalina.bat,在echo "Using CATALINA_BASE: $CATALINA_BASE"上面加入以下行:
       JAVA_OPTS="-server -XX:PermSize=64M -XX:MaxPermSize=128m
      建議:將相同的第三方jar文件移置到tomcat/shared/lib目錄下,這樣可以減少jar 文檔重復占用內存

    1。參數的含義

    -vmargs -Xms128M -Xmx512M -XX:PermSize=64M -XX:MaxPermSize=128M

    參數中-vmargs的意思是設置JVM參數,所以后面的其實都是JVM的參數了,我們首先了解一下JVM內存管理的機制,然后再解釋每個參數代表的含義。
    堆(Heap)和非堆(Non-heap)內存
    按照官方的說法:“Java 虛擬機具有一個堆,堆是運行時數據區域,所有類實例和數組的內存均從此處分配。堆是在 Java 虛擬機啟動時創建的。”“在JVM中堆之外的內存稱為非堆內存(Non-heap memory)”??梢钥闯鯦VM主要管理兩種類型的內存:堆和非堆。簡單來說堆就是Java代碼可及的內存,是留給開發人員使用的;非堆就是JVM留給自己用的,所以方法區、JVM內部處理或優化所需的內存(如JIT編譯后的代碼緩存)、每個類結構(如運行時常數池、字段和方法數據)以及方法和構造方法的代碼都在非堆內存中。
    堆內存分配
    JVM初始分配的內存由-Xms指定,默認是物理內存的1/64;JVM最大分配的內存由-Xmx指定,默認是物理內存的1/4。默認空余堆內存小于40%時,JVM就會增大堆直到-Xmx的最大限制;空余堆內存大于70%時,JVM會減少堆直到-Xms的最小限制。因此服務器一般設置-Xms、-Xmx相等以避免在每次GC 后調整堆的大小。
    非堆內存分配
    JVM使用-XX:PermSize設置非堆內存初始值,默認是物理內存的1/64;由XX:MaxPermSize設置最大非堆內存的大小,默認是物理內存的1/4。
    JVM內存限制(最大值)
    首先JVM內存限制于實際的最大物理內存,假設物理內存無限大的話,JVM內存的最大值跟操作系統有很大的關系。簡單的說就32位處理器雖然可控內存空間有4GB,但是具體的操作系統會給一個限制,這個限制一般是2GB-3GB(一般來說Windows系統下為1.5G-2G,Linux系統下為2G-3G),而64bit以上的處理器就不會有限制了。

    2. 為什么有的機器我將-Xmx和-XX:MaxPermSize都設置為512M之后Eclipse可以啟動,而有些機器無法啟動?

    通過上面對JVM內存管理的介紹我們已經了解到JVM內存包含兩種:堆內存和非堆內存,另外JVM最大內存首先取決于實際的物理內存和操作系統。所以說設置VM參數導致程序無法啟動主要有以下幾種原因:
    1) 參數中-Xms的值大于-Xmx,或者-XX:PermSize的值大于-XX:MaxPermSize;
    2) -Xmx的值和-XX:MaxPermSize的總和超過了JVM內存的最大限制,比如當前操作系統最大內存限制,或者實際的物理內存等等。說到實際物理內存這里需要說明一點的是,如果你的內存是1024MB,但實際系統中用到的并不可能是1024MB,因為有一部分被硬件占用了。

    3. 為何將上面的參數寫入到eclipse.ini文件Eclipse沒有執行對應的設置?
    那為什么同樣的參數在快捷方式或者命令行中有效而在eclipse.ini文件中是無效的呢?這是因為我們沒有遵守eclipse.ini文件的設置規則:
    參數形如“項 值”這種形式,中間有空格的需要換行書寫,如果值中有空格的需要用雙引號包括起來。比如我們使用-vm C:\Java\jre1.6.0\bin\javaw.exe參數設置虛擬機,在eclipse.ini文件中要寫成這樣:
    -vm
    C:\Java\jre1.6.0\bin\javaw.exe
    按照上面所說的,最后參數在eclipse.ini中可以寫成這個樣子:
    -vmargs
    -Xms128M
    -Xmx512M
    -XX:PermSize=64M
    -XX:MaxPermSize=128M
    實際運行的結果可以通過Eclipse中“Help”-“About Eclipse SDK”窗口里面的“Configuration Details”按鈕進行查看。
    另外需要說明的是,Eclipse壓縮包中自帶的eclipse.ini文件內容是這樣的:
    -showsplash
    org.eclipse.platform
    --launcher.XXMaxPermSize
    256m
    -vmargs
    -Xms40m
    -Xmx256m
    其中–launcher.XXMaxPermSize(注意最前面是兩個連接線)跟-XX:MaxPermSize參數的含義基本是一樣的,我覺得唯一的區別就是前者是eclipse.exe啟動的時候設置的參數,而后者是eclipse所使用的JVM中的參數。其實二者設置一個就可以了,所以這里可以把–launcher.XXMaxPermSize和下一行使用#注釋掉。

    3. 其他的啟動參數。 如果你有一個雙核的CPU,也許可以嘗試這個參數:

    -XX:+UseParallelGC

    讓GC可以更快的執行。(只是JDK 5里對GC新增加的參數)

     

    補充:

    可以在myelipse里選中相應的服務器比如tomcat5,展開里面的JDK子項頁面,來增加服務器啟動的JVM參數設置:

    -Xms128m
    -Xmx256m
    -XX:PermSize=128M
    -XX:MaxNewSize=256m
    -XX:MaxPermSize=256m

    posted @ 2010-06-26 21:37 笑看人生 閱讀(531) | 評論 (0)編輯 收藏

    Ajax中的XMLHttpRequest對象提供了兩個屬性來訪問服務器端相應。

    • responseText:將相應作為一個字符串返回;(系列一中已經介紹)
    • responseXML:將相應作為一個XML對象返回;(本系列中介紹)
    本節要介紹的內容,很多人應該比較熟悉,比如在網上注冊時,在“省”列表框中選擇不同的省份,對應的“市”列表框中出現該省的所有市,這個過程,不用刷新整個頁面。

    要實現這個功能,只須修改一下系列一中的index.jsp和AjaxServlet.java這兩個文件。

    index.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding
    ="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>

    <script language="javascript">
        
    var xmlHttp;
        
    function refresh() {
            xmlHttp 
    = createXMLHttpRequest();
            
    var url = "AjaxServlet?province="
                    
    + document.getElementById("province").value;
            xmlHttp.open(
    "GET", url);
            xmlHttp.onreadystatechange 
    = handleStateChange;
            xmlHttp.send(
    null);
        }

        
    function handleStateChange() {
            
    if (xmlHttp.readyState == 4) {
                
    if (xmlHttp.status == 200) {
                    updateCity();
                }
            }
        }

        
    function updateCity() {
            clearCity();
            
    var city = document.getElementById("city");
            
    var cities = xmlHttp.responseXML.getElementsByTagName("city");        
            
    for(var i=0;i<cities.length;i++){
                option 
    = document.createElement("option");
                option.appendChild(document.createTextNode(cities[i].firstChild.nodeValue));
                city.appendChild(option);                        
            }
        }

        
    function clearCity() {        
            
    var city = document.getElementById("city");
            
    while(city.childNodes.length > 0) {
                city.removeChild(city.childNodes[
    0]);
            }                    
        }
        
        
    function createXMLHttpRequest() {
            
    if (window.ActiveXObject) {
                xmlHttp 
    = new ActiveXObject("Microsoft.XMLHTTP");
            } 
    else if (window.XMLHttpRequest) {
                xmlHttp 
    = new XMLHttpRequest();
            }
            
    return xmlHttp;
        }
    </script>

    <body>
    <form action="#"><select id="province" onchange="refresh()">
        
    <option value="">Select One</option>
        
    <option value="jiangsu">Jiang Su</option>
        
    <option value="zhejiang">Zhe Jiang</option>
    </select> <br>
    <br>
    <br>
    <select id="city"></select></form>
    </body>

    </html>

    AjaxServlet.java

    package servlet;

    import java.io.IOException;
    import java.io.PrintWriter;

    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    public class AjaxServlet extends HttpServlet {

        
    private static final long serialVersionUID = 7032718233562299325L;

        @Override
        
    protected void doPost(HttpServletRequest req, HttpServletResponse response)
                
    throws ServletException, IOException {
            processRequest(req, response, 
    "POST");
        }

        @Override
        
    protected void doGet(HttpServletRequest req, HttpServletResponse response)
                
    throws ServletException, IOException {
            processRequest(req, response, 
    "GET");
        }

        
    private void processRequest(HttpServletRequest req,
                HttpServletResponse response, String method) 
    throws IOException {
            String province 
    = req.getParameter("province");
            StringBuffer cities 
    = new StringBuffer("<cities>");
            
            
    if("jiangsu".equals(province)){
                cities.append(
    "<city>Nanjing</city>");
                cities.append(
    "<city>Zhenjiang</city>");
            }
    else if("zhejiang".equals(province)){
                cities.append(
    "<city>Hanzhou</city>");
                cities.append(
    "<city>Wenzhou</city>");
            }        
            
            PrintWriter writer 
    = response.getWriter();    
            cities.append(
    "</cities>");
            response.setContentType(
    "text/xml");
            writer.write(cities.toString());
            writer.close();
        }
    }




    posted @ 2009-11-15 09:28 笑看人生 閱讀(246) | 評論 (0)編輯 收藏

    簡單介紹一下Ajax應用程序的基本流程:

    1. 創建XMLHttpRequest對象;
    2. 從頁面中獲取獲取需要的數據;
    3. 建立要連接的URL;
    4. 打開與服務器的連接;
    5. 設置服務器相應之后要調用的函數,即回調函數;
    6. 發送請求;
    下面以一個簡單的例子來演示一下,該例子要完成的功能是使用Ajax技術對輸入的EMail地址進行簡單校驗,根據校驗的結果,在頁面顯示相應的消息。

    index.jsp

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding
    ="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Insert title here</title>
    </head>

    <script language="javascript">
          
    var xmlHttp;  
         
    function sendreq(){  
           xmlHttp 
    = createXMLHttpRequest();  //步驟1
           
    var url = "AjaxServlet?email=" + document.getElementById("email").value;//步驟2,3
           xmlHttp.open(
    "GET", url);  //步驟4
           xmlHttp.onreadystatechange 
    = handleStateChange; //步驟5
           xmlHttp.send(
    null);    //步驟6
        }  
         
    function handleStateChange(){       
          
    if(xmlHttp.readyState == 4){  
             
    if(xmlHttp.status == 200){             
                 document.getElementById(
    "result").innerHTML=xmlHttp.responseText;  
             }  
           }  
         }  
         
    function createXMLHttpRequest(){  
             
    if (window.ActiveXObject){  
                 xmlHttp 
    = new ActiveXObject("Microsoft.XMLHTTP");  
             }  
             
    else if (window.XMLHttpRequest){  
                 xmlHttp 
    = new XMLHttpRequest();  
             }  
             
    return xmlHttp;  
         }  
        
        
    </script>
    <body>
      
    <label id="result">&nbsp;</label><br>
      Email:
    <input type="text" id="email" onblur="sendreq()" value="" />  
      
    <label id="result">&nbsp;</label>
      
    </body>
    </html>

    AjaxServlet.java

    package servlet;

    import java.io.IOException;
    import java.io.PrintWriter;

    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    public class AjaxServlet extends HttpServlet {

        
    private static final long serialVersionUID = 7032718233562299325L;

        @Override
        
    protected void doPost(HttpServletRequest req, HttpServletResponse response)
                
    throws ServletException, IOException {
            processRequest(req, response, 
    "POST");
        }

        @Override
        
    protected void doGet(HttpServletRequest req, HttpServletResponse response)
                
    throws ServletException, IOException {
            processRequest(req, response, 
    "GET");
        }

        
    private void processRequest(HttpServletRequest req,
                HttpServletResponse response, String method) 
    throws IOException {
            String email 
    = req.getParameter("email");
            StringBuffer validator 
    = new StringBuffer("");
            validator.append(method);
            response.setContentType(
    "text/html;charset=UTF-8");
            PrintWriter writer 
    = response.getWriter();
            
    if (email.indexOf("@"< 0) {
                validator.append(
    ":FAILURE!");
            }
    else{
                validator.append(
    ":SUCCESS!");
            }
            writer.write(validator.toString());
            writer.close();
        }
    }

    GET和POST請求方式區別:

    • POST方法將參數串放在請求體中發送;
    • GET方法將參數串放在URL中發送;

    如果數據處理不改變數據模型的狀態,建議使用GET方式,如果需要改變數據模型的狀態,建議使用POST方式;

    web.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4"
        xmlns
    ="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation
    ="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
        
    <display-name>ajax</display-name>
        
    <welcome-file-list>
            
    <welcome-file>index.jsp</welcome-file>
        
    </welcome-file-list>
        
    <servlet>
            
    <servlet-name>AjaxServlet</servlet-name>
            
    <servlet-class>servlet.AjaxServlet</servlet-class>
        
    </servlet>
        
    <servlet-mapping>
            
    <servlet-name>AjaxServlet</servlet-name>
            
    <url-pattern>/AjaxServlet</url-pattern>
        
    </servlet-mapping>
    </web-app>


    posted @ 2009-11-01 12:31 笑看人生 閱讀(325) | 評論 (0)編輯 收藏

    最近在升級JDK版本后,啟動Eclipse時候,遇到這樣的問題:
    JVM terminated.Exit code=1.
    在網上找了些資料,找到了解決方法。
    只要修改eclipse.ini文件即可。修改內容如下:
    -startup
    plugins\org.eclipse.equinox.launcher_1.0.100.v20080509-1800.jar
    --launcher.library
    plugins\org.eclipse.equinox.launcher.win32.win32.x86_1.0.100.v20080509-1800
    -showsplash
    vm
    D:\Java\jdk15011\bin\javaw.exe
    org.eclipse.platform
    --launcher.XXMaxPermSize
    256m
    -vmargs
    -Xms40m
    -Xmx256m
    其中粗體部分為新增內容。

    posted @ 2008-07-27 21:22 笑看人生 閱讀(11639) | 評論 (4)編輯 收藏

     

    問題描述:

    最近在做Eclipse插件開發的時候,在國際化的問題上遇到這樣問題,比如我的plugin.xml文件中,通過%xxx來引用plugin_zh.properties中對應鍵xxx的信息時,在插件運行時,相應的信息顯示不了,后來進過研究,發現是由于在MANIFEST.MF少配置了一項造成的

    Bundle-Localization: plugin,

    而這一項配置我在Overview標簽頁上沒有找到相應設置的地方,把這個在MANIFEST.MF加上,插件在運行時,就可以顯示plugin_zh.properties中定義的消息了。

    posted @ 2008-04-23 19:44 笑看人生 閱讀(1610) | 評論 (0)編輯 收藏

      問題描述:

    最近在Eclipse插件開發中遇到這樣的問題,我使用如入擴展點

    <extension
           
    point="org.eclipse.debug.ui.launchConfigurationTabs">
        
    <tab
              
    class="com.example.launch.SqlDebugTab"
              group
    ="org.eclipse.jdt.debug.ui.launchConfigurationTabGroup.localJavaApplication"
              id
    =" com.example.launchs.SqlDebugTab"
              name
    ="SqlDebugTab">
           
    <associatedDelegate
                 
    delegate=" com.example.launch.SqlDebugLaunchDelegate">
           
    </associatedDelegate>
        
    </tab>
     
    </extension>

    <extension
              
    point="org.eclipse.debug.core.launchDelegates">
           
    <launchDelegate
                 
    delegate=" com.example.launch.SqlDebugLaunchDelegate"
                 id
    =" com.example.launch.SqlDebugLaunchDelegate"
                 modes
    ="debug"
                 type
    ="org.eclipse.jdt.launching.localJavaApplication">
           
    </launchDelegate>
        
    </extension>

     

    也就是在調式Java Application的對話框中,增加一個Tab頁,Tab頁的名字為SqlDebugTab,在這個Tab頁上增加幾個復選框,復選框要顯示視圖的名稱,如果用戶選擇某個復選框,點“Debug”后,將顯示指定的視圖,可是在com.example.launch.SqlDebugLaunchDelegate類中的launch方法中調用PlatformUI.getWorkbench().getActiveWorkbenchWindow(),得到的對象卻為null,調試程序才發現,運行com.example.launch.SqlDebugLaunchDelegate類是,走的是新線程,也就是說點“Debug”按鈕時,Eclipse平臺啟動的是新的線程(非UI線程),而在新線程中是取不到ActiveWorkbenchWindow對象,為了解決這個問題,花費了很多時間,最后終于找到解決方法,launch方法通過如下程序來顯示視圖,就可以解決上面遇到的問題:

    PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
                
    public void run() {
                    IWorkbenchWindow window 
    = PlatformUI.getWorkbench()
                            .getActiveWorkbenchWindow();
                    
    if (window != null){
                        window.getActivePage().showView(
    "……");
    }

    }

    }

    posted @ 2008-04-23 19:41 笑看人生 閱讀(2159) | 評論 (1)編輯 收藏

    主站蜘蛛池模板: 麻豆精品成人免费国产片| 亚洲人成网站色在线入口| 中文字幕免费人成乱码中国| 久久久久久亚洲精品影院| 免费的黄色的网站| 日本一道一区二区免费看 | 久久国产乱子伦免费精品| 成人免费夜片在线观看| 久久亚洲精品国产亚洲老地址| 亚洲国产精品自在线一区二区 | 四虎影视永久在线精品免费| 77777亚洲午夜久久多喷| 久久久久亚洲精品无码蜜桃| 亚洲av永久无码精品古装片| 亚洲日本中文字幕天堂网| 免费国产精品视频| 免费鲁丝片一级在线观看| 亚洲高清中文字幕免费| 亚洲一级毛片免费在线观看| 免费人妻无码不卡中文字幕系| 热久久这里是精品6免费观看| 一级毛片在线播放免费| 免费精品国产自产拍在线观看| 亚洲AV第一成肉网| 朝桐光亚洲专区在线中文字幕| 亚洲精品无码久久久久久| 中文字幕亚洲情99在线| 亚洲国产日韩视频观看| 亚洲熟伦熟女专区hd高清| 亚洲国产精品一区二区三区在线观看| 亚洲免费福利视频| 亚洲欧美日韩综合俺去了| 亚洲日韩国产一区二区三区在线| 亚洲欧洲国产综合AV无码久久| 亚洲色大成网站www| 亚洲爆乳少妇无码激情| 亚洲AV第一成肉网| 丰满妇女做a级毛片免费观看| 久久久久国色AV免费观看| a级毛片毛片免费观看永久| 国产免费一区二区视频|