From b0eaa62299117f06d335091018a29847d074a7a0 Mon Sep 17 00:00:00 2001
From: "Dott. Federico Volpini" <federico.volpini@isti.cnr.it>
Date: Tue, 2 Jul 2013 13:56:27 +0000
Subject: [PATCH] Bug #323 fixed + added getter methods for bundleId and
 bundleVersion in Part.java

---
 .../tools/packaging/tool/api/Page.java        |   2 +-
 .../tools/packaging/tool/gui/GUI.java         |  12 +-
 .../tools/packaging/tool/gui/Page1.java       | 115 +++++++++++++-
 .../tools/packaging/tool/gui/StartPage.java   |   2 +-
 .../tools/packaging/tool/parts/App.java       |  11 +-
 .../tools/packaging/tool/parts/MenuEntry.java | 148 ++++++++++++++++++
 .../tools/packaging/tool/parts/Part.java      |   8 +
 7 files changed, 289 insertions(+), 9 deletions(-)
 create mode 100644 mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/parts/MenuEntry.java

diff --git a/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/api/Page.java b/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/api/Page.java
index 2fb0e7f79..9b0fcedcf 100644
--- a/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/api/Page.java
+++ b/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/api/Page.java
@@ -20,7 +20,7 @@ public interface Page {
 	
 	public final String KARAF_NAMESPACE = "krf";
 	
-	public final String XSD = "'http://www.universaal.org/aal-uapp/v1.0.0'"; //"http://www.universaal.org/aal-uapp/v1.0.0/AAL-UAPP.xsd";
+	public final String XSD = "'http://www.universaal.org/aal-uapp/v1.0.1'"; // "'http://www.universaal.org/aal-uapp/v1.0.0'" - //"http://www.universaal.org/aal-uapp/v1.0.0/AAL-UAPP.xsd";
 	public final String Karaf = "'http://karaf.apache.org/xmlns/features/v1.0.0'";
 	public final String w3c = "'http://www.w3.org/2001/XMLSchema'";
 	
diff --git a/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/gui/GUI.java b/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/gui/GUI.java
index a7a02f4b9..1676c3090 100644
--- a/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/gui/GUI.java
+++ b/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/gui/GUI.java
@@ -226,10 +226,15 @@ public class GUI extends WizardMod {
 				}
 			}
 
+			// copy icon file if set
+			File iconFile = mpa.getAAL_UAPP().getApplication().getMenuEntry().getIconFile();
+			if(iconFile != null && iconFile.exists()) copyFile(iconFile, new File(tempDir+"/bin/icon/"+iconFile.getName()));
+	
 			UAPP descriptor = new UAPP();
 			descriptor.createUAPPfile(tempDir, destination);
 
 			callUSTORE(destination);
