13
1 Mobile Tools for the Java Platform Coding Examples Version 0.3

Mobile Tools for the Java Platform

  • Upload
    chen

  • View
    22

  • Download
    0

Embed Size (px)

DESCRIPTION

Mobile Tools for the Java Platform. Coding Examples Version 0. 3. Get Extension Implementation. import org.eclipse.mtj.api.extension.DeviceManagement; import org.eclipse.mtj.api.enumerations.ExtensionType; import org.eclipse.mtj.api.extension.MtjExtension; - PowerPoint PPT Presentation

Citation preview

Page 1: Mobile Tools for the Java Platform

1

Mobile Tools forthe Java Platform

Coding ExamplesVersion 0.3

Page 2: Mobile Tools for the Java Platform

21.3.2006

Get Extension Implementation

import org.eclipse.mtj.api.extension.DeviceManagement;

import org.eclipse.mtj.api.enumerations.ExtensionType;

import org.eclipse.mtj.api.extension.MtjExtension;

import org.eclipse.mtj.core.MtjServices;

...

String version = null;

String vendor = null;

boolean onlyActive = true;

MtjExtension[] list = MtjServices.getInstance()

.getImplementations( ExtensionType.DEVICE_MANAGEMENT_LITERAL,

version,

vendor,

onlyActive);

DeviceManagement deviceManagement = (DeviceManagement ) list[0];

Page 3: Mobile Tools for the Java Platform

31.3.2006

Get DevicePlatform, Device and RuntimePlatform

ImplementationRef

fileRef : StringsourceRef : StringjavadocRef : String

JvmImplementationname : Stringversion : Stringvendor : StringfileRef : String

DeviceProfile

name : Stringversion : String

ServiceApi

name : Stringversion : Stringdescription : String

DeviceConfiguration

name : Stringversion : String

+implementation0..1

+implementation

1

+jvmRef0..1

+serviceApis

1..*1..*

0..11

0..1

DevicePlatformname : Stringvendor : Stringversion : StringdebugEnabled : booleanpredeploymentRequired : booleanpreferencesDialogAvailable : booleanutil itesDialogAvailable : boolean

RuntimePlatformDefinition

name : String

1..*

+deviceProfiles1..*

1..*

+serviceApis

1..* 1..*

+deviceConfigurations

1..*

Device

name : Stringversion : Stringvendor : Stringdescription : String

1..*+devices

1..*

1..*1..*

+runtimePlatformDefinitions1..*

1..*

1..*

+runtimePlatformDefinitions

1..*+devices

DevicePlatforms, that are defined by DevicePlatformProviders, define their content with specific data model.

The model right describes the main parts of the object model structure of the DevicePlatform –definition.

Page 4: Mobile Tools for the Java Platform

41.3.2006

Get DevicePlatform, Device and RuntimePlatform (cont.)

import org.eclipse.mtj.api.extension.DeviceManagement;

import org.eclipse.mtj.api.enumerations.ExtensionType;

import org.eclipse.mtj.api.extension.MtjExtension;

import org.eclipse.mtj.core.MtjServices;

import org.eclipse.mtj.api.devices.Device;

import org.eclipse.mtj.api.devices.DevicePlatform;

import org.eclipse.mtj.api.runtimes.RuntimePlatformDefinition;

...

DeviceManagement deviceManagement = (DeviceManagement) MtjServices.getInstance()

.getImplementations( ExtensionType.DEVICE_MANAGEMENT_LITERAL,null,null)[0];

DevicePlatform[] devicePlatform = deviceManagement .getDevicePlatforms()[0];

Device device = devicePlatform.getDevices().get(1);

RuntimePlatformDefinition runtimePlatformDefinition = device .getRuntimePlatformDefinitions().get(1);

Page 5: Mobile Tools for the Java Platform

51.3.2006

Modify Project Data

Projects, that have Mtj Nature, contains Mtj specific descriptions. Next example shows, how to access Project’s descriptions and how to modify them.

The model right describes the object model structure of the Project –definitions.

DebugConfiguration

ProjectType

PROJECT_TYPE_MIDP : 0PROJECT_TYPE_PERSONAL_PROFILE : 1

<<enumeration>>ObfuscationDetail

level : intadditionalSettings : String

Project

name : String

1

+type1

0..1

