use of org.netbeans.api.annotations.common.CheckForNull in project netbeans-rcp-lite by outersky.
the class KeyStrokeUtils method getKeyStrokes.
/**
* Converts a textual representation of key strokes to an array of <code>KeyStroke</code>
* objects. Please see {@link #keyStrokesToString(Collection<KeyStroke>, boolean)}
* ror details about the available formats.
*
* @param key The textual representation of keystorkes to convert. Its format
* depends on the value of <code>emacsStyle</code> parameter.
*
* @return The <code>KeyStroke</code>s that were represented by the <code>key</code>
* text or <code>null</code> if the textual representation was malformed.
* @since 1.16
*/
@CheckForNull
public static KeyStroke[] getKeyStrokes(@NonNull String key) {
// NOI18N
assert key != null : "The parameter key must not be null";
List<KeyStroke> result = new ArrayList<KeyStroke>();
// NOI18N
String delimiter = " ";
for (StringTokenizer st = new StringTokenizer(key, delimiter); st.hasMoreTokens(); ) {
// NOI18N
String ks = st.nextToken().trim();
KeyStroke keyStroke = getKeyStroke(ks);
if (keyStroke != null) {
result.add(keyStroke);
} else {
if (LOG.isLoggable(Level.FINE)) {
LOG.log(Level.FINE, "Invalid keystroke string: ''{0}''", // NOI18N
ks);
}
return null;
}
}
return result.toArray(new KeyStroke[result.size()]);
}
use of org.netbeans.api.annotations.common.CheckForNull in project netbeans-rcp-lite by outersky.
the class SearchInfoUtils method findDefinedSearchInfo.
/**
* Get a search info for a node, if it was explicitly defined in node's
* lookup, or in lookup of a ancestor node. Default search info is not
* created.
*
* @see #getSearchInfoForNode(org.openide.nodes.Node)
*
* @return Defined SearchInfo, or null if not available.
*/
@CheckForNull
public static SearchInfo findDefinedSearchInfo(@NonNull Node node) {
// NOI18N
Parameters.notNull("node", node);
SearchInfoDefinition sid = SearchInfoDefinitionUtils.findSearchInfoDefinition(node);
if (sid != null) {
return new DelegatingSearchInfo(sid);
} else {
return null;
}
}
use of org.netbeans.api.annotations.common.CheckForNull in project netbeans-rcp-lite by outersky.
the class SearchInfoUtils method getSearchInfoForNode.
/**
* Gets a search info for node.
*
* <div class="nonnormative">
* <p>
* Algorithm for getting search info:
* </p>
* <ol>
* <li>Look for SearchInfoDefinition in lookup of the node. If found,
* create and return search info for this definition.</li>
* <li>Look for SubTreeSearchOptions in lookups of this node and its
* ancestors. If found, check if the node has a {@link FileObject}
* (possibly as primary file of a {@link DataObject}) in its lookup,
* and, if so, create search info for recursive searching in the file
* object, using filters defined in found {@link SubTreeSearchOptions}.
* </li>
* <li>Check whether the node has a {@link FileObject}
* (possibly as primary file of a {@link DataObject}) in is lookup. If
* so, create default search info for that file object. Default means
* that the file object will be searched recursively, using default
* filters.
* </li>
* <li>
* Return null.
* </li>
* </ol>
* </div>
*
* @see FileObject
* @see DataObject
* @see SearchInfoDefinition
* @see SubTreeSearchOptions
* @see #findDefinedSearchInfo(org.openide.nodes.Node)
*
* @return Search info for a node. If no search info was defined and it
* cannot be created for this node, null is returned.
*/
@CheckForNull
public static SearchInfo getSearchInfoForNode(@NonNull Node node) {
// NOI18N
Parameters.notNull("node", node);
SearchInfoDefinition sid = SearchInfoDefinitionUtils.getSearchInfoDefinition(node);
if (sid == null) {
return null;
} else {
return new DelegatingSearchInfo(sid);
}
}
use of org.netbeans.api.annotations.common.CheckForNull in project netbeans-rcp-lite by outersky.
the class PluginManager method install.
/**
* Open standard dialog for installing modules including declared dependencies.
* Shows it to the user, asks for confirmation, license acceptance, etc.
* The whole operation requires AWT dispatch thread access (to show the dialog)
* and blocks (until the user clicks through), so either call from AWT dispatch
* thread directly, or be sure you hold no locks and block no progress of other
* threads to avoid deadlocks.
*
* @param codenamebases the codenamebases of modules to install; must contain at least
* one codenamebase
* @param alternativeOptions alternative options possibly displayed in error
* dialog user may choose if it is not possible to install the plugin;
* if chosen the option is return value of this method
* @return <code>null</code> if all the requested modules have been successfully
* installed and/or activated, otherwise it returns the options user has
* selected in problem dialog, typically {@link NotifyDescriptor#DEFAULT_OPTION}
* (on esc), {@link NotifyDescriptor#CANCEL_OPTION} or
* any of <code>alternativeOptions</code>.
* @throws IllegalArgumentException if the <code>codenamebases</code> is empty
* @since 1.35
*/
@CheckForNull
public static Object install(@NonNull Set<String> codenamebases, @NonNull Object... alternativeOptions) {
Parameters.notNull("cnb", codenamebases);
Parameters.notNull("alternativeOptions", alternativeOptions);
if (codenamebases.isEmpty()) {
throw new IllegalArgumentException("No plugins to install");
}
try {
return new ModuleInstallerSupport(alternativeOptions).installPlugins(null, codenamebases);
} catch (OperationException ex) {
Logger.getLogger(PluginManager.class.getName()).log(Level.WARNING, null, ex);
}
return NotifyDescriptor.DEFAULT_OPTION;
}
use of org.netbeans.api.annotations.common.CheckForNull in project netbeans-rcp-lite by outersky.
the class FileBuilder method createFromTemplate.
/**
* Creates a new file based on the template. This convenience method is intended for easier
* migration of clients using DataLoader templating API before {@link FileBuilder} introduction.
* The method will collect parameters
* tied to the template using registered {@link CreateFromTemplateAttributes} providers,
* and will try to locate a willing {@link CreateFromTemplateHandler} that will create
* the target file. If no such handler exists, and the {@code defaultCopy} parameter is true,
* the file contents is just copied to the target location.
* <p>
* If the {@code name} parameter is null, the function attempts to compute a suitable name
* from the file.
* <p>
* The default copy algorithm uses the supplied {@link Mode#FORMAT} to
* process tokens.
* <p>
* If the passed {@code name} is {@code null}, the implementation will pick a free name based on
* the template's own name (see {@link FileUtil#findFreeFileName}).
* @param f the template file
* @param folder the target folder, must exist
* @param name the desired name. If {@code null}, the implementation will choose the name.
* @param attributes values to apply on the template. May be {@code null} = no values.
* @param defaultMode the mode of operations to use
* @return The created file, or {@code null} if no creation handler is located.
* @throws IOException when an I/O operation fails
*/
@SuppressWarnings("AssignmentToMethodParameter")
@CheckForNull
public static FileObject createFromTemplate(@NonNull FileObject f, @NonNull FileObject folder, @NullAllowed String name, @NullAllowed Map<String, ?> attributes, Mode defaultMode) throws IOException {
Format frm = null;
switch(defaultMode) {
case FORMAT:
MapFormat mf = new MapFormat(new HashMap());
mf.setExactMatch(false);
mf.setLeftBrace("__");
mf.setRightBrace("__");
frm = mf;
break;
case COPY:
frm = new Format() {
@Override
public StringBuffer format(Object obj, StringBuffer toAppendTo, FieldPosition pos) {
toAppendTo.append(obj);
return toAppendTo;
}
@Override
public Object parseObject(String source, ParsePosition pos) {
// To change body of generated methods, choose Tools | Templates.
throw new UnsupportedOperationException("Not supported yet.");
}
};
break;
}
FileBuilder fb = new FileBuilder(f, folder).name(name).withParameters(attributes).useFormat(frm).defaultMode(defaultMode);
List<FileObject> fos = fb.build();
if (fos == null || fos.isEmpty()) {
return null;
} else {
return fos.iterator().next();
}
}
Aggregations