Package com._1c.g5.v8.dt.qw.ui.utils
Class QueryWizardServiceUtils
- java.lang.Object
-
- com._1c.g5.v8.dt.qw.ui.utils.QueryWizardServiceUtils
-
public final class QueryWizardServiceUtils extends Object
Services methods for query wizard
-
-
Constructor Summary
Constructors Constructor Description QueryWizardServiceUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidaddErrorMessage(StringBuilder errorMessage, String message, int lineNumber, int columnNumber)Append issue description to errors messagestatic DbViewElementcomputeDbView(org.eclipse.emf.ecore.EObject object)ComputesDbViewElementby objectstatic List<DbViewElement>computeDbViewFields(org.eclipse.emf.ecore.EObject object)Compute dbView fieldsstatic DbViewElementcomputeDbViewForTempTable(DbViewElement element, QueryWizardSource source)Compute DbView for temporary table.static QuerySchemaExpressioncopyExpression(QuerySchemaExpression expression)Get expression copystatic QuerySchemaExpressioncopyExpression(QuerySchemaExpression expression, NestedTableExpression parentNestedTable)Make copy of query schema expression.static org.eclipse.jface.dialogs.MessageDialogcreateMessageDialog(org.eclipse.swt.widgets.Shell shell, String errorMessage)Creates warning message dialog with text of errors and warnings from Query.static org.eclipse.jface.dialogs.MessageDialogcreateMessageDialog(org.eclipse.swt.widgets.Shell shell, String errorMessage, boolean askQuestion)Creates message dialog with text of errors and warnings from Query.static voidexpandJoinsToChangedItems(QueryWizardTreeViewer tree, List<QuerySchemaSource> changedSources)Expand joins tree to changed itemsstatic FunctionInvocationExpressiongetAggregateFromExpressions(org.eclipse.emf.common.util.EList<QuerySchemaExpression> fields)Is collection of expressions contain aggregate fieldstatic org.eclipse.swt.graphics.ImagegetAliasImage(QueryWizardSource source, Object element)Get image for aliasstatic List<QuerySchemaQuerySourceJoin>getAllJoins(QuerySchemaOperator operator)Get all joins in operatorstatic List<QuerySchemaQuerySourceJoin>getAllJoins(QueryWizardSource qwSource)Get all joins in operatorstatic List<QuerySchemaExpression>getAllNestedTables(org.eclipse.emf.common.util.EList<QuerySchemaExpression> fields)Get all nested tablesstatic Set<QuerySchemaSource>getAllSources(QuerySchemaOperator operator)Returns all sources contained in operatorstatic voidgetConditionAndExpressions(AbstractExpression condition, List<AbstractExpression> expressions)Break condition on expressions by AND operationstatic FunctionInvocationExpressiongetContainedAggregate(AbstractExpression field)Get aggregate from expressionstatic List<DbViewFieldDef>getDbViewFieldFields(DbViewFieldDef sourceItem, QueryWizardSource queryWizardSource)Get children fields in fieldstatic DbViewElementgetDbViewForQuery(org.eclipse.emf.ecore.EObject source)Get DbView for nested querystatic StringgetDcsFieldText(Object element, QueryWizardSource source)Get dcs field textstatic StringgetEmptyQuery(ScriptVariant scriptVariant)Get empty query textstatic StringgetExpressionAlias(QueryWizardSource source, QuerySchemaExpression expression)Get alias for expressionstatic StringgetExpressionText(Object element, QueryWizardSource source)Get text for expressionstatic StringgetExpressionText(Object element, QueryWizardSource source, boolean removeLinesSeparators)Get text for expressionstatic StringgetJoinPresentation(QuerySchemaJoinType joinType)Get join type string presentationstatic StringgetLoacalName(Object element, ScriptVariant scriptVariant)Get object name, depending of script variantstatic AbstractQuerySchemaTablegetPlacementTable(QueryWizardSource source)Get table for placement from querystatic QuerySchemaExpressiongetPresentationForRefExpression(QueryWizardSource source, QuerySchemaExpression field)Get presentation for ref expressionstatic List<? extends DbViewElement>getQuerySchemaSourceFields(Object sourceItem, QueryWizardSource queryWizardsource)Get fields for source or field from sourcestatic ScriptVariantgetScriptVariant(org.eclipse.emf.ecore.EObject object)Get current script variant (English or Russian)static QuerySchemaSourcegetSourceFromJoin(Object source)Get source from joinstatic DbViewFromQuerygetTempTableDbView(QuerySchemaSource source)Is source temporary tablestatic StringgetTempTableName(QuerySchemaSource tempTable)Get temporary table description namestatic Map<String,QuerySchemaSelectQuery>getTempTables(QueryWizardSource source)Get temporary tables available for current querystatic Map<String,QuerySchemaSelectQuery>getTempTables(QueryWizardSource source, int queryIndex)Get temporary tables available for query by indexstatic Set<String>getTempTablesNames(QueryWizardSource source)Get temporary tables names used in querystatic List<String>getTempTablesNames(QueryWizardSource source, int endQueryIndex)Get temporary tables names available for query by indexstatic StringgetTreeItemText(org.eclipse.swt.widgets.TreeItem item)Get tree item text, use '.' as separator for fields, and '[]' for nested table part.static StringgetTypeAsString(TypeDescription type, QueryWizardSource source)Get TypeDescription as stringstatic StringgetTypeAsString(TypeDescription type, QueryWizardSource source, ScriptVariant scriptVariant)Get TypeDescription as stringstatic IV8ProjectgetV8project(org.eclipse.emf.ecore.EObject object)Get the V8 project by specified object.static voidhandleQueryWizardEditException(QueryWizardEditProviderException qwException, QueryWizardControl qwControl)Processing query wizard exceptionstatic booleanisContainIndex(QueryWizardSource source, String value)Is index contain given expressionstatic booleanisContainOrder(QueryWizardSource source, String value)Is order contain given expressionstatic booleanisContainTotal(QueryWizardSource source, String value)Returns whether totals contain given expressionstatic booleanisExpressionContainSource(String sourceAlias, org.eclipse.emf.ecore.EObject expression)Is expression contain source aliasstatic booleanisExpressionsInGroupings(QuerySchemaOperator operator)If groupings have expressions - return truestatic booleanisNestedTableInGroupings(QuerySchemaOperator operator)If groupings have nested table - return truestatic booleanisNestedTableInOperator(QuerySchemaOperator operator)If operator have nested table - return truestatic booleanisNestedTableInOperator(QueryWizardSource source, int queryIndex, int operatorIndex)If operator have nested table - return truestatic booleanisNumberExpression(QueryWizardSource source, QuerySchemaExpression expression)Returns whether expression have number typestatic booleanisPresentationAlias(QuerySchemaExpression expression, QueryWizardSource source)Is expressions from alias contain PRESENTATION functionstatic booleanisPresentationExpression(AbstractExpression expression)Is expression contain PRESENTATION functionstatic booleanisQueriesEquals(String query1, String query2)Is queries text equalsstatic booleanisTempTableDescription(QuerySchemaSource source, QueryWizardSource qwSource)Is source temporary table descriptionstatic StringnormalizeString(String text)Remove from text special characters and extra spacesstatic StringprepareQueryForTextModule(String query, String lineFormatter, String lineSeparator)Prepare query text for text modulestatic booleanreplaceSourceAliasInExpression(String[] oldAndNewAliases, org.eclipse.emf.ecore.EObject expression)Replace source alias in expressionstatic booleanreplaceSourceAliasInExpression(String sourceAlias, String newSourceAlias, org.eclipse.emf.ecore.EObject expression)Replace source alias in expressionstatic voidsetCanMove(TreeViewer tree, org.eclipse.jface.action.Action moveUpAction, org.eclipse.jface.action.Action moveDownAction)Set enabled state for actions move up or move downstatic booleanvalidateAlias(QueryWizardControl queryWizard, String newAlias, List<String> existAliases)Check is valid alias for expression.static StringvalidateResource(org.eclipse.emf.ecore.resource.Resource resource, org.eclipse.xtext.validation.IResourceValidator resourceValidator)Checking query schema on errorsstatic StringvalidateResource(org.eclipse.emf.ecore.resource.Resource resource, org.eclipse.xtext.validation.IResourceValidator resourceValidator, boolean onlyCritical)Checking query schema on errors
-
-
-
Method Detail
-
getDbViewForQuery
public static DbViewElement getDbViewForQuery(org.eclipse.emf.ecore.EObject source)
Get DbView for nested query- Parameters:
source- QuerySchemaNestedQuery- Returns:
- DbViewDef for source. Return null if parent container of nested query expression is not operator
-
computeDbView
public static DbViewElement computeDbView(org.eclipse.emf.ecore.EObject object)
ComputesDbViewElementby object- Parameters:
object- computeDbViewElementfor this object- Returns:
- computed
DbViewElement
-
computeDbViewFields
public static List<DbViewElement> computeDbViewFields(org.eclipse.emf.ecore.EObject object)
Compute dbView fields- Parameters:
object- - fields source- Returns:
- fields collection
-
getAllSources
public static Set<QuerySchemaSource> getAllSources(QuerySchemaOperator operator)
Returns all sources contained in operator- Parameters:
operator-- Returns:
- all sources in operator
-
getJoinPresentation
public static String getJoinPresentation(QuerySchemaJoinType joinType)
Get join type string presentation- Parameters:
joinType- join type- Returns:
- string presentation
-
getConditionAndExpressions
public static void getConditionAndExpressions(AbstractExpression condition, List<AbstractExpression> expressions)
Break condition on expressions by AND operation- Parameters:
condition- contain expression with binary operations. Not nullexpressions- collection for storing expressions from condition (broke by AND operation). Not null
-
expandJoinsToChangedItems
public static void expandJoinsToChangedItems(QueryWizardTreeViewer tree, List<QuerySchemaSource> changedSources)
Expand joins tree to changed items- Parameters:
tree- tree viewerchangedSources- list of changed sources
-
handleQueryWizardEditException
public static void handleQueryWizardEditException(QueryWizardEditProviderException qwException, QueryWizardControl qwControl)
Processing query wizard exception- Parameters:
qwException- query wizard exceptionqwControl- parent query wizard control
-
isNestedTableInOperator
public static boolean isNestedTableInOperator(QueryWizardSource source, int queryIndex, int operatorIndex)
If operator have nested table - return true- Parameters:
querySchema- QueryWizardSourcequeryIndex- query indexoperatorIndex- operator index in query- Returns:
- true if is nested table in operator
-
isNestedTableInOperator
public static boolean isNestedTableInOperator(QuerySchemaOperator operator)
If operator have nested table - return true- Parameters:
operator-- Returns:
- true if is nested table in operator
-
isNestedTableInGroupings
public static boolean isNestedTableInGroupings(QuerySchemaOperator operator)
If groupings have nested table - return true- Parameters:
operator-- Returns:
- true if is nested table in groupings
-
isExpressionsInGroupings
public static boolean isExpressionsInGroupings(QuerySchemaOperator operator)
If groupings have expressions - return true- Parameters:
operator-- Returns:
- true if is expression in groupings
-
getSourceFromJoin
public static QuerySchemaSource getSourceFromJoin(Object source)
Get source from join- Parameters:
source- QuerySchemaSource- Returns:
- query schema source
-
copyExpression
public static QuerySchemaExpression copyExpression(QuerySchemaExpression expression)
Get expression copy- Parameters:
expression- query schema expression- Returns:
- copy of expression
-
copyExpression
public static QuerySchemaExpression copyExpression(QuerySchemaExpression expression, NestedTableExpression parentNestedTable)
Make copy of query schema expression. If expression from nested table, expression will be copied with parent nested table.- Parameters:
expression- query schema expressionparentNestedTable- parent nested table- Returns:
- expression copy
-
isExpressionContainSource
public static boolean isExpressionContainSource(String sourceAlias, org.eclipse.emf.ecore.EObject expression)
Is expression contain source alias- Parameters:
sourceAlias- source aliasexpression- query schema expression- Returns:
- if contained - return true
-
replaceSourceAliasInExpression
public static boolean replaceSourceAliasInExpression(String[] oldAndNewAliases, org.eclipse.emf.ecore.EObject expression)
Replace source alias in expression- Parameters:
oldAndNewAliases- strings array with old and new aliasesexpression- query schema expression- Returns:
- true if source alias was found
-
replaceSourceAliasInExpression
public static boolean replaceSourceAliasInExpression(String sourceAlias, String newSourceAlias, org.eclipse.emf.ecore.EObject expression)
Replace source alias in expression- Parameters:
sourceAlias- source aliasnewSourceAlias- new source alias. If null, alias will not be replaced.expression- query schema expression- Returns:
- true if source alias was found
-
getAggregateFromExpressions
public static FunctionInvocationExpression getAggregateFromExpressions(org.eclipse.emf.common.util.EList<QuerySchemaExpression> fields)
Is collection of expressions contain aggregate field- Parameters:
fields- fields list- Returns:
- first found aggregate, if contained or null otherwise
-
getTempTablesNames
public static Set<String> getTempTablesNames(QueryWizardSource source)
Get temporary tables names used in query- Parameters:
source- query wizard source- Returns:
- temporary tables names
-
getTempTablesNames
public static List<String> getTempTablesNames(QueryWizardSource source, int endQueryIndex)
Get temporary tables names available for query by index- Parameters:
source- - query wizard sourceendQueryIndex- - query index- Returns:
- available temporary tables names
-
getTempTables
public static Map<String,QuerySchemaSelectQuery> getTempTables(QueryWizardSource source)
Get temporary tables available for current query- Parameters:
source- - query wizard source- Returns:
- available temporary tables
-
getTempTables
public static Map<String,QuerySchemaSelectQuery> getTempTables(QueryWizardSource source, int queryIndex)
Get temporary tables available for query by index- Parameters:
source- - query wizard sourcequeryIndex- - query index- Returns:
- available temporary tables
-
getContainedAggregate
public static FunctionInvocationExpression getContainedAggregate(AbstractExpression field)
Get aggregate from expression- Parameters:
field- abstract expression- Returns:
- aggregate, if contained or null otherwise
-
getTreeItemText
public static String getTreeItemText(org.eclipse.swt.widgets.TreeItem item)
Get tree item text, use '.' as separator for fields, and '[]' for nested table part.- Parameters:
item- tree item- Returns:
- text for tree item
-
isTempTableDescription
public static boolean isTempTableDescription(QuerySchemaSource source, QueryWizardSource qwSource)
Is source temporary table description- Parameters:
source- - query schema source- Returns:
- true if temporary table description
-
getTempTableDbView
public static DbViewFromQuery getTempTableDbView(QuerySchemaSource source)
Is source temporary table- Parameters:
source- - query schema source- Returns:
- true if source is temporary table
-
getLoacalName
public static String getLoacalName(Object element, ScriptVariant scriptVariant)
Get object name, depending of script variant- Parameters:
element- - object for getting namescriptVariant- - configuration script variant- Returns:
- object name
-
isContainOrder
public static boolean isContainOrder(QueryWizardSource source, String value)
Is order contain given expression- Parameters:
source- query wizard sourcevalue- expression or alias- Returns:
- true if contain
-
isContainIndex
public static boolean isContainIndex(QueryWizardSource source, String value)
Is index contain given expression- Parameters:
source- query wizard sourcevalue- expression or alias- Returns:
- true if contain
-
isContainTotal
public static boolean isContainTotal(QueryWizardSource source, String value)
Returns whether totals contain given expression- Parameters:
source- query wizard sourcevalue- expression or alias- Returns:
- true if contain
-
isNumberExpression
public static boolean isNumberExpression(QueryWizardSource source, QuerySchemaExpression expression)
Returns whether expression have number type- Parameters:
source- - query wizard sourceexpression- - expression- Returns:
- is number type
-
getTempTableName
public static String getTempTableName(QuerySchemaSource tempTable)
Get temporary table description name- Parameters:
tempTable- - temporary table source- Returns:
- table name
-
getAllJoins
public static List<QuerySchemaQuerySourceJoin> getAllJoins(QueryWizardSource qwSource)
Get all joins in operator- Parameters:
qwSource- - query wizard source- Returns:
- all joins in current operator
-
getAllJoins
public static List<QuerySchemaQuerySourceJoin> getAllJoins(QuerySchemaOperator operator)
Get all joins in operator- Parameters:
operator- - operator- Returns:
- all joins in current operator
-
getPlacementTable
public static AbstractQuerySchemaTable getPlacementTable(QueryWizardSource source)
Get table for placement from query- Parameters:
source- - query wizard control- Returns:
- if query have table for placement - return table, otherwise null
-
validateResource
public static String validateResource(org.eclipse.emf.ecore.resource.Resource resource, org.eclipse.xtext.validation.IResourceValidator resourceValidator)
Checking query schema on errors- Parameters:
resource- - checking resourceresourceValidator- - resource validator- Returns:
- null if no errors or errors text description
-
validateResource
public static String validateResource(org.eclipse.emf.ecore.resource.Resource resource, org.eclipse.xtext.validation.IResourceValidator resourceValidator, boolean onlyCritical)
Checking query schema on errors- Parameters:
resource- - checking resourceresourceValidator- - resource validatoronlyCritical- - check only critical errors- Returns:
- null if no errors or errors text description
-
addErrorMessage
public static void addErrorMessage(StringBuilder errorMessage, String message, int lineNumber, int columnNumber)
Append issue description to errors message- Parameters:
errorMessage- - errors messages listmessage- - new error messagelineNumber- - line number with errorcolumnNumber- - column number with error
-
computeDbViewForTempTable
public static DbViewElement computeDbViewForTempTable(DbViewElement element, QueryWizardSource source)
Compute DbView for temporary table. My be it from parent query (for nested query)- Parameters:
element- - temporary table dbview- Returns:
- real dbview
-
getEmptyQuery
public static String getEmptyQuery(ScriptVariant scriptVariant)
Get empty query text- Parameters:
script- variant- Returns:
- query text
-
getScriptVariant
public static ScriptVariant getScriptVariant(org.eclipse.emf.ecore.EObject object)
Get current script variant (English or Russian)- Returns:
- script variant
-
getV8project
public static IV8Project getV8project(org.eclipse.emf.ecore.EObject object)
Get the V8 project by specified object.- Returns:
- v8project the V8 project, never
null
-
getAllNestedTables
public static List<QuerySchemaExpression> getAllNestedTables(org.eclipse.emf.common.util.EList<QuerySchemaExpression> fields)
Get all nested tables- Parameters:
fields- - fields collection- Returns:
- nested tables collection
-
setCanMove
public static void setCanMove(TreeViewer tree, org.eclipse.jface.action.Action moveUpAction, org.eclipse.jface.action.Action moveDownAction)
Set enabled state for actions move up or move down- Parameters:
tree- - tree viewermoveUpAction- - move up actionmoveDownAction- - move down action
-
normalizeString
public static String normalizeString(String text)
Remove from text special characters and extra spaces- Parameters:
text- - text- Returns:
- normalized text
-
getExpressionAlias
public static String getExpressionAlias(QueryWizardSource source, QuerySchemaExpression expression)
Get alias for expression- Parameters:
source- - query wizard sourceexpression- - expression from select fields- Returns:
- expression alias
-
getAliasImage
public static org.eclipse.swt.graphics.Image getAliasImage(QueryWizardSource source, Object element)
Get image for alias- Parameters:
source- query wizard sourceelement- expression- Returns:
- image. Return null if image not found.
-
getDbViewFieldFields
public static List<DbViewFieldDef> getDbViewFieldFields(DbViewFieldDef sourceItem, QueryWizardSource queryWizardSource)
Get children fields in field- Parameters:
sourceItem- - parent fieldqueryWizardSource- - query wizard source- Returns:
- children fields
-
getExpressionText
public static String getExpressionText(Object element, QueryWizardSource source)
Get text for expression- Parameters:
element- - expressionsource- - query wizard source return text
-
getExpressionText
public static String getExpressionText(Object element, QueryWizardSource source, boolean removeLinesSeparators)
Get text for expression- Parameters:
element- - expressionsource- - query wizard sourceremoveLinesSeparators- - remove lines separators return text
-
getTypeAsString
public static String getTypeAsString(TypeDescription type, QueryWizardSource source)
Get TypeDescription as string- Parameters:
type- - TypeDescriptionsource- - query wizard source- Returns:
- string presentation
-
getQuerySchemaSourceFields
public static List<? extends DbViewElement> getQuerySchemaSourceFields(Object sourceItem, QueryWizardSource queryWizardsource)
Get fields for source or field from source- Parameters:
sourceItem- - source or fieldqueryWizardsource- - query wizard source- Returns:
- array of fields
-
getDcsFieldText
public static String getDcsFieldText(Object element, QueryWizardSource source)
Get dcs field text- Parameters:
element- - dcs expressionsource- - query wizard source- Returns:
- expression text
-
getTypeAsString
public static String getTypeAsString(TypeDescription type, QueryWizardSource source, ScriptVariant scriptVariant)
Get TypeDescription as string- Parameters:
type- - TypeDescriptionsource- - query wizard sourcescriptVariant- - script variant- Returns:
- string presentation
-
validateAlias
public static boolean validateAlias(QueryWizardControl queryWizard, String newAlias, List<String> existAliases)
Check is valid alias for expression. Will show message dialog if not valid.- Parameters:
queryWizard- - query wizard dialognewAlias- - new aliasexistAliases- - exist aliases- Returns:
- true if valid alias
-
getPresentationForRefExpression
public static QuerySchemaExpression getPresentationForRefExpression(QueryWizardSource source, QuerySchemaExpression field)
Get presentation for ref expression- Parameters:
source- - query wizard sourcefield- - expression- Returns:
- expression presentation or null if field not ref
-
isPresentationExpression
public static boolean isPresentationExpression(AbstractExpression expression)
Is expression contain PRESENTATION function- Parameters:
expression- - expression- Returns:
- true if expression contain PRESENTATION function
-
isPresentationAlias
public static boolean isPresentationAlias(QuerySchemaExpression expression, QueryWizardSource source)
Is expressions from alias contain PRESENTATION function- Parameters:
expression- - expression from aliassource- - query wizard source- Returns:
- true if alias contain presentation function
-
isQueriesEquals
public static boolean isQueriesEquals(String query1, String query2)
Is queries text equals- Parameters:
query1- - query textquery2- - query text- Returns:
- true if equals otherwise false
-
prepareQueryForTextModule
public static String prepareQueryForTextModule(String query, String lineFormatter, String lineSeparator)
Prepare query text for text module- Parameters:
query- - query textlineFormatter- - line formatterlineSeparator- - line separator- Returns:
- formatted query text for text module
-
createMessageDialog
public static org.eclipse.jface.dialogs.MessageDialog createMessageDialog(org.eclipse.swt.widgets.Shell shell, String errorMessage, boolean askQuestion)Creates message dialog with text of errors and warnings from Query. Dialog will have one "OK" button ifaskQuestionisfalseor two buttons Yes and No ifaskQuestionistrue. Also ifaskQuestionistruedialog will be Question dialog, otherwise Warning- Parameters:
shell- activeShell, cannot benullerrorMessage- string contains all messages of errors and warnings, cannot benull- Returns:
- created message dialog with text of errors and warnings from Query, never
null
-
createMessageDialog
public static org.eclipse.jface.dialogs.MessageDialog createMessageDialog(org.eclipse.swt.widgets.Shell shell, String errorMessage)Creates warning message dialog with text of errors and warnings from Query. Dialog will have one "OK" button.- Parameters:
shell- activeShell, cannot benullerrorMessage- string contains all messages of errors and warnings, cannot benull- Returns:
- created message dialog with text of errors and warnings from Query, never
null
-
-