01: /*******************************************************************************
02: * Copyright (c) 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: ******************************************************************************/package org.eclipse.ui.examples.contributions.editor;
11:
12: import org.eclipse.core.commands.AbstractHandler;
13: import org.eclipse.core.commands.ExecutionEvent;
14: import org.eclipse.core.commands.ExecutionException;
15: import org.eclipse.jface.dialogs.MessageDialog;
16: import org.eclipse.ui.examples.contributions.ContributionMessages;
17: import org.eclipse.ui.examples.contributions.model.Person;
18: import org.eclipse.ui.handlers.HandlerUtil;
19:
20: /**
21: * Show if there is any delta from the model for the active editor.
22: *
23: * @since 3.3
24: */
25: public class DeltaInfoHandler extends AbstractHandler {
26:
27: /*
28: * (non-Javadoc)
29: *
30: * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
31: */
32: public Object execute(ExecutionEvent event)
33: throws ExecutionException {
34: InfoEditor editor = (InfoEditor) HandlerUtil
35: .getActiveEditorChecked(event);
36: Person model = editor.getModelPerson();
37: Person local = editor.getLocalPerson();
38:
39: boolean delta = false;
40: StringBuffer buf = new StringBuffer();
41: buf.append(ContributionMessages.InfoEditor_surname);
42: if (!model.getSurname().equals(local.getSurname())) {
43: delta = true;
44: buf.append(' ');
45: buf.append(model.getSurname());
46: buf.append(", "); //$NON-NLS-1$
47: buf.append(local.getSurname());
48: }
49: buf.append(" - "); //$NON-NLS-1$
50: buf.append(ContributionMessages.InfoEditor_givenname);
51: if (!model.getGivenname().equals(local.getGivenname())) {
52: delta = true;
53: buf.append(' ');
54: buf.append(model.getGivenname());
55: buf.append(", "); //$NON-NLS-1$
56: buf.append(local.getGivenname());
57: }
58: buf.append(" - "); //$NON-NLS-1$
59: if (delta) {
60: buf.append(ContributionMessages.DeltaInfoHandler_found);
61: } else {
62: buf.append(ContributionMessages.DeltaInfoHandler_notFound);
63: }
64: MessageDialog.openInformation(editor.getSite().getShell(),
65: ContributionMessages.DeltaInfoHandler_shellTitle, buf
66: .toString());
67: return null;
68: }
69: }
|