+obfuscationDetail0..1

SigningDetail

keystore : Stringalias : String

PreprocessingDetail

condition : String

DeviceConfiguration

name : Stringversion : String

TargetDevice

name : Stringdescription : StringdevicePlatformName : StringdeviceName : StringdeviceGroupName : String

1..*

+targetDevices

1..* 1

+defaultTargetDevice

1

0..*

+signingDetails

0..*

0..*

+preprocessingDetails0..*

ImplementationRef

fileRef : StringsourceRef : StringjavadocRef : String

1

+implementation

1

RuntimePlatformDefinition

name : String

1..*

+deviceConfigurations

1..*

1+runtimePlatform

1

DeviceProfile

name : Stringversion : String

1..*

+deviceProfiles

1..*

ServiceApi

name : Stringversion : Stringdescription : String

0..1

+implementation0..1

1..*+serviceApis1..*

1..*

+serviceApis

1..*

Page 6: Mobile Tools for the Java Platform

61.3.2006

Modify Project Data (cont.)

import org.eclipse.jdt.core.IJavaProject;

import org.eclipse.mtj.api.model.IMtjProject;

import org.eclipse.mtj.core.project.MtjProject;

import org.eclipse.mtj.api.project.Project;

...

IJavaProject javaProject;

...

IMtjProject mtjProject = MtjProject.getMtjProject(javaProject);

Project project = mtjProject.getProjectData();

ObfuscationDetail obfuscationDetail = new ObfuscationDetail();

obfuscationDetail.setLevel(1);

project.setObfuscationDetail(obfuscationDetail);

mtjProject.setProjectData(project);

Page 7: Mobile Tools for the Java Platform

71.3.2006

Add Runtime Platform Definition To Project

import org.eclipse.mtj.api.devices.Device;import org.eclipse.mtj.api.devices.DevicePlatform;import org.eclipse.mtj.api.runtimes.RuntimePlatformDefinition; import org.eclipse.mtj.api.project.Project;import org.eclipse.mtj.api.project.ProjectFactory;import org.eclipse.mtj.api.project.TargetDevice;import org.eclipse.mtj.core.util.MtjEmfUtil;

...

Project project;

DevicePlatform devicePlatform;

Device device;

RuntimePlatformDefinition runtimePlatformDefinition;

...

TargetDevice targetDevice = ProjectFactory.eINSTANCE.createTargetDevice();

targetDevice.setName(”Nokia S80 Device”);

targetDevice.setDevicePlatformName(devicePlatform.getName());

targetDevice.setDeviceName(device.getName());

// create a project specific copy of the RuntimePlatformDefinition

RuntimePlatformDefinition copyRPD = MtjEmfUtil.clone(runtimePlatformDefinition);

targetDevice.setRuntimePlatform(copyRPD);

mtjProject.setProjectData(project);

Page 8: Mobile Tools for the Java Platform

81.3.2006

Get Project’s Default Targets

import org.eclipse.jdt.core.IJavaProject;

import org.eclipse.mtj.api.model.IMtjProject;

import org.eclipse.mtj.core.project.MtjProject;

import org.eclipse.mtj.api.project.Project;

import org.eclipse.mtj.api.devices.Device;

import org.eclipse.mtj.api.devices.DevicePlatform;

import org.eclipse.mtj.api.runtimes.RuntimePlatformDefinition;

...

IJavaProject javaProject;

...

IMtjProject mtjProject = MtjProject.getMtjProject(javaProject);

DevicePlatform devicePlatform = mtjProject.getPlatformDefinition();

Device device = mtjProject.getDefaultDevice();

RuntimePlatformDefinition runtimePlatformDefinition =

mtjProject.getProjectData().getDefaultTargetDevice().getRuntimePlatform();

Page 9: Mobile Tools for the Java Platform

91.3.2006

Deploy Project’s Data

import org.eclipse.mtj.api.model.IMtjProject;

import org.eclipse.mtj.api.devices.Device;

import org.eclipse.mtj.api.extension. DeploymentManagement ;

import org.eclipse.mtj.api.runtimes.RuntimePlatformDefinition;

import org.eclipse.mtj.api.enumerations.DeviceCommunicationProtocol;

import org.eclipse.core.runtime.IProgressMonitor;

...

IMtjProject mtjProject;

