01: /*
02: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
03: *
04: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
05: *
06: * The contents of this file are subject to the terms of either the GNU
07: * General Public License Version 2 only ("GPL") or the Common
08: * Development and Distribution License("CDDL") (collectively, the
09: * "License"). You may not use this file except in compliance with the
10: * License. You can obtain a copy of the License at
11: * http://www.netbeans.org/cddl-gplv2.html
12: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13: * specific language governing permissions and limitations under the
14: * License. When distributing the software, include this License Header
15: * Notice in each file and include the License file at
16: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17: * particular file as subject to the "Classpath" exception as provided
18: * by Sun in the GPL Version 2 section of the License file that
19: * accompanied this code. If applicable, add the following below the
20: * License Header, with the fields enclosed by brackets [] replaced by
21: * your own identifying information:
22: * "Portions Copyrighted [year] [name of copyright owner]"
23: *
24: * Contributor(s):
25: *
26: * Portions Copyrighted 2007 Sun Microsystems, Inc.
27: */
28: package org.netbeans.modules.ruby.hints.infrastructure;
29:
30: import java.util.ArrayList;
31: import java.util.List;
32: import org.netbeans.modules.gsf.api.CompilationInfo;
33: import org.netbeans.modules.ruby.hints.options.HintsAdvancedOption;
34: import org.netbeans.modules.ruby.hints.options.HintsSettings;
35: import org.netbeans.modules.ruby.hints.spi.Rule;
36: import org.netbeans.modules.ruby.hints.spi.UserConfigurableRule;
37: import org.netbeans.spi.editor.hints.ChangeInfo;
38: import org.netbeans.spi.editor.hints.EnhancedFix;
39: import org.netbeans.spi.editor.hints.ErrorDescription;
40: import org.netbeans.spi.editor.hints.Fix;
41: import org.netbeans.spi.editor.hints.HintsController;
42: import org.openide.util.NbBundle;
43:
44: /**
45: *
46: * @author Tor Norbye
47: */
48: public class DisableHintFix implements EnhancedFix {
49: private final UserConfigurableRule rule;
50: private final CompilationInfo info;
51: private final int caretPos;
52: private final String sortText;
53:
54: public DisableHintFix(UserConfigurableRule rule,
55: CompilationInfo info, int caretPos, String sortText) {
56: this .rule = rule;
57: this .info = info;
58: this .caretPos = caretPos;
59: this .sortText = sortText;
60: }
61:
62: public String getText() {
63: return NbBundle.getMessage(HintsAdvancedOption.class,
64: "DisableHint");
65: }
66:
67: public ChangeInfo implement() throws Exception {
68: HintsSettings.setEnabled(RulesManager.getInstance()
69: .getPreferences(rule, null), false);
70:
71: // Force a refresh
72: // HACK ALERT!
73: RubyHintsProvider provider = new RubyHintsProvider();
74: List<ErrorDescription> result = new ArrayList<ErrorDescription>();
75: if (caretPos == -1) {
76: provider.computeHints(info, result);
77: HintsController
78: .setErrors(
79: info.getFileObject(),
80: "org.netbeans.modules.gsfret.hints.infrastructure.HintsTask",
81: result);
82: } else {
83: provider.computeSuggestions(info, result, caretPos);
84: HintsController
85: .setErrors(
86: info.getFileObject(),
87: "org.netbeans.modules.gsfret.hints.infrastructure.SuggestionsTask",
88: result);
89: }
90:
91: return null;
92: }
93:
94: public CharSequence getSortText() {
95: return sortText;
96: }
97: }
|