01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package org.terracotta.dso.actions;
05:
06: import org.eclipse.jdt.core.IJavaElement;
07: import org.eclipse.swt.widgets.Shell;
08: import org.terracotta.dso.ConfigurationHelper;
09: import org.terracotta.dso.PatternHelper;
10: import org.terracotta.dso.dialogs.AutolockDialog;
11:
12: import com.tc.util.event.UpdateEvent;
13: import com.tc.util.event.UpdateEventListener;
14: import com.terracottatech.config.Autolock;
15: import com.terracottatech.config.LockLevel;
16:
17: /**
18: * Mark the currently selected IMethod as being autolocked.
19: *
20: * @see org.terracotta.dso.ConfigurationHelper.isAutolocked
21: * @see org.terracotta.dso.ConfigurationHelper.ensureAutolocked
22: * @see org.terracotta.dso.ConfigurationHelper.ensureNotAutolocked
23: */
24:
25: public class AutolockAction extends BaseAction {
26: public AutolockAction() {
27: super ("Autolock", AS_CHECK_BOX);
28: }
29:
30: public void setJavaElement(IJavaElement element) {
31: super .setJavaElement(element);
32: setChecked(getConfigHelper().isAutolocked(element));
33: }
34:
35: public void performAction() {
36: final ConfigurationHelper helper = getConfigHelper();
37:
38: if (isChecked()) {
39: Shell shell = ActionUtil.findSelectedEditorPart().getSite()
40: .getShell();
41: final String pattern = PatternHelper
42: .getExecutionPattern(m_element);
43: AutolockDialog dialog = new AutolockDialog(shell, pattern);
44: dialog.addValueListener(new UpdateEventListener() {
45: public void handleUpdate(UpdateEvent e) {
46: Object[] values = (Object[]) e.data;
47: boolean autoSync = (Boolean) values[0];
48: LockLevel.Enum level = (LockLevel.Enum) values[1];
49: Autolock lock = helper.addNewAutolock(pattern,
50: level);
51: lock.setAutoSynchronized(autoSync);
52: }
53: });
54: dialog.open();
55: } else {
56: helper.ensureNotAutolocked(m_element);
57: }
58:
59: inspectCompilationUnit();
60: }
61: }
|