?? abstractcreatepackageaction.java
字號:
/**
* Copyright (c) 2003-2005 Craig Setera
* All Rights Reserved.
* Licensed under the Eclipse Public License - v 1.0
* For more information see http://www.eclipse.org/legal/epl-v10.html
*/
package eclipseme.ui.internal.actions;
import java.util.Iterator;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import eclipseme.core.internal.EclipseMECorePlugin;
import eclipseme.core.internal.utils.LoggingSafeRunnable;
import eclipseme.core.model.IMidletSuiteProject;
import eclipseme.core.model.MidletSuiteFactory;
import eclipseme.core.model.device.IDevice;
import eclipseme.ui.internal.preferences.ObfuscationPreferencePage;
/**
* Abstract action delegate implementation for creating a packaged
* version of a J2ME project. This action will create a
* deployed jar containing the application code as well
* as updating and deploying the JAD file. Subclasses define
* whether or not the created package will be obfuscated or not.
* <p />
* Copyright (c) 2003-2005 Craig Setera<br>
* All Rights Reserved.<br>
* Licensed under the Eclipse Public License - v 1.0<p/>
* <br>
* $Revision: 1.10 $
* <br>
* $Date: 2006/02/16 23:55:43 $
* <br>
* @author Craig Setera
*/
public abstract class AbstractCreatePackageAction extends AbstractJavaProjectAction {
/**
* Default constructor
*/
public AbstractCreatePackageAction() {
super();
}
/**
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
*/
public void run(IAction action) {
if ((selection != null) && !selection.isEmpty()) {
boolean proguardConfigured = true;
if (shouldObfuscate() && !selection.isEmpty()) {
proguardConfigured = isProguardConfigurationValid();
}
if (!proguardConfigured) {
warnAboutProguardConfiguration();
} else {
try {
doPackageCreation();
} catch (CoreException e) {
EclipseMECorePlugin.log(IStatus.ERROR, "Creating package", e);
}
}
}
}
/**
* Return a boolean indicating whether or not the resulting package
* should be obfuscated using Proguard.
*
* @return
*/
protected abstract boolean shouldObfuscate();
/**
* Create the deployed package for the specified java project.
*
* @param monitor
* @param javaProject
*/
private void createPackageForProject(
IProgressMonitor monitor,
IJavaProject javaProject)
{
IMidletSuiteProject suite =
MidletSuiteFactory.getMidletSuiteProject(javaProject);
try {
suite.createPackage(monitor, shouldObfuscate());
} catch (CoreException e) {
EclipseMECorePlugin.log(IStatus.ERROR, "createPackageForProject", e);
ErrorDialog.openError(
getShell(),
"Error packaging " + javaProject.getElementName(),
e.getMessage(),
e.getStatus());
}
}
/**
* Do the work of packaging.
* @throws CoreException
*/
private void doPackageCreation()
throws CoreException
{
// Setup the progress monitoring
ProgressMonitorDialog dialog =
new ProgressMonitorDialog(workbenchPart.getSite().getShell());
dialog.open();
final IProgressMonitor monitor = dialog.getProgressMonitor();
monitor.beginTask("Create Packages", 3);
// Create the packages
Iterator iter = selection.iterator();
while (iter.hasNext()) {
final IJavaProject javaProject = getJavaProject(iter.next());
if (javaProject != null) {
if (doesProjectHaveValidDevice(javaProject)) {
Platform.run(new LoggingSafeRunnable() {
public void run() throws Exception {
createPackageForProject(monitor, javaProject);
}
});
} else {
warnAboutInvalidDevice(javaProject);
}
}
}
// All done
monitor.done();
dialog.close();
}
/**
* Return a boolean indicating whether the project has a valid
* platform definition associated.
*
* @param javaProject
* @return
* @throws CoreException
*/
private boolean doesProjectHaveValidDevice(IJavaProject javaProject)
throws CoreException
{
boolean hasValidDevice = false;
IMidletSuiteProject suite = MidletSuiteFactory.getMidletSuiteProject(javaProject);
if (suite != null) {
IDevice device = suite.getDevice();
hasValidDevice = (device != null);
}
return hasValidDevice;
}
/**
* Return a boolean indicating whether the proguard configuration
* is valid for obfuscation.
*
* @return
*/
private boolean isProguardConfigurationValid() {
return EclipseMECorePlugin.getProguardJarFile().exists();
}
/**
* Warn the user that the project being packaged does not
* have a valid device and won't be packaged.
* @param javaProject
*/
private void warnAboutInvalidDevice(IJavaProject javaProject) {
String message =
javaProject.getElementName() + " does not have a valid device.\n" +
javaProject.getElementName() + " will not be packaged.";
MessageDialog.openWarning(getShell(), "Invalid Device", message);
}
/**
* Warn the user that Proguard is not correctly configured
* for creating obfuscated packages.
*/
private void warnAboutProguardConfiguration() {
String message =
"Proguard is not correctly configured.\n" +
"Please configure Proguard preferences.";
ConfigurationErrorDialog dialog = new ConfigurationErrorDialog(
getShell(),
ObfuscationPreferencePage.ID,
"Obfuscation Error",
message,
"Configure Proguard...");
dialog.open();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -