130 likes | 260 Views
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;
E N D
Mobile Tools forthe 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; 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];
Get 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.
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);
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.
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);
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);
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();
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);
Persistent 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.
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);
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);
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);