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.pde.internal.ui.editor.toc;
11:
12: import org.eclipse.core.resources.IFile;
13: import org.eclipse.core.runtime.IStatus;
14: import org.eclipse.core.runtime.Status;
15: import org.eclipse.pde.core.IBaseModel;
16: import org.eclipse.pde.internal.ui.PDEPlugin;
17: import org.eclipse.pde.internal.ui.PDEUIMessages;
18: import org.eclipse.ui.dialogs.ISelectionStatusValidator;
19:
20: /**
21: * TocFileValidator
22: *
23: */
24: public class TocFileValidator implements ISelectionStatusValidator {
25: IBaseModel fModel;
26:
27: /**
28: *
29: */
30: public TocFileValidator(IBaseModel model) {
31: fModel = model;
32: }
33:
34: /* (non-Javadoc)
35: * @see org.eclipse.ui.dialogs.ISelectionStatusValidator#validate(java.lang.Object[])
36: */
37: public IStatus validate(Object[] selection) {
38:
39: // Ensure something was selected
40: if (selection.length == 0) {
41: return errorStatus(""); //$NON-NLS-1$
42: }
43: // Ensure we have a file
44: if ((selection[0] instanceof IFile) == false) {
45: return errorStatus(""); //$NON-NLS-1$
46: }
47: IFile file = (IFile) selection[0];
48: // Ensure we have a TOC file
49: if (!TocExtensionUtil.isTOCFile(file.getFullPath())) {
50: return errorStatus(PDEUIMessages.TocFileValidator_errorInvalidTOC);
51: }
52:
53: //Ensure that the TOC file selected isn't the current file
54: if (TocExtensionUtil.isCurrentResource(file.getFullPath(),
55: fModel)) {
56: return errorStatus(PDEUIMessages.TocFileValidator_errorSameTOC);
57: }
58:
59: // If we got this far, we have a valid file
60: return okStatus(""); //$NON-NLS-1$
61:
62: }
63:
64: /**
65: * @param message
66: * @return
67: */
68: private IStatus errorStatus(String message) {
69: return new Status(IStatus.ERROR, PDEPlugin.getPluginId(),
70: IStatus.ERROR, message, null);
71: }
72:
73: /**
74: * @param message
75: * @return
76: */
77: private IStatus okStatus(String message) {
78: return new Status(IStatus.OK, PDEPlugin.getPluginId(),
79: IStatus.OK, message, null);
80: }
81:
82: }
|