Title: Mobile Tools for the Java Platform
1Mobile Tools forthe Java Platform
- Coding Examples
- Version 0.3
2Get Extension Implementation
import org.eclipse.mtj.api.extension.DeviceManagem
ent import org.eclipse.mtj.api.enumerations.Exten
sionType import org.eclipse.mtj.api.extension.Mtj
Extension import org.eclipse.mtj.core.MtjServices
... String version null String vendor
null boolean onlyActive true MtjExtension
list MtjServices.getInstance() .getImplementati
ons( ExtensionType.DEVICE_MANAGEMENT_LITERAL, v
ersion, vendor, onlyActive) DeviceManageme
nt deviceManagement (DeviceManagement )
list0
3Get DevicePlatform, Device and RuntimePlatform
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.
4Get DevicePlatform, Device and RuntimePlatform
(cont.)
import org.eclipse.mtj.api.extension.DeviceManagem
ent import org.eclipse.mtj.api.enumerations.Exten
sionType import org.eclipse.mtj.api.extension.Mtj
Extension import org.eclipse.mtj.core.MtjServices
import org.eclipse.mtj.api.devices.Device impor
t org.eclipse.mtj.api.devices.DevicePlatform impo
rt org.eclipse.mtj.api.runtimes.RuntimePlatformDef
inition ... DeviceManagement deviceManagement
(DeviceManagement) MtjServices.getInstance() .get
Implementations( ExtensionType.DEVICE_MANAGEMENT_L
ITERAL,null,null)0 DevicePlatform
devicePlatform deviceManagement
.getDevicePlatforms()0 Device device
devicePlatform.getDevices().get(1) RuntimePlatfo
rmDefinition runtimePlatformDefinition device
.getRuntimePlatformDefinitions().get(1)
5Modify Project Data
Projects, that have Mtj Nature, contains Mtj
specific descriptions. Next example shows, how to
access Projects descriptions and how to modify
them. The model right describes the object model
structure of the Project definitions.
6Modify 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 ... IJavaPro
ject javaProject ... IMtjProject mtjProject
MtjProject.getMtjProject(javaProject) Project
project mtjProject.getProjectData() Obfuscatio
nDetail obfuscationDetail new
ObfuscationDetail() obfuscationDetail.setLevel(1)
project.setObfuscationDetail(obfuscationDetail)
mtjProject.setProjectData(project)
7Add 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.RuntimePlatformDefin
ition import org.eclipse.mtj.api.project.Project
import org.eclipse.mtj.api.project.ProjectFactor
y import org.eclipse.mtj.api.project.TargetDevice
import org.eclipse.mtj.core.util.MtjEmfUtil ...
Project project DevicePlatform
devicePlatform Device device RuntimePlatformDefi
nition runtimePlatformDefinition ... TargetDevic
e targetDevice ProjectFactory.eINSTANCE.createTa
rgetDevice() targetDevice.setName(Nokia S80
Device) targetDevice.setDevicePlatformName(devic
ePlatform.getName()) targetDevice.setDeviceName(d
evice.getName()) // create a project specific
copy of the RuntimePlatformDefinition RuntimePlatf
ormDefinition copyRPD MtjEmfUtil.clone(runtimePl
atformDefinition) targetDevice.setRuntimePlatform
(copyRPD) mtjProject.setProjectData(project)
8Get Projects 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.RuntimePlatformDefin
ition ... IJavaProject javaProject ... IMtjProj
ect mtjProject MtjProject.getMtjProject(javaProj
ect) DevicePlatform devicePlatform
mtjProject.getPlatformDefinition() Device device
mtjProject.getDefaultDevice() RuntimePlatformD
efinition runtimePlatformDefinition
mtjProject.getProjectData().getDefaultTargetDevi
ce().getRuntimePlatform()
9Deploy Projects Data
import org.eclipse.mtj.api.model.IMtjProject impo
rt org.eclipse.mtj.api.devices.Device import
org.eclipse.mtj.api.extension. DeploymentManagemen
t import org.eclipse.mtj.api.runtimes.RuntimePla
tformDefinition import org.eclipse.mtj.api.enumer
ations.DeviceCommunicationProtocol import
org.eclipse.core.runtime.IProgressMonitor ... IM
tjProject mtjProject ... RuntimePlatformDefinitio
n runtimePlatformDefinition mtjProject.getProj
ectData().getDefaultTargetDevice().getRuntimePlatf
orm() DeploymentManagement deploymentManagement
(DeploymentManagement)MtjServices.getInstance()
.getImplementations(ExtensionType.DEPLOYMENT_MANA
GEMENT_LITERAL,null,null)0 Device devices
deploymentManagement.getTargetDevices(runtimePlatf
ormDefinition) DeviceCommunicationProtocol
transferProtocols null IProgressMonitor
monitor null deploymentManagement.deploy(mtjPro
ject. getDeployment(), devices,
transferProtocols, monitor)
10Persistent Store Usage RuntimePlatforms
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.
11Persistent Store Usage RuntimePlatforms (cont.)
import org.eclipse.mtj.api.extension.PersistentSto
reProvider import org.eclipse.mtj.api.enumeration
s.ExtensionType import org.eclipse.mtj.api.runti
mes.RuntimePlatform ... PersistentStoreProvider
pstore (PersistentStoreProvider)MtjServices.getI
nstance() .getImplementations(ExtensionType.PERSI
STENT_STORE_PROVIDER_LITERAL,null,null)0
String dataExtension runtimes String
projectName "org.eclipse.mtj.extension.rpm.ui"
String key MtjRuntimePlatform
s EList runtimePlatforms (EList)pstore.get(Pe
rsistentStoreProvider.DATA_TYPE_EMF,
dataExtension , projectName
, key) RuntimePlatform
runtimePlatform (RuntimePlatform)
runtimePlatforms.get(0)
12Persistent Store Usage RuntimePlatforms (cont.)
import org.eclipse.mtj.api.extension.PersistentSto
reProvider import org.eclipse.mtj.api.enumeration
s.ExtensionType import org.eclipse.mtj.api.runti
mes.RuntimePlatform ... PersistentStoreProvider
pstore Elist runtimePlatforms RuntimePlatform
newRuntimePlatform ... runtimePlatforms.add(newRu
ntimePlatform) String dataExtension
runtimes String projectName
"org.eclipse.mtj.extension.rpm.ui" String key
MtjRuntimePlatforms pstore.stor
e( runtimePlatforms ,
PersistentStoreProvider.DATA_TYPE_EMF,
dataExtension , projectName , key)
13Get Admin GUI
import org.eclipse.mtj.api.extension.DeviceManagem
ent import org.eclipse.mtj.api.enumerations.Exten
sionType import org.eclipse.mtj.api.extension.Mtj
Extension import org.eclipse.mtj.core.MtjServices
import org.eclipse.swt.widgets.Composite import
org.eclipse.SWT ... DeviceManagement
mtjExtension null Composite composite AdminGu
iProvider adminGuiProvider MtjServices.getInsta
nce() .getCorrespondingAdminGuiProvider(MtjExtens
ion extension) Composite composite
adminGuiProvider.create(Composite composite,
SWT.NONE)