changeset 5662:5560bff5eea1

RT-33590 Ensemble8: remove playground and docs links/docs search references on embedded
author dmasada
date Thu, 07 Nov 2013 11:29:50 -0800
parents a10660cea86f
children d234defb41f7
files apps/samples/Ensemble8/src/app/java/ensemble/PlatformFeatures.java apps/samples/Ensemble8/src/app/java/ensemble/samplepage/Description.java apps/samples/Ensemble8/src/app/java/ensemble/samplepage/SamplePageContent.java apps/samples/Ensemble8/src/app/java/ensemble/search/IndexSearcher.java
diffstat 4 files changed, 96 insertions(+), 88 deletions(-) [+]
line wrap: on
line diff
--- a/apps/samples/Ensemble8/src/app/java/ensemble/PlatformFeatures.java	Thu Nov 07 08:55:42 2013 -0800
+++ b/apps/samples/Ensemble8/src/app/java/ensemble/PlatformFeatures.java	Thu Nov 07 11:29:50 2013 -0800
@@ -46,6 +46,6 @@
     public static final boolean USE_IOS_THEME = IOS;
     public static final boolean START_FULL_SCREEN = ARM;
     public static final boolean EMBEDDED = ARM || IOS;
-    
+        
     private PlatformFeatures(){}
 }
--- a/apps/samples/Ensemble8/src/app/java/ensemble/samplepage/Description.java	Thu Nov 07 08:55:42 2013 -0800
+++ b/apps/samples/Ensemble8/src/app/java/ensemble/samplepage/Description.java	Thu Nov 07 11:29:50 2013 -0800
@@ -32,6 +32,7 @@
 package ensemble.samplepage;
 
 import ensemble.EnsembleApp;
+import ensemble.PlatformFeatures;
 import ensemble.SampleInfo;
 import ensemble.SampleInfo.URL;
 import ensemble.generated.Samples;
@@ -48,6 +49,8 @@
 
 import static ensemble.samplepage.SamplePage.INDENT;
 import static ensemble.samplepage.SamplePageContent.title;
