import org.tizen.nativeplatform.Activator;
public class BuildPackageObjectAction implements IWorkbenchWindowActionDelegate, IObjectActionDelegate {
- protected IProject project;
- protected IWorkbenchWindow window;
- private IStatus status = null;
- private final String PKGTYPE = "RPM";
-
- public BuildPackageObjectAction() {
- }
-
- public BuildPackageObjectAction(IProject project) {
- this.project = project;
- }
-
- @Override
- public void run(IAction action) {
-
- CommonBuildPackageFile.setPackageType(project, PKGTYPE);
- window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
- ProgressMonitorDialog dialog = new ProgressMonitorDialog(window.getShell());
-
- try {
- dialog.run(true, true, new IRunnableWithProgress() {
- @Override
- public void run(IProgressMonitor monitor) throws InvocationTargetException,
- InterruptedException {
- status = null;
- monitor.beginTask(CommonBuildMessages.PACKAGING_APPLICATION, -1);
-
- CommonProjectDependentPackager packager = ProjectTypeManager.getProjectPackagerInstance(project);
- CheckCancelJob cancelJob = new CheckCancelJob(monitor, project, packager.getSbi(), true);
- Thread checkCancelThread = new Thread(cancelJob);
- checkCancelThread.start();
-
- try {
- monitor.subTask("Building package...");
- packager.buildPackage(PKGTYPE);
- } catch (SBIException e) {
- e.printStackTrace();
- status = new Status(Status.ERROR, Activator.PLUGIN_ID, CommonBuildMessages.FAIL_TO_BUILD_PACKAGE);
- cancelJob.setFinishFlag(true);
- monitor.done();
- return;
- }
- cancelJob.setFinishFlag(true);
- monitor.done();
- }
- });
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- if (status != null) {
- if (status.isOK()) {
- MessageDialog.openInformation(window.getShell(), CommonBuildMessages.BUILD_RESULT, status.getMessage());
- } else {
- MessageDialog.openError(window.getShell(), CommonBuildMessages.BUILD_RESULT, status.getMessage());
- }
- }
-
-
- // refresh the project explorer
- try {
- project.refreshLocal(IResource.DEPTH_INFINITE, null );
- } catch (CoreException e) {
- e.printStackTrace();
- }
- }
-
- protected File findFirstFilebyExtension(File searchPath, String ext) {
- File[] allFiles = searchPath.listFiles(new ExtFilter(ext));
- if (allFiles == null || allFiles.length == 0)
- return null;
- return allFiles[0];
- }
-
- protected class ExtFilter implements FilenameFilter {
- protected String ext;
-
- public ExtFilter(String ext) {
- this.ext = ext;
- }
-
- public boolean accept(File dir, String name) {
- return name.endsWith(ext);
- }
- }
-
- @Override
- public void selectionChanged(IAction action, ISelection selection) {
- Object obj = null;
-
- if (selection instanceof TreeSelection) {
- TreeSelection _selection = (TreeSelection)selection;
-
- if (_selection != null) {
- obj = _selection.getFirstElement();
- }
- }
-
- if (obj != null) {
- if (obj instanceof IProject) {
- project = (IProject) obj;
- }
- }
- }
-
- @Override
- public void setActivePart(IAction action, IWorkbenchPart targetPart) {
- // do nothing
- }
-
- @Override
- public void dispose() {
- // do nothing
- }
-
- @Override
- public void init(IWorkbenchWindow window) {
- // do nothing
- }
-
- private class checkBuildPackageContinue implements Runnable {
- private int result = -1;
-
- public checkBuildPackageContinue() {
- }
-
- @Override
- public void run() {
- synchronized(this) {
- // TODO Auto-generated method stub
- Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
- boolean bResult = MessageDialog.openQuestion(shell, "Question",
- "Dependency checking has finished.\nDo you want to continue ?");
- if (bResult) {
- result = 1;
- } else {
- result = 0;
- }
- }
- }
-
- public int getResult() {
- return this.result;
- }
- };
+ protected IProject project;
+ protected IWorkbenchWindow window;
+ private IStatus status = null;
+ private final String PKGTYPE = "RPM";
+
+ public BuildPackageObjectAction() {
+ }
+
+ public BuildPackageObjectAction(IProject project) {
+ this.project = project;
+ }
+
+ @Override
+ public void run(IAction action) {
+
+ CommonBuildPackageFile.setPackageType(project, PKGTYPE);
+ window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ ProgressMonitorDialog dialog = new ProgressMonitorDialog(window.getShell());
+
+ try {
+ dialog.run(true, true, new IRunnableWithProgress() {
+ @Override
+ public void run(IProgressMonitor monitor) throws InvocationTargetException,
+ InterruptedException {
+ status = null;
+ monitor.beginTask(CommonBuildMessages.PACKAGING_APPLICATION, -1);
+
+ CommonProjectDependentPackager packager = ProjectTypeManager.getProjectPackagerInstance(project);
+ CheckCancelJob cancelJob = new CheckCancelJob(monitor, project, packager.getSbi(), true);
+ Thread checkCancelThread = new Thread(cancelJob);
+ checkCancelThread.start();
+
+ try {
+ monitor.subTask("Building package...");
+ packager.buildPackage(PKGTYPE);
+ } catch (SBIException e) {
+ e.printStackTrace();
+ status = new Status(Status.ERROR, Activator.PLUGIN_ID, CommonBuildMessages.FAIL_TO_BUILD_PACKAGE);
+ cancelJob.setFinishFlag(true);
+ monitor.done();
+ return;
+ } catch (CoreException e) {
+ status = new Status(Status.ERROR, Activator.PLUGIN_ID, e.getMessage());
+ cancelJob.setFinishFlag(true);
+ monitor.done();
+ return;
+ }
+
+ cancelJob.setFinishFlag(true);
+ monitor.done();
+ }
+ });
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+
+ if (status != null) {
+ if (status.isOK()) {
+ MessageDialog.openInformation(window.getShell(), CommonBuildMessages.BUILD_RESULT, status.getMessage());
+ } else {
+ MessageDialog.openError(window.getShell(), CommonBuildMessages.BUILD_RESULT, status.getMessage());
+ }
+ }
+
+
+ // refresh the project explorer
+ try {
+ project.refreshLocal(IResource.DEPTH_INFINITE, null );
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
+ protected File findFirstFilebyExtension(File searchPath, String ext) {
+ File[] allFiles = searchPath.listFiles(new ExtFilter(ext));
+ if (allFiles == null || allFiles.length == 0)
+ return null;
+ return allFiles[0];
+ }
+
+ protected class ExtFilter implements FilenameFilter {
+ protected String ext;
+
+ public ExtFilter(String ext) {
+ this.ext = ext;
+ }
+
+ public boolean accept(File dir, String name) {
+ return name.endsWith(ext);
+ }
+ }
+
+ @Override
+ public void selectionChanged(IAction action, ISelection selection) {
+ Object obj = null;
+
+ if (selection instanceof TreeSelection) {
+ TreeSelection _selection = (TreeSelection)selection;
+
+ if (_selection != null) {
+ obj = _selection.getFirstElement();
+ }
+ }
+
+ if (obj != null) {
+ if (obj instanceof IProject) {
+ project = (IProject) obj;
+ }
+ }
+ }
+
+ @Override
+ public void setActivePart(IAction action, IWorkbenchPart targetPart) {
+ // do nothing
+ }
+
+ @Override
+ public void dispose() {
+ // do nothing
+ }
+
+ @Override
+ public void init(IWorkbenchWindow window) {
+ // do nothing
+ }
+
+ private class checkBuildPackageContinue implements Runnable {
+ private int result = -1;
+
+ public checkBuildPackageContinue() {
+ }
+
+ @Override
+ public void run() {
+ synchronized(this) {
+ // TODO Auto-generated method stub
+ Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
+ boolean bResult = MessageDialog.openQuestion(shell, "Question",
+ "Dependency checking has finished.\nDo you want to continue ?");
+ if (bResult) {
+ result = 1;
+ } else {
+ result = 0;
+ }
+ }
+ }
+
+ public int getResult() {
+ return this.result;
+ }
+ };
}