...

RuntimePlatformDefinition runtimePlatformDefinition =

mtjProject.getProjectData().getDefaultTargetDevice().getRuntimePlatform();

DeploymentManagement deploymentManagement = (DeploymentManagement)MtjServices.getInstance()

.getImplementations(ExtensionType.DEPLOYMENT_MANAGEMENT_LITERAL,null,null)[0];

Device[] devices = deploymentManagement.getTargetDevices(runtimePlatformDefinition);

DeviceCommunicationProtocol[] transferProtocols = null;

IProgressMonitor monitor = null;

deploymentManagement.deploy(mtjProject. getDeployment(), devices, transferProtocols, monitor);

Page 10: Mobile Tools for the Java Platform

101.3.2006

Persistent Store Usage & RuntimePlatforms

DeviceConfiguration

name : Stringversion : String

ImplementationRef

fileRef : StringsourceRef : StringjavadocRef : String

1

+implementation

1

DeviceProfile

name : Stringversion : String

ServiceApi

name : Stringversion : Stringdescription : String

0..1

+implementation

0..1

1..*

+serviceApis

1..*

RuntimePlatformDefinition

name : String

1..*

+deviceConfigurations

1..*

1..*

+deviceProfiles

1..*

1..*+serviceApis1..*

TargetDevice

name : Stringdescription : StringdevicePlatformName : StringdeviceName : StringdeviceGroupName : String

1+runtimePlatform

1

RuntimePlatformname : Stringdescription : String

1..*

+targetDevices1..*

RuntimePlatforms, that are stored by the Workspaces, are stored with the PersistentStorageProvider –plugin. Next example shows, how to access the stored definitions and how to modify them.

The model right describes the object model structure of the RuntimePlatform –definitions.

Page 11: Mobile Tools for the Java Platform

111.3.2006

Persistent Store Usage & RuntimePlatforms (cont.)

import org.eclipse.mtj.api.extension.PersistentStoreProvider;import org.eclipse.mtj.api.enumerations.ExtensionType; import org.eclipse.mtj.api.runtimes.RuntimePlatform;

...

PersistentStoreProvider pstore = (PersistentStoreProvider)MtjServices.getInstance()

.getImplementations(ExtensionType.PERSISTENT_STORE_PROVIDER_LITERAL,null,null)[0];

String dataExtension = ”runtimes”;

String projectName = "org.eclipse.mtj.extension.rpm.ui";

String key = ”MtjRuntimePlatforms”;

EList runtimePlatforms = (EList)pstore.get(PersistentStoreProvider.DATA_TYPE_EMF,

dataExtension ,

projectName ,

key);

RuntimePlatform runtimePlatform= (RuntimePlatform) runtimePlatforms.get(0);

Page 12: Mobile Tools for the Java Platform

121.3.2006

Persistent Store Usage & RuntimePlatforms (cont.)

import org.eclipse.mtj.api.extension.PersistentStoreProvider;import org.eclipse.mtj.api.enumerations.ExtensionType; import org.eclipse.mtj.api.runtimes.RuntimePlatform;

...

PersistentStoreProvider pstore;

Elist runtimePlatforms;

RuntimePlatform newRuntimePlatform;

...

runtimePlatforms.add(newRuntimePlatform);

String dataExtension = ”runtimes”;

String projectName = "org.eclipse.mtj.extension.rpm.ui";

String key = ”MtjRuntimePlatforms”;

pstore.store( runtimePlatforms ,

PersistentStoreProvider.DATA_TYPE_EMF,

dataExtension ,

projectName ,

key);

Page 13: Mobile Tools for the Java Platform

131.3.2006

Get Admin GUI

import org.eclipse.mtj.api.extension.DeviceManagement;

import org.eclipse.mtj.api.enumerations.ExtensionType;

import org.eclipse.mtj.api.extension.MtjExtension;

import org.eclipse.mtj.core.MtjServices;

import org.eclipse.swt.widgets.Composite;

import org.eclipse.SWT;

...

DeviceManagement mtjExtension = null;

Composite composite;

AdminGuiProvider adminGuiProvider = MtjServices.getInstance()

.getCorrespondingAdminGuiProvider(MtjExtension extension);

Composite composite = adminGuiProvider.create(Composite composite, SWT.NONE);