+import javafx.application.ConditionalFeature;
+import javafx.application.Platform;
 
 /**
  * Description Section on Sample Page
@@ -79,42 +82,48 @@
         sourceBtn.setOnAction(event -> {
             samplePage.pageBrowser.goToPage(samplePage.getUrl().replaceFirst("sample://", "sample-src://"));
         });
-        if (!EnsembleApp.IS_EMBEDDED) getChildren().add(sourceBtn);
+        if (!PlatformFeatures.EMBEDDED) getChildren().add(sourceBtn);
+        if (Platform.isSupported(ConditionalFeature.WEB)) {
+            // Setup Columns
+            GridPane gridPane = new GridPane();
+            getChildren().add(gridPane);
+            gridPane.setVgap(INDENT);
+            gridPane.setHgap(INDENT);
+            ColumnConstraints leftColumn = new ColumnConstraints();
+            leftColumn.setPercentWidth(50);
+            ColumnConstraints rightColumn = new ColumnConstraints();
+            rightColumn.setPercentWidth(50);
+            gridPane.getColumnConstraints().addAll(leftColumn, rightColumn);
 
-        // Setup Columns
-        GridPane gridPane = new GridPane();
-        getChildren().add(gridPane);
-        gridPane.setVgap(INDENT);
-        gridPane.setHgap(INDENT);
-        ColumnConstraints leftColumn = new ColumnConstraints();
-        leftColumn.setPercentWidth(50);
-        ColumnConstraints rightColumn = new ColumnConstraints();
-        rightColumn.setPercentWidth(50);
-        gridPane.getColumnConstraints().addAll(leftColumn, rightColumn);
+            // Add Related Documents
+            Text relatedDocumentsTitle = title("RELATED DOCUMENTS");
+            GridPane.setConstraints(relatedDocumentsTitle, 0, 0);
+            relatedDocumentsList = new VBox();
+            ScrollPane relatedDocumentsScrollPane = new ScrollPane(relatedDocumentsList);
+            relatedDocumentsScrollPane.setPrefSize(50, 20);
+            GridPane.setConstraints(relatedDocumentsScrollPane, 0, 1);
+            relatedDocumentsScrollPane.setFitToHeight(true);
+            relatedDocumentsScrollPane.setFitToWidth(true);
+            relatedDocumentsScrollPane.prefHeightProperty().bind(heightProperty());
+            relatedDocumentsScrollPane.getStyleClass().clear();
 
-        // Add Related Documents
-        Text relatedDocumentsTitle = title("RELATED DOCUMENTS");
-        GridPane.setConstraints(relatedDocumentsTitle, 0, 0);
-        relatedDocumentsList = new VBox();
-        ScrollPane relatedDocumentsScrollPane = new ScrollPane(relatedDocumentsList);
-        relatedDocumentsScrollPane.setPrefSize(50,20);
-        GridPane.setConstraints(relatedDocumentsScrollPane, 0, 1);
-        relatedDocumentsScrollPane.setFitToHeight(true);
-        relatedDocumentsScrollPane.setFitToWidth(true);
-        relatedDocumentsScrollPane.prefHeightProperty().bind(heightProperty());
-        relatedDocumentsScrollPane.getStyleClass().clear();
+            // Add Related Samples
+            Text relatedSamplesTitle = title("RELATED SAMPLES");
+            GridPane.setConstraints(relatedSamplesTitle, 1, 0);
+            relatedSamples = new VBox();
+            GridPane.setConstraints(relatedSamples, 1, 1);
 
-        // Add Related Samples
-        Text relatedSamplesTitle = title("RELATED SAMPLES");
-        GridPane.setConstraints(relatedSamplesTitle, 1, 0);
-        relatedSamples = new VBox();
-        GridPane.setConstraints(relatedSamples, 1, 1);
-
-        gridPane.getChildren().addAll(
-                relatedDocumentsTitle,
-                relatedDocumentsScrollPane,
-                relatedSamplesTitle,
-                relatedSamples);
+            gridPane.getChildren().addAll(
+                    relatedDocumentsTitle,
+                    relatedDocumentsScrollPane,
+                    relatedSamplesTitle,
+                    relatedSamples);
+        } else {
+            Text relatedSamplesTitle = title("RELATED SAMPLES");
+            relatedSamples = new VBox();
+            getChildren().addAll(relatedSamplesTitle, relatedSamples);
+            relatedDocumentsList = null;
+        }
 
         // listen for when sample changes
         samplePage.registerSampleInfoUpdater(sampleInfo -> {
@@ -124,21 +133,23 @@
     }
 
     private void update(SampleInfo sampleInfo) {
-        relatedDocumentsList.getChildren().clear();
-        for (final URL docUrl : sampleInfo.getDocURLs()) {
-            Hyperlink link = new Hyperlink(docUrl.getName());
-            link.setOnAction(t -> {
-                samplePage.pageBrowser.goToPage(docUrl.getURL());
-            });
-            link.setTooltip(new Tooltip(docUrl.getName()));
-            relatedDocumentsList.getChildren().add(link);
-        }
-        for (final String classpath : sampleInfo.apiClasspaths) {
-            Hyperlink link = new Hyperlink(classpath.replace('$', '.'));
-            link.setOnAction(t -> {
-                samplePage.pageBrowser.goToPage(samplePage.apiClassToUrl(classpath));
-            });
-            relatedDocumentsList.getChildren().add(link);
+        if (Platform.isSupported(ConditionalFeature.WEB)) {
+            relatedDocumentsList.getChildren().clear();
+            for (final URL docUrl : sampleInfo.getDocURLs()) {
+                Hyperlink link = new Hyperlink(docUrl.getName());
+                link.setOnAction(t -> {
+                    samplePage.pageBrowser.goToPage(docUrl.getURL());
+                });
+                link.setTooltip(new Tooltip(docUrl.getName()));
+                relatedDocumentsList.getChildren().add(link);
+            }
+            for (final String classpath : sampleInfo.apiClasspaths) {
+                Hyperlink link = new Hyperlink(classpath.replace('$', '.'));
+                link.setOnAction(t -> {
+                    samplePage.pageBrowser.goToPage(samplePage.apiClassToUrl(classpath));
+                });
+                relatedDocumentsList.getChildren().add(link);
+            }
         }
         relatedSamples.getChildren().clear();
         for (final SampleInfo.URL sampleURL : sampleInfo.getRelatedSampleURLs()) {
--- a/apps/samples/Ensemble8/src/app/java/ensemble/samplepage/SamplePageContent.java	Thu Nov 07 08:55:42 2013 -0800
+++ b/apps/samples/Ensemble8/src/app/java/ensemble/samplepage/SamplePageContent.java	Thu Nov 07 11:29:50 2013 -0800
@@ -31,6 +31,7 @@
  */
 package ensemble.samplepage;
 
+import ensemble.PlatformFeatures;
 import ensemble.SampleInfo;
 import javafx.scene.Node;
 import javafx.scene.layout.Region;
