When there is HTML/Java project, clicking on 'Develop' should open the project wizard nbrwsr
authorJaroslav Tulach <jtulach@netbeans.org>
Mon, 08 Sep 2014 17:15:18 +0200
branchnbrwsr
changeset 2089073c01ba497
parent 207 caac10b379ae
child 209 daed0ea9470b
When there is HTML/Java project, clicking on 'Develop' should open the project wizard
minesweeper/pom.xml
minesweeper/src/main/java/org/apidesign/demo/minesweeper/MinesModel.java
minesweeper/src/main/webapp/pages/index.html
minesweeper/src/main/webapp/pages/index_cs.html
     1.1 --- a/minesweeper/pom.xml	Mon Sep 08 17:13:40 2014 +0200
     1.2 +++ b/minesweeper/pom.xml	Mon Sep 08 17:15:18 2014 +0200
     1.3 @@ -582,6 +582,34 @@
     1.4                    <version>${nb.html.version}</version>
     1.5                    <scope>compile</scope>
     1.6                </dependency>
     1.7 +              <dependency>
     1.8 +                  <artifactId>org-openide-filesystems</artifactId>
     1.9 +                  <groupId>org.netbeans.api</groupId>
    1.10 +                  <type>jar</type>
    1.11 +                  <version>RELEASE80</version>
    1.12 +                  <scope>compile</scope>
    1.13 +              </dependency>
    1.14 +              <dependency>
    1.15 +                  <artifactId>org-openide-awt</artifactId>
    1.16 +                  <groupId>org.netbeans.api</groupId>
    1.17 +                  <type>jar</type>
    1.18 +                  <version>RELEASE80</version>
    1.19 +                  <scope>compile</scope>
    1.20 +              </dependency>
    1.21 +              <dependency>
    1.22 +                  <artifactId>org-openide-util</artifactId>
    1.23 +                  <groupId>org.netbeans.api</groupId>
    1.24 +                  <type>jar</type>
    1.25 +                  <version>RELEASE80</version>
    1.26 +                  <scope>compile</scope>
    1.27 +              </dependency>
    1.28 +              <dependency>
    1.29 +                  <artifactId>org-openide-util-lookup</artifactId>
    1.30 +                  <groupId>org.netbeans.api</groupId>
    1.31 +                  <type>jar</type>
    1.32 +                  <version>RELEASE80</version>
    1.33 +                  <scope>compile</scope>
    1.34 +              </dependency>
    1.35            </dependencies>
    1.36            <build>
    1.37                <plugins>
     2.1 --- a/minesweeper/src/main/java/org/apidesign/demo/minesweeper/MinesModel.java	Mon Sep 08 17:13:40 2014 +0200
     2.2 +++ b/minesweeper/src/main/java/org/apidesign/demo/minesweeper/MinesModel.java	Mon Sep 08 17:15:18 2014 +0200
     2.3 @@ -23,15 +23,28 @@
     2.4   */
     2.5  package org.apidesign.demo.minesweeper;
     2.6  
     2.7 +import java.awt.event.ActionEvent;
     2.8 +import java.net.MalformedURLException;
     2.9 +import java.net.URL;
    2.10  import java.util.ArrayList;
    2.11  import java.util.List;
    2.12  import java.util.Random;
    2.13 +import java.util.logging.Level;
    2.14 +import java.util.logging.Logger;
    2.15 +import javax.swing.Action;
    2.16  import net.java.html.json.ComputedProperty;
    2.17  import net.java.html.json.Function;
    2.18  import net.java.html.json.Model;
    2.19  import net.java.html.json.ModelOperation;
    2.20  import net.java.html.json.Property;
    2.21  import net.java.html.sound.AudioClip;
    2.22 +import org.openide.awt.HtmlBrowser;
    2.23 +import org.openide.filesystems.FileObject;
    2.24 +import org.openide.filesystems.FileUtil;
    2.25 +import org.openide.util.ContextAwareAction;
    2.26 +import org.openide.util.Exceptions;
    2.27 +import org.openide.util.Lookup;
    2.28 +import org.openide.util.Utilities;
    2.29  
    2.30  /** Model of the mine field.
    2.31   */
    2.32 @@ -114,6 +127,42 @@
    2.33          }
    2.34      }
    2.35      
    2.36 +    private static final Logger LOG = Logger.getLogger(MinesModel.class.getName());
    2.37 +    @Function static void develop(Mines model) {
    2.38 +        Action a = null;
    2.39 +        try {
    2.40 +            ClassLoader l = Lookup.getDefault().lookup(ClassLoader.class);
    2.41 +            if (l == null) {
    2.42 +                l = Thread.currentThread().getContextClassLoader();
    2.43 +            }
    2.44 +            if (l == null) {
    2.45 +                l = MinesModel.class.getClassLoader();
    2.46 +            }
    2.47 +            Class<?> newPrj = Class.forName("org.netbeans.spi.project.ui.support.CommonProjectActions", true, l); // NOI18N
    2.48 +            a = (Action) newPrj.getMethod("newProjectAction").invoke(null); // NOI18N
    2.49 +        } catch (Exception ex) {
    2.50 +            LOG.log(Level.FINE, "Cannot find New project action!", ex);
    2.51 +        }
    2.52 +        if (a != null) {
    2.53 +            FileObject fo = FileUtil.getConfigFile("Templates/Project/ClientSide"); // NOI18N
    2.54 +            if (fo != null) {
    2.55 +                a.putValue("PRESELECT_CATEGORY", "ClientSide"); // NOI18N
    2.56 +                for (FileObject template : fo.getChildren()) {
    2.57 +                    if (template.getName().contains("htmljava")) { // NOI18N
    2.58 +                        a.putValue("PRESELECT_TEMPLATE", template.getName()); // NOI18N
    2.59 +                        a.actionPerformed(new ActionEvent(model, 0, null));
    2.60 +                        return;
    2.61 +                    }
    2.62 +                }
    2.63 +            }
    2.64 +        } 
    2.65 +        try {
    2.66 +            HtmlBrowser.URLDisplayer.getDefault().showURL(new URL("http://wiki.apidesign.org/wiki/DukeScriptInNetBeans")); // NO18N
    2.67 +        } catch (MalformedURLException ex) {
    2.68 +            Exceptions.printStackTrace(ex);
    2.69 +        }
    2.70 +    }
    2.71 +    
    2.72      @ModelOperation static void init(Mines model, int width, int height, int mines) {
    2.73          List<Row> rows = model.getRows();
    2.74          if (rows.size() != height || rows.get(0).getColumns().size() != width) {
     3.1 --- a/minesweeper/src/main/webapp/pages/index.html	Mon Sep 08 17:13:40 2014 +0200
     3.2 +++ b/minesweeper/src/main/webapp/pages/index.html	Mon Sep 08 17:15:18 2014 +0200
     3.3 @@ -226,6 +226,7 @@
     3.4              <a href="http://wiki.apidesign.org/wiki/DukeScriptInNetBeans"
     3.5                 target="_blank"
     3.6                 class="btn btn-primary" role="button"
     3.7 +               data-bind="click: $root.develop"
     3.8                 >Develop &raquo;</a> 
     3.9          </p>
    3.10        </div>
     4.1 --- a/minesweeper/src/main/webapp/pages/index_cs.html	Mon Sep 08 17:13:40 2014 +0200
     4.2 +++ b/minesweeper/src/main/webapp/pages/index_cs.html	Mon Sep 08 17:15:18 2014 +0200
     4.3 @@ -229,6 +229,7 @@
     4.4              <a href="http://wiki.apidesign.org/wiki/DukeScriptInNetBeans"
     4.5                 target="_blank"
     4.6                 class="btn btn-primary" role="button"
     4.7 +               data-bind="click: $root.develop"
     4.8                 >Vyvíjejte &raquo;</a> 
     4.9          </p>
    4.10        </div>