Search in sources :

Example 1 with ViewElement

use of org.obeonetwork.dsl.database.ViewElement in project InformationSystem by ObeoNetwork.

the class ViewElementItemProvider method getText.

/**
 * This returns the label text for the adapted class.
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated NOT
 */
@Override
public String getText(Object object) {
    String type;
    EObject element = (EObject) object;
    if (element.eContainingFeature().equals(DatabasePackage.Literals.VIEW__TABLES)) {
        type = "_UI_Table_type";
    } else if (element.eContainingFeature().equals(DatabasePackage.Literals.VIEW__COLUMNS)) {
        type = "_UI_Column_type";
    } else {
        type = "_UI_ViewElement_type";
    }
    String label = ((ViewElement) object).getName();
    return label == null || label.length() == 0 ? getString(type) : getString(type) + " " + label;
}
Also used : EObject(org.eclipse.emf.ecore.EObject) ViewElement(org.obeonetwork.dsl.database.ViewElement)

Example 2 with ViewElement

use of org.obeonetwork.dsl.database.ViewElement 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 3 with ViewElement

use of org.obeonetwork.dsl.database.ViewElement 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)

Example 4 with ViewElement

use of org.obeonetwork.dsl.database.ViewElement in project InformationSystem by ObeoNetwork.

the class ViewPropertiesEditionComponent method initPart.

/**
 * {@inheritDoc}
 *
 * @see org.eclipse.emf.eef.runtime.api.component.IPropertiesEditionComponent#initPart(java.lang.Object, int, org.eclipse.emf.ecore.EObject,
 *      org.eclipse.emf.ecore.resource.ResourceSet)
 */
public void initPart(Object key, int kind, EObject elt, ResourceSet allResource) {
    setInitializing(true);
    if (editingPart != null && key == partKey) {
        editingPart.setContext(elt, allResource);
        final View view = (View) elt;
        final ViewPropertiesEditionPart viewPart = (ViewPropertiesEditionPart) editingPart;
        // init values
        if (isAccessible(DatabaseViewsRepository.View.Properties.name))
            viewPart.setName(EEFConverterUtil.convertToString(EcorePackage.Literals.ESTRING, view.getName()));
        if (isAccessible(DatabaseViewsRepository.View.Properties.query))
            viewPart.setQuery(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, view.getQuery()));
        if (isAccessible(DatabaseViewsRepository.View.Properties.comments))
            viewPart.setComments(EcoreUtil.convertToString(EcorePackage.Literals.ESTRING, view.getComments()));
        if (isAccessible(DatabaseViewsRepository.View.Properties.columns)) {
            columnsSettings = new ReferencesTableSettings(view, DatabasePackage.eINSTANCE.getView_Columns());
            viewPart.initColumns(columnsSettings);
        }
        if (isAccessible(DatabaseViewsRepository.View.Properties.tables)) {
            tablesSettings = new ReferencesTableSettings(view, DatabasePackage.eINSTANCE.getView_Tables());
            viewPart.initTables(tablesSettings);
        }
        if (isAccessible(DatabaseViewsRepository.View.Properties.columns)) {
            viewPart.addFilterToColumns(new ViewerFilter() {

                /**
                 * {@inheritDoc}
                 *
                 * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
                 */
                public boolean select(Viewer viewer, Object parentElement, Object element) {
                    // $NON-NLS-1$
                    return (element instanceof String && element.equals("")) || (element instanceof ViewElement);
                }
            });
        // Start of user code for additional businessfilters for columns
        // End of user code
        }
        if (isAccessible(DatabaseViewsRepository.View.Properties.tables)) {
            viewPart.addFilterToTables(new ViewerFilter() {

                /**
                 * {@inheritDoc}
                 *
                 * @see org.eclipse.jface.viewers.ViewerFilter#select(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
                 */
                public boolean select(Viewer viewer, Object parentElement, Object element) {
                    // $NON-NLS-1$
                    return (element instanceof String && element.equals("")) || (element instanceof ViewElement);
                }
            });
        // Start of user code for additional businessfilters for tables
        // End of user code
        }
    // init values for referenced views
    // init filters for referenced views
    }
    setInitializing(false);
}
Also used : ReferencesTableSettings(org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings) ViewerFilter(org.eclipse.jface.viewers.ViewerFilter) ViewPropertiesEditionPart(org.obeonetwork.dsl.database.parts.ViewPropertiesEditionPart) Viewer(org.eclipse.jface.viewers.Viewer) EObject(org.eclipse.emf.ecore.EObject) View(org.obeonetwork.dsl.database.View) ViewElement(org.obeonetwork.dsl.database.ViewElement)

Aggregations

ViewElement (org.obeonetwork.dsl.database.ViewElement)4 EObject (org.eclipse.emf.ecore.EObject)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 ReferencesTableSettings (org.eclipse.emf.eef.runtime.ui.widgets.referencestable.ReferencesTableSettings)1 RecordingCommand (org.eclipse.emf.transaction.RecordingCommand)1 TransactionalEditingDomain (org.eclipse.emf.transaction.TransactionalEditingDomain)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerFilter (org.eclipse.jface.viewers.ViewerFilter)1 Session (org.eclipse.sirius.business.api.session.Session)1 View (org.obeonetwork.dsl.database.View)1 ViewPropertiesEditionPart (org.obeonetwork.dsl.database.parts.ViewPropertiesEditionPart)1 ViewSpec (org.obeonetwork.dsl.database.spec.ViewSpec)1