01: package com.bostechcorp.cbesb.ui.ide.actions;
02:
03: import org.eclipse.core.resources.IFile;
04: import org.eclipse.core.resources.IProject;
05: import org.eclipse.core.resources.IResource;
06: import org.eclipse.jface.action.IAction;
07: import org.eclipse.jface.viewers.ISelection;
08: import org.eclipse.jface.viewers.StructuredSelection;
09: import org.eclipse.ui.IObjectActionDelegate;
10: import org.eclipse.ui.IWorkbenchPart;
11: import org.eclipse.ui.PlatformUI;
12:
13: import com.bostechcorp.cbesb.common.i18n.I18N;
14: import com.bostechcorp.cbesb.common.i18n.Messages;
15: import com.bostechcorp.cbesb.common.util.project.ProjectUtil;
16: import com.bostechcorp.cbesb.ui.util.MsgUtil;
17: import com.bostechcorp.cbesb.ui.util.ViewUtil;
18: import com.bostechcorp.cbesb.ui.util.log.ESBLog;
19:
20: public class BuildProjectAction implements IObjectActionDelegate {
21:
22: protected ISelection selection;
23:
24: protected IWorkbenchPart targetPart;
25:
26: public void setActivePart(IAction action, IWorkbenchPart targetPart) {
27: this .targetPart = targetPart;
28: }
29:
30: public void run(IAction action) {
31: boolean openView = ViewUtil.displayConsoleView(ESBLog.ID);
32: StructuredSelection sele = (StructuredSelection) selection;
33: IProject project = null;
34: if (sele.getFirstElement() instanceof IProject) {
35: project = (IProject) sele.getFirstElement();
36:
37: } else if (sele.getFirstElement() instanceof IFile) {
38: IFile f = (IFile) sele.getFirstElement();
39: project = f.getProject();
40: }
41: if (project != null) {
42: try {
43: ProjectUtil.buildProject(project.getLocation()
44: .toString());
45: project.refreshLocal(IResource.DEPTH_INFINITE, null);
46:
47: } catch (Exception ex) {
48: ex.printStackTrace();
49: MsgUtil.warningMsg(ex.getMessage());
50: return;
51: }
52: MsgUtil.confirmMsg(PlatformUI.getWorkbench()
53: .getActiveWorkbenchWindow().getShell(), I18N
54: .getString(Messages.IDE_BUILD_SUCC));
55: }
56: }
57:
58: public void selectionChanged(IAction action, ISelection selection) {
59:
60: this.selection = selection;
61: action.setEnabled(!selection.isEmpty());
62: }
63: }
|