001: /**
002: *
003: */package gui.participants;
004:
005: import org.eclipse.core.runtime.CoreException;
006: import org.eclipse.core.runtime.IProgressMonitor;
007: import org.eclipse.core.runtime.OperationCanceledException;
008: import org.eclipse.ltk.core.refactoring.Change;
009: import org.eclipse.ltk.core.refactoring.RefactoringStatus;
010: import org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext;
011: import org.eclipse.ltk.core.refactoring.participants.RenameArguments;
012: import org.eclipse.ltk.core.refactoring.participants.RenameParticipant;
013: import org.openarchitectureware.workflow.issues.Issue;
014: import org.openarchitectureware.workflow.issues.Issues;
015:
016: import core.ModelAccessTest;
017:
018: /**
019: * This is a participant which takes part in the eclipse compilation
020: * unit rename refactorings. It includes the CUModelChange class
021: * which adapts the changes to the process model.
022: *
023: * @author sh
024: */
025: public class CURenameParticipant extends RenameParticipant {
026: // the selected element to refacter
027: private Object selection = null;
028:
029: // the input of the refactoring dialog
030: private RenameArguments arguments = null;
031:
032: /**
033: * Constructor
034: */
035: public CURenameParticipant() {
036: }
037:
038: /*
039: * check all conditions if the model update culd be executed.
040: *
041: * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#checkConditions(org.eclipse.core.runtime.IProgressMonitor, org.eclipse.ltk.core.refactoring.participants.CheckConditionsContext)
042: */
043: @Override
044: public RefactoringStatus checkConditions(IProgressMonitor pm,
045: CheckConditionsContext context)
046: throws OperationCanceledException {
047:
048: // do the check here if the model update could be executed
049: RefactoringStatus result = new RefactoringStatus();
050:
051: // check if model could be read
052: Issues issues = ModelAccessTest.INSTANCE.readModel();
053: Issue[] errors = issues.getErrors();
054: for (int i = 0; i < errors.length; i++) {
055: Issue issue = errors[i];
056: result.addFatalError(issue.getMessage());
057: }
058: return result;
059: }
060:
061: /* (non-Javadoc)
062: * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#createChange(org.eclipse.core.runtime.IProgressMonitor)
063: */
064: @Override
065: public Change createChange(IProgressMonitor pm)
066: throws CoreException, OperationCanceledException {
067:
068: try {
069: pm.beginTask("Collecting changes", 100);
070: CUModelChange change = new CUModelChange(this .selection,
071: this .arguments);
072: pm.worked(100);
073: return change;
074: } finally {
075: pm.done();
076: }
077: }
078:
079: /* (non-Javadoc)
080: * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#getName()
081: */
082: @Override
083: public String getName() {
084: return new String("Compilation Unit Rename Participant");
085: }
086:
087: /*
088: * This initializes the Rename Participant with the selection element.
089: * and the input of the Refactoring Dialog.
090: *
091: * @see org.eclipse.ltk.core.refactoring.participants.RefactoringParticipant#initialize(java.lang.Object)
092: */
093: @Override
094: protected boolean initialize(Object element) {
095: // the arguments of the Refactoring Dialog
096: this .arguments = getArguments();
097:
098: // the selection object
099: this .selection = element;
100:
101: // this participant could enabled by returning true
102: return true;
103: }
104: }
|