@@ -120,7 +121,11 @@
     private void update(SampleInfo sampleInfo) {
         sampleContainer = new SampleContainer(samplePage.sampleRuntimeInfoProperty.get().getSampleNode());
         sampleContainer.getStyleClass().add("sample-page-sample-node");
-        needsPlayground = sampleInfo.needsPlayground();
+        if (PlatformFeatures.EMBEDDED) {
+            needsPlayground = false;
+        } else {
+            needsPlayground = sampleInfo.needsPlayground();
+        }
         if (needsPlayground) {
             getChildren().setAll(playground, description, sampleContainer);
         } else {
--- a/apps/samples/Ensemble8/src/app/java/ensemble/search/IndexSearcher.java	Thu Nov 07 08:55:42 2013 -0800
+++ b/apps/samples/Ensemble8/src/app/java/ensemble/search/IndexSearcher.java	Thu Nov 07 11:29:50 2013 -0800
@@ -36,6 +36,8 @@
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.util.*;
+import javafx.application.ConditionalFeature;
+import javafx.application.Platform;
 import org.apache.lucene.analysis.Analyzer;
 import org.apache.lucene.analysis.standard.StandardAnalyzer;
 import org.apache.lucene.document.Document;
@@ -89,45 +91,35 @@
                 DocumentType docType = DocumentType.valueOf(groupDocs.groupValue);
                 List<SearchResult> results = new ArrayList<>();
                 for (ScoreDoc scoreDoc : groupDocs.scoreDocs) {
-                    Document doc = searcher.doc(scoreDoc.doc);
-                    SearchResult result = new SearchResult(
-                            docType,
-                            doc.get("name"),
-                            doc.get("url"),
-                            doc.get("className"),
-                            doc.get("package"),
-                            doc.get("ensemblePath"),
-                            docType == DocumentType.DOC ? 
-                                    doc.get("bookTitle") == null ? doc.get("chapter") : doc.get("bookTitle")
-                                    : doc.get("shortDescription").trim()
-                    );
-                    /* If the result is a sample, then filter out the samples that 
-                     * the runtime platform does not support. We really want to show
-                     * just 5 results, but we search for 10 and filter out unsupported
-                     * samples and show just 5.
-                     */
-                    // If result is a sample, check if supported sample exists before adding so it's
-                    // either not sample or it is a supported sample
-                    if (!result.getDocumentType().name().equals(DocumentType.SAMPLE.name())
-                            || Samples.ROOT.sampleForPath(result.getEnsemblePath().substring(9).trim()) != null) {
-                        results.add(result);
-                        if (results.size() == 5) {
-                            // 5 samples is enough
-                            break;
+                    if ((Platform.isSupported(ConditionalFeature.WEB)) || (docType != DocumentType.DOC)) {
+                        Document doc = searcher.doc(scoreDoc.doc);
+                        SearchResult result = new SearchResult(
+                                docType,
+                                doc.get("name"),
+                                doc.get("url"),
+                                doc.get("className"),
+                                doc.get("package"),
+                                doc.get("ensemblePath"),
+                                docType == DocumentType.DOC
+                                        ? doc.get("bookTitle") == null ? doc.get("chapter") : doc.get("bookTitle")
+                                        : doc.get("shortDescription").trim()
+                        );
+                        /* If the result is a sample, then filter out the samples that
+                        * the runtime platform does not support. We really want to show
+                        * just 5 results, but we search for 10 and filter out unsupported
+                        * samples and show just 5.
+                        */
+                        // If result is a sample, check if supported sample exists before adding so it's
+                        // either not sample or it is a supported sample
+                        if (!result.getDocumentType().name().equals(DocumentType.SAMPLE.name())
+                                || Samples.ROOT.sampleForPath(result.getEnsemblePath().substring(9).trim()) != null) {
+                            results.add(result);
+                            if (results.size() == 5) {
+                                // 5 samples is enough
+                                break;
+                            }
                         }
-                    }
-
-                    /*                   if (results.size() < 5) {
-                     //If result is a sample check if supported sample exists before adding
-                     if (result.getDocumentType().name().equals(DocumentType.SAMPLE.name())) {
-                     if (Samples.ROOT.sampleForPath(result.getEnsemblePath().substring(9).trim()) != null) {
-                     results.add(result);
-                     }
-                     } else {
-                     results.add(result);
-                     }
-                     }
-                     */
+                    } 
                 }
                 resultMap.put(docType, results);
             }