+
 		} 
 		catch (Exception e) {
 			e.printStackTrace();
@@ -291,10 +296,12 @@ public class GUI extends WizardMod {
 			File f = new File(tempDir);
 			f.mkdir();
 
-			File bin, config, doc, license, part, emptyFile;
+			File bin, icon, config, doc, license, part, emptyFile;
 
 			bin = new File(f+"/bin");
 			bin.mkdir();
+			icon = new File(f+"/bin/icon");
+			icon.mkdir();
 			config = new File(f+"/config");
 			config.mkdir();
 			doc = new File(f+"/doc");
@@ -311,6 +318,9 @@ public class GUI extends WizardMod {
 			emptyFile = new File(f+"/license/.empty");
 			emptyFile.createNewFile();
 
+			emptyFile = new File(f+"/bin/icon/.empty"); 
+			emptyFile.createNewFile();
+			
 			for(int i = 0; i < parts.size(); i++){
 				part = new File(f+"/bin/part"+(i+1));
 				part.mkdir();
diff --git a/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/gui/Page1.java b/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/gui/Page1.java
index 87ee50036..e35e5428c 100644
--- a/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/gui/Page1.java
+++ b/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/gui/Page1.java
@@ -20,15 +20,28 @@
  */
 package org.universaal.tools.packaging.tool.gui;
 
+import java.io.File;
+import java.net.URI;
+
 import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.graphics.FontData;
 import org.eclipse.swt.layout.GridData;
 import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Label;
 import org.eclipse.swt.widgets.Text;
 import org.universaal.tools.packaging.tool.impl.PageImpl;
+import org.universaal.tools.packaging.tool.impl.PageImpl.QL;
+import org.universaal.tools.packaging.tool.util.Dialog;
 import org.universaal.tools.packaging.tool.validators.AlphabeticV;
+import org.universaal.tools.packaging.tool.validators.FileV;
 import org.universaal.tools.packaging.tool.validators.IntegerV;
+import org.universaal.tools.packaging.tool.validators.UriV;
 
 /**
  * Second page of the wizard
@@ -39,13 +52,15 @@ import org.universaal.tools.packaging.tool.validators.IntegerV;
  */
 public class Page1 extends PageImpl {
 
-	private Text name, id, description, tags, version_major, version_minor, version_micro, version_build, app_profile;
-
+	private Text name, id, description, tags, version_major, version_minor, version_micro, version_build, app_profile, menuName, serviceUri, iconFile;
+	private File sourcePNG;
+	private Button b1;
+	
 	protected Page1(String pageName) {
 		super(pageName, "Specify details of the Application you are creating");
 	}
 
-	public void createControl(Composite parent) { 
+	public void createControl(final Composite parent) { 
 
 		container = new Composite(parent, SWT.NULL);
 		setControl(container);
@@ -126,6 +141,62 @@ public class Page1 extends PageImpl {
 		app_profile.addVerifyListener(new AlphabeticV());
 		app_profile.setLayoutData(gd);
 
+		Label label10 = new Label(container, SWT.NULL);
+		label10.setText("\nMenu Entry\n");
+		
+		Label label100 = new Label(container, SWT.NULL);
+		label100.setText("");
+		
+		FontData[] fD = label10.getFont().getFontData();
+		fD[0].setStyle(SWT.BOLD);
+		label10.setFont(new Font(container.getDisplay(), fD[0]));	
+		
+		Label label11 = new Label(container, SWT.NULL);
+		label11.setText("Menu name");
+				
+		menuName = new Text(container, SWT.BORDER | SWT.SINGLE);
+		menuName.setText(app.getApplication().getMenuEntry().getMenuName());
+		menuName.addVerifyListener(new AlphabeticV());
+		menuName.setLayoutData(gd);
+		
+		Label label12 = new Label(container, SWT.NULL);
+		label12.setText("* Service URI");
+		
+		serviceUri = new Text(container, SWT.BORDER | SWT.SINGLE );
+		serviceUri.setText(app.getApplication().getMenuEntry().getServiceUri().toASCIIString());
+		serviceUri.setLayoutData(gd);
+		serviceUri.addVerifyListener(new UriV());
+		
+		Label label13 = new Label(container, SWT.NULL);
+		label13.setText("Menu Entry Icon (PNG)");
+		
+		iconFile = new Text(container, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
+		iconFile.setLayoutData(gd);
+		iconFile.addVerifyListener(new FileV());
+		
+		Label label133 = new Label(container, SWT.NULL);
+		label133.setText("");
+		
+		b1 = new Button(container, SWT.PUSH);
+		b1.setText("Browse");
+		b1.addSelectionListener(new SelectionListener() {
+
+			public void widgetSelected(SelectionEvent e) {
+				Dialog d = new Dialog();
+				sourcePNG = d.open(parent.getShell(), new String[]{"*.png"}, false, "PNG Icon");			
+
+				if(!sourcePNG.getAbsolutePath().endsWith(".png"))
+					sourcePNG = new File(sourcePNG+".png");
+
+				iconFile.setText(sourcePNG.getAbsolutePath());
+			}
+
+			public void widgetDefaultSelected(SelectionEvent e) {
+			}
+		});	
+		
+		checkMenuEntry();
+		
 		name.addKeyListener(new FullListener());
 		id.addKeyListener(new FullListener());
 		description.addKeyListener(new FullListener());
@@ -135,10 +206,40 @@ public class Page1 extends PageImpl {
 		version_build.addKeyListener(new FullListener());
 		app_profile.addKeyListener(new FullListener());
 		
+		menuName.addKeyListener(new QL() {
+
+			@Override
+			public void keyReleased(KeyEvent e) {
+				checkMenuEntry();
+				setPageComplete(validate());
+			}
+		});	
+		serviceUri.addKeyListener(new FullListener());
+				
 		loadDefaultValues();
 		
 	}
 
+	private void checkMenuEntry(){
+		if(menuName.getText().trim().length() == 0){
+			serviceUri.setText("");
+			serviceUri.setEnabled(false);
+			mandatory.remove(serviceUri);
+			
+			iconFile.setText("");
+			iconFile.setEnabled(false);
+			
+			b1.setEnabled(false);
+		} else {
+			serviceUri.setEnabled(true);
+			mandatory.add(serviceUri);
+			
+			iconFile.setEnabled(true);
+
+			b1.setEnabled(true);
+		}
+	}
+	
 	private void loadDefaultValues() {
 		if ( app.getApplication() != null ) {
 		    name.setText( app.getApplication().getName() );
@@ -162,7 +263,13 @@ public class Page1 extends PageImpl {
 			app.getApplication().getVersion().setMinor(version_minor.getText());	
 			app.getApplication().getVersion().setMicro(version_micro.getText());		
 			app.getApplication().getVersion().setBuild(version_build.getText());	
-			app.getApplication().setApplicationProfile(app_profile.getText());		
+			app.getApplication().setApplicationProfile(app_profile.getText());
+			if(menuName.getText().trim().length() > 0){
+				app.getApplication().getMenuEntry().setMenuName(menuName.getText().trim());
+				app.getApplication().getMenuEntry().setServiceUri(URI.create(serviceUri.getText()));
+				if(iconFile.getText().trim().length()>0)
+					app.getApplication().getMenuEntry().setIconFile(sourcePNG);
+			}	
 		}
 		catch(Exception ex){
 			ex.printStackTrace();
diff --git a/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/gui/StartPage.java b/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/gui/StartPage.java
index a5bee9f80..aedb9ca34 100644
--- a/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/gui/StartPage.java
+++ b/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/gui/StartPage.java
@@ -140,7 +140,7 @@ public class StartPage extends PageImpl {
 		Label label70 = new Label(container, SWT.NULL);
 		label70.setText("");
 
-		name = new Text(container, SWT.BORDER | SWT.SINGLE);
+		name = new Text(container, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
 		name.setText(app.getApplication().getName());			
 		name.setLayoutData(gd);		
 		name.addVerifyListener(new FileV());
diff --git a/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/parts/App.java b/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/parts/App.java
index bd967c6d8..8e9493439 100644
--- a/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/parts/App.java
+++ b/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/parts/App.java
@@ -38,7 +38,8 @@ public class App implements Serializable {
 	private String tags;
 	private Contact applicationProvider;
 	private List<LicenseSet> licenses;
-
+	private MenuEntry menuEntry;
+	
 	public App(){
 		name  = Application.defaultString;
 		appID = Application.defaultString;
@@ -47,6 +48,7 @@ public class App implements Serializable {
 
 		version = new Version();
 		applicationProvider = new Contact();
+		menuEntry = new MenuEntry();
 	}
 
 	public String getName() {
@@ -104,7 +106,11 @@ public class App implements Serializable {
 	public Contact getApplicationProvider() {
 		return applicationProvider;
 	}
-
+	
+	public MenuEntry getMenuEntry(){
+		return menuEntry;
+	}
+	
 	public List<LicenseSet> getLicenses() {
 		if(licenses == null)
 			licenses = new ArrayList<LicenseSet>();
@@ -125,6 +131,7 @@ public class App implements Serializable {
 		for(int i = 0; i < getLicenses().size(); i++)
 			r = r.concat(licenses.get(i).getXML());
 		r = r.concat("<applicationProfile>"+applicationProfile+"</applicationProfile>");
+		if(menuEntry.getMenuName().trim().length() > 0) r = r.concat("<menuEntry>"+menuEntry.getXML()+"</menuEntry>");
 		//r = r.concat("</app>");
 
 		return r;
diff --git a/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/parts/MenuEntry.java b/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/parts/MenuEntry.java
new file mode 100644
index 000000000..76d4ccf4b
--- /dev/null
+++ b/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/parts/MenuEntry.java
@@ -0,0 +1,148 @@
+/*
+
+        Copyright 2007-2014 CNR-ISTI, http://isti.cnr.it
+        Institute of Information Science and Technologies
+        of the Italian National Research Council
+
+        See the NOTICE file distributed with this work for additional
+        information regarding copyright ownership
+
+        Licensed under the Apache License, Version 2.0 (the "License");
+        you may not use this file except in compliance with the License.
+        You may obtain a copy of the License at
+
+          http://www.apache.org/licenses/LICENSE-2.0
+
+        Unless required by applicable law or agreed to in writing, software
+        distributed under the License is distributed on an "AS IS" BASIS,
+        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+        See the License for the specific language governing permissions and
+        limitations under the License.
+ */
+package org.universaal.tools.packaging.tool.parts;
+
+import java.io.File;
+import java.io.Serializable;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.universaal.tools.packaging.tool.validators.UriV;
+
+/**
+ * 
+ * @author <a href="mailto:manlio.bacco@isti.cnr.it">Manlio Bacco</a>
+ * @author <a href="mailto:stefano.lenzi@isti.cnr.it">Stefano Lenzi</a>
+ * @version $LastChangedRevision$ ( $LastChangedDate$ )
+ */
+public class MenuEntry implements Serializable {
+
+	private String menuName;
+	private URI serviceUri, iconPath;
+	private File iconFile;
+	
+	public MenuEntry(){
+
+		menuName = Application.defaultString;
+		
+		try{
+			serviceUri = URI.create(Application.defaultURL);
+			iconPath = URI.create(Application.defaultURL);
+		}
+		catch(Exception ex){}
+	}
+
+	public MenuEntry(String menuName, URI serviceUri){
+
+		menuName = this.menuName;
+		serviceUri = this.serviceUri;
+		
+		try{
+			iconPath = URI.create(Application.defaultURL);
+		}
+		catch(Exception ex){}
+	}
+	
+	public MenuEntry(String menuName, URI serviceUri, URI iconPath){
+
+		menuName = this.menuName;
+		serviceUri = this.serviceUri;
+		iconPath = this.iconPath;
+	}
+
+	
+
+	public String getMenuName() {
+		return menuName;
+	}
+
+	public void setMenuName(String menuName) {
+		if(menuName.trim().length() > 0)
+			this.menuName = menuName;
+	}
+	
+	public URI getServiceUri() {
+		return serviceUri;
+	}
+
+	public void setServiceUri(URI serviceUri) {
+		if(serviceUri.toASCIIString().trim().length() > 0)
+			this.serviceUri = serviceUri;
+	}
+	
+	public URI getIconPath() {
+		return iconPath;
+	}
+
+	public void setIconPath(URI iconPath) {
+		if(iconPath.toASCIIString().trim().length() > 0)
+			this.iconPath = iconPath;
+	}
+	
+	public File getIconFile() {
+		return iconFile;
+	}
+
+	public void setIconFile(File iconFile) {
+		this.iconFile = iconFile;
+		String iconPath = Application.defaultURL+"bin/icon/"+iconFile.getName();
+		setIconPath(URI.create(iconPath));
+	}
+	
+	public String getXML(){
+
+		String r = "";
+		r = r.concat("<menuName>"+menuName+"</menuName>");
+		r = r.concat("<serviceUri>"+serviceUri.toASCIIString()+"</serviceUri>");
+		if(iconPath.toASCIIString().trim().length() > 0) r = r.concat("<iconPath>"+iconPath.toASCIIString().trim()+"</iconPath>");
+		
+		return r;
+	}
+
+	/*
+	 * <xs:element name="menuEntry" minOccurs="0">
+						<xs:annotation>
+										<xs:documentation>basic info for the menu entries of the application</xs:documentation>
+						</xs:annotation>
+						<xs:complexType>
+										<xs:sequence>
+														<xs:element name="menuName" type="xs:string">
+																		<xs:annotation>
+																						<xs:documentation>name of the application to show in the menu</xs:documentation>
+																		</xs:annotation>
+														</xs:element>
+														<xs:element name="serviceUri" type="xs:anyURI">
+																		<xs:annotation>
+																						<xs:documentation>service uri to start the application</xs:documentation>
+																		</xs:annotation>
+														</xs:element>
+														<xs:element name="iconPath" type="xs:anyURI" minOccurs="0">
+																		<xs:annotation>
+																						<xs:documentation>path for the menu icon; please save in: /bin/icon/*.png</xs:documentation>
+																		</xs:annotation>
+														</xs:element>
+										</xs:sequence>
+						</xs:complexType>
+		</xs:element>
+	 */
+}
\ No newline at end of file
diff --git a/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/parts/Part.java b/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/parts/Part.java
index 5c8144d47..1a7b23bbd 100644
--- a/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/parts/Part.java
+++ b/mpa/org.universaal.tools.packaging.tool/src/org/universaal/tools/packaging/tool/parts/Part.java
@@ -88,6 +88,14 @@ public class Part implements Serializable {
 		this.bundleVersion = version;
 	}
 	
+	public String getPartBundleId(){
+		return this.bundleId;
+	}
+	
+	public String getPartBundleVersion(){
+		return this.bundleVersion;
+	}
+	
 	public void setCapability(String name, String value){
 		partCapabilities.put(name, value);
 	}
-- 
GitLab