01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package org.terracotta.dso.actions;
06:
07: import org.eclipse.jdt.core.IJavaElement;
08: import org.eclipse.swt.widgets.Event;
09: import org.eclipse.swt.widgets.Shell;
10: import org.terracotta.dso.PatternHelper;
11: import org.terracotta.dso.dialogs.NamedLockDialog;
12:
13: import com.tc.util.event.UpdateEvent;
14: import com.tc.util.event.UpdateEventListener;
15: import com.terracottatech.config.LockLevel;
16:
17: /**
18: * Marks the currently selected method as being name-locked. Creates a default name based on the simple name of the
19: * method and sets the lock-type to WRITE.
20: *
21: * @see org.eclipse.jdt.core.IMethod
22: * @see BaseAction
23: * @see org.terracotta.dso.ConfigurationHelper.isNameLocked
24: * @see org.terracotta.dso.ConfigurationHelper.ensureNameLocked
25: * @see org.terracotta.dso.ConfigurationHelper.ensureNotNameLocked
26: */
27:
28: public class NameLockedAction extends BaseAction {
29: public NameLockedAction() {
30: super ("Name Locked", AS_CHECK_BOX);
31: }
32:
33: public void setJavaElement(IJavaElement element) {
34: super .setJavaElement(element);
35: setChecked(getConfigHelper().isNameLocked(element));
36: }
37:
38: public void performAction(Event event) {
39: if (isChecked()) {
40: Shell shell = ActionUtil.findSelectedEditorPart().getSite()
41: .getShell();
42: NamedLockDialog dialog = new NamedLockDialog(shell,
43: PatternHelper.getExecutionPattern(m_element));
44: dialog.addValueListener(new UpdateEventListener() {
45: public void handleUpdate(UpdateEvent e) {
46: Object[] values = (Object[]) e.data;
47: getConfigHelper().ensureNameLocked(m_element,
48: (String) values[0],
49: (LockLevel.Enum) values[1]);
50: }
51: });
52: dialog.open();
53: } else {
54: getConfigHelper().ensureNotNameLocked(m_element);
55: }
56:
57: inspectCompilationUnit();
58: }
59: }
|