Search in sources :

Example 1 with ViewContentProvider

use of org.obeonetwork.dsl.database.view.parser.ViewContentProvider in project InformationSystem by ObeoNetwork.

the class DatabaseServices method initializeViewContent.

/**
 * Initialize the content of a view.
 *
 * Tables and Columns are transient and not saved.
 * They need to be be computed at the opening of the diagram.
 * @param view to initialize.
 */
private void initializeViewContent(View view) {
    /* The tables and the columns references are transient. 
		 * Initializing the transient reference is a workaround 
		 * to avoid some diagram refresh problems.
		 * The initializing need to be done only one time.
		 */
    ViewSpec viewSpec = (ViewSpec) view;
    if (viewSpec.initialized == false) {
        // Clear view content
        if (viewSpec.getColumns() != null) {
            viewSpec.getColumns().clear();
        }
        if (viewSpec.getTables() != null) {
            viewSpec.getTables().clear();
        }
        // Parse new query and update view content
        String query = viewSpec.getQuery();
        if (!Strings.isNullOrEmpty(query)) {
            ViewContentProvider viewContentProvider = new ViewContentProvider();
            viewContentProvider.parseViewQuery(viewSpec.getQuery());
            List<ColObject> listOfColumns = viewContentProvider.getColumns();
            if (listOfColumns != null) {
                for (ColObject column : listOfColumns) {
                    ViewElement elem = DatabaseFactory.eINSTANCE.createViewElement();
                    elem.setName(column.getName());
                    elem.setAlias(column.getAlias());
                    viewSpec.getColumns().add(elem);
                }
            }
            List<String> listOfTables = viewContentProvider.getTables();
            if (listOfTables != null) {
                for (String table : listOfTables) {
                    ViewElement elem = DatabaseFactory.eINSTANCE.createViewElement();
                    elem.setName(table);
                    viewSpec.getTables().add(elem);
                }
            }
        }
        // The initialization was done update boolean.
        viewSpec.initialized = true;
    }
}
Also used : ViewSpec(org.obeonetwork.dsl.database.spec.ViewSpec) ViewContentProvider(org.obeonetwork.dsl.database.view.parser.ViewContentProvider) ColObject(org.obeonetwork.dsl.database.view.parser.ColObject) ViewElement(org.obeonetwork.dsl.database.ViewElement)

Example 2 with ViewContentProvider

use of org.obeonetwork.dsl.database.view.parser.ViewContentProvider in project InformationSystem by ObeoNetwork.

the class ViewQueryChangeTrigger method localChangesAboutToCommit.

@Override
public Option<Command> localChangesAboutToCommit(Collection<Notification> notifications) {
    Iterable<Notification> querySetNotification = Iterables.filter(notifications, IS_QUERY_SET);
    for (Notification notification : querySetNotification) {
        view = (View) notification.getNotifier();
        query = view.getQuery();
        final Session session = SessionManager.INSTANCE.getSession(view);
        final TransactionalEditingDomain domain = session.getTransactionalEditingDomain();
        if (!Strings.isNullOrEmpty(query)) {
            final Command result = new RecordingCommand(domain) {

                @Override
                protected void doExecute() {
                    if (view.getColumns() != null) {
                        view.getColumns().clear();
                    }
                    if (view.getTables() != null) {
                        view.getTables().clear();
                    }
                    // Parse new query
                    ViewContentProvider viewContentProvider = new ViewContentProvider();
                    viewContentProvider.parseViewQuery(query);
                    List<ColObject> listOfColumns = viewContentProvider.getColumns();
                    if (listOfColumns != null) {
                        for (ColObject column : listOfColumns) {
                            ViewElement elem = DatabaseFactory.eINSTANCE.createViewElement();
                            elem.setName(column.getName());
                            elem.setAlias(column.getAlias());
                            view.getColumns().add(elem);
                        }
                    }
                    List<String> listOfTables = viewContentProvider.getTables();
                    if (listOfTables != null) {
                        for (String table : listOfTables) {
                            ViewElement elem = DatabaseFactory.eINSTANCE.createViewElement();
                            elem.setName(table);
                            view.getTables().add(elem);
                        }
                    }
                }
            };
            return Options.newSome(result);
        } else if (Strings.isNullOrEmpty(query)) {
            final Command result = new RecordingCommand(domain) {

                @Override
                protected void doExecute() {
                    if (view.getColumns() != null) {
                        view.getColumns().clear();
                    }
                    if (view.getTables() != null) {
                        view.getTables().clear();
                    }
                }
            };
            return Options.newSome(result);
        }
    }
    return Options.newNone();
}
Also used : ColObject(org.obeonetwork.dsl.database.view.parser.ColObject) ViewElement(org.obeonetwork.dsl.database.ViewElement) Notification(org.eclipse.emf.common.notify.Notification) TransactionalEditingDomain(org.eclipse.emf.transaction.TransactionalEditingDomain) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) RecordingCommand(org.eclipse.emf.transaction.RecordingCommand) Command(org.eclipse.emf.common.command.Command) ViewContentProvider(org.obeonetwork.dsl.database.view.parser.ViewContentProvider) Session(org.eclipse.sirius.business.api.session.Session)

Aggregations

ViewElement (org.obeonetwork.dsl.database.ViewElement)2 ColObject (org.obeonetwork.dsl.database.view.parser.ColObject)2 ViewContentProvider (org.obeonetwork.dsl.database.view.parser.ViewContentProvider)2 Command (org.eclipse.emf.common.command.Command)1 Notification (org.eclipse.emf.common.notify.Notification)1 RecordingCommand (org.eclipse.emf.transaction.RecordingCommand)1 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)1 Session (org.eclipse.sirius.business.api.session.Session)1 ViewSpec (org.obeonetwork.dsl.database.spec.ViewSpec)1