本文整理汇总了Java中com.intellij.openapi.ide.CopyPasteManager.setContents方法的典型用法代码示例。如果您正苦于以下问题:Java CopyPasteManager.setContents方法的具体用法?Java CopyPasteManager.setContents怎么用?Java CopyPasteManager.setContents使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.intellij.openapi.ide.CopyPasteManager
的用法示例。
在下文中一共展示了CopyPasteManager.setContents方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: actionPerformed
import com.intellij.openapi.ide.CopyPasteManager; //导入方法依赖的package包/类
/**
* execute sql generation and copy task
*
* @param e action event
*/
public void actionPerformed(AnActionEvent e) {
PsiFile psiFile = e.getData(DataKeys.PSI_FILE);
Editor editor = e.getData(DataKeys.EDITOR);
if ((psiFile != null && psiFile instanceof XmlFile) && editor != null) {
PsiElement psiElement = psiFile.findElementAt(editor.getCaretModel().getOffset());
if (psiElement != null) {
XmlTag xmlTag = getResultMapTag(psiElement);
if (xmlTag != null) {
DomElement domElement = DomManager.getDomManager(psiFile.getProject()).getDomElement(xmlTag);
if (domElement != null && domElement instanceof ResultMap) {
List<String> columns = new ArrayList<String>();
ResultMap resultMap = (ResultMap) domElement;
List<Result> allResults = resultMap.getAllResults();
for (Result result : allResults) {
String columnName = result.getColumn().getValue();
if (columnName != null && columnName.length() > 0 && !columns.contains(columnName)) {
columns.add(columnName);
}
}
PsiClass psiClass = resultMap.getClazz().getValue();
if (psiClass != null) {
String tableName = "table_name_here";
String select = "*";
DatabaseTableData tableData = TableColumnReferenceProvider.getDatabaseTableData(psiClass);
if (tableData != null) {
tableName = tableData.getName();
}
if (columns.size() > 0) {
select = StringUtil.join(columns, ", ");
}
String sentenceSQL = "select " + select + " from " + tableName;
CopyPasteManager copyPasteManager = CopyPasteManager.getInstance();
copyPasteManager.setContents(new StringSelection(sentenceSQL));
}
}
}
}
}
}
示例2: actionPerformed
import com.intellij.openapi.ide.CopyPasteManager; //导入方法依赖的package包/类
public void actionPerformed(AnActionEvent e) {
PsiFile psiFile = e.getData(DataKeys.PSI_FILE);
Editor editor = e.getData(DataKeys.EDITOR);
if ((psiFile != null && psiFile instanceof XmlFile) && editor != null) {
PsiElement psiElement = psiFile.findElementAt(editor.getCaretModel().getOffset());
if (psiElement != null) {
XmlTag xmlTag = SqlMapSymbolCompletionData.getXmlTagForSQLCompletion(psiElement, psiFile);
if (xmlTag != null) {
DomElement domElement = DomManager.getDomManager(e.getData(DataKeys.PROJECT)).getDomElement(xmlTag);
if (domElement != null && domElement instanceof BaseStatement) {
BaseStatement baseStatement = (BaseStatement) domElement;
PsiClass parameterClass = baseStatement.getParameterClass().getValue();
String SQLCode = IbatisUtil.getSQLForXmlTag(xmlTag);
String pattern = "#[\\w:\\.]*#";
if (parameterClass == null) { //type is unknown
SQLCode = SQLCode.replaceAll(pattern, "''");
} else
if (IbatisClassShortcutsReferenceProvider.isDomain(parameterClass.getName())) // domain class
{
List<String> inlineParameters = IbatisUtil.grep(SQLCode, pattern);
for (String parameter : inlineParameters) {
PsiClass referencedClass = parameterClass;
String fieldName = parameter.replaceAll("#", "").replaceAll(":\\w*", "");
String[] referencePath = fieldName.split("\\.");
for (String part : referencePath) {
referencedClass = FieldAccessMethodReferenceProvider.findGetterMethodReturnType(referencedClass, "get" + StringUtil.capitalize(part));
if (referencedClass == null) break;
}
SQLCode = SQLCode.replaceAll(parameter, getDefaultValueForType(referencedClass == null ? "" : referencedClass.getQualifiedName()));
}
} else //domain class
{
SQLCode = SQLCode.replaceAll(pattern, getDefaultValueForType(parameterClass.getQualifiedName()));
}
CopyPasteManager copyPasteManager = CopyPasteManager.getInstance();
copyPasteManager.setContents(new StringSelection(SQLCode.trim()));
}
}
}
}
}