| /** |
| * |
| * Copyright (c) 2011, 2016 - Loetz GmbH&Co.KG (69115 Heidelberg, Germany) |
| * |
| * All rights reserved. This program and the accompanying materials |
| * are made available under the terms of the Eclipse Public License v1.0 |
| * which accompanies this distribution, and is available at |
| * http://www.eclipse.org/legal/epl-v10.html |
| * |
| * Contributors: |
| * Christophe Loetz (Loetz GmbH&Co.KG) - initial implementation |
| */ |
| package org.eclipse.osbp.xtext.datamart.common; |
| |
| import java.sql.Connection; |
| import java.sql.ResultSet; |
| import java.util.ArrayList; |
| import java.util.HashMap; |
| import java.util.List; |
| import java.util.Map; |
| |
| import org.eclipse.osbp.dsl.common.datatypes.IDto; |
| import org.eclipse.osbp.ui.api.datamart.DerivedOlapException; |
| import org.eclipse.osbp.ui.api.user.IUser; |
| import org.eclipse.osbp.utils.common.IEntityIdModificationListenerView; |
| import org.eclipse.osbp.utils.fillertext.FillerTextProvider; |
| import org.eclipse.osbp.xtext.datamart.common.olap.DerivedAxis; |
| import org.eclipse.osbp.xtext.datamart.common.olap.DerivedCell; |
| import org.eclipse.osbp.xtext.datamart.common.olap.DerivedCellSet; |
| import org.eclipse.osbp.xtext.datamart.common.olap.DerivedPosition; |
| |
| @SuppressWarnings("all") |
| public abstract class AEntityDatamart extends ADatamart<Connection> { |
| public abstract DerivedCellSet getResults(final IUser user, final Map<String,String> filteredItems, Class operativeDtoClass, List<IDto> operativeDtos); |
| protected boolean fFillerTextEnabled = false; |
| |
| /** |
| * @param enableFillerText enable using filler text for following calls to {@link #getResults(Map)} |
| */ |
| public void enableFillerText(boolean enableFillerText) { |
| fFillerTextEnabled = enableFillerText; |
| } |
| /** |
| * @return the generated filler text result set. Has be generated for each datamart class |
| */ |
| protected ResultSet generateFillerTextResultSet() { |
| return null; |
| } |
| /** |
| * @param provider the filler text provider in use |
| * @return the generated filler text row. Has be generated for each datamart class |
| */ |
| public Map<String, Object> generateFillerTextRow(FillerTextProvider provider) { |
| return null; |
| } |
| |
| /** |
| * @see {@link IEntityIdModificationListenerView} |
| * The view has to subscribe/unsubsribe to REFRESH_VIEW! |
| * <br> |
| * <b>The IDs/UUIDs for entities have to be on the AXIS_COLUMN only!</b> |
| * @param listeningView the view, that should listen to modifications on modified entity ids |
| * @param cellSet the result set, from which the entity ids, that should be listened to, are extracted |
| */ |
| public void addEntityIdsToModifyListener(IEntityIdModificationListenerView listeningView, DerivedCellSet cellSet) { |
| // --- find all columns containing entity ids/uuids |
| Map<String,Integer> entityIdColumns = new HashMap<String, Integer>(); |
| try { |
| // --- next get the header for all "columns" --- |
| // Column header |
| // See |
| // http://www.olap4j.org/api/index.html?org/olap4j/Position.html |
| // on how Position works, it helps a lot |
| // Every position will be a column in the header |
| int count = 0; |
| for (DerivedPosition pos : cellSet.getAxes().get(DerivedAxis.AXIS_COLUMNS).getPositions()) { |
| String columnName = pos.getMembers().get(0).getCaption(); |
| if (DatamartDefinitionUtil.isEntityIdColumnName(columnName)) { |
| entityIdColumns.put(DatamartDefinitionUtil.getEntityNameForIdColumnName(columnName), count); |
| } |
| count++; |
| } |
| } |
| catch (Exception e) { |
| } |
| if (!entityIdColumns.isEmpty()) { |
| addEntityIdsToModifyListener(listeningView, cellSet, entityIdColumns, cellSet.getAxes().size(), new ArrayList<Integer>()); |
| } |
| } |
| |
| private void addEntityIdsToModifyListener(IEntityIdModificationListenerView listeningView, DerivedCellSet cellSet, Map<String,Integer> entityIdColumns, int axisDepth, ArrayList<Integer> coordinate) { |
| int itemCount = cellSet.getAxes().get(axisDepth-1).getPositions().size(); |
| if (axisDepth > 1) { |
| for (int item = 0; item < itemCount; item++) { |
| ArrayList<Integer> newCoordinate = new ArrayList<Integer>(); |
| newCoordinate.add(item); |
| newCoordinate.addAll(coordinate); |
| addEntityIdsToModifyListener(listeningView, cellSet, entityIdColumns, axisDepth-1, newCoordinate); |
| } |
| } |
| else { |
| for (String entityName : entityIdColumns.keySet()) { |
| ArrayList<Integer> newCoordinate = new ArrayList<Integer>(); |
| newCoordinate.add(entityIdColumns.get(entityName)); |
| newCoordinate.addAll(coordinate); |
| DerivedCell result; |
| try { |
| result = cellSet.getCell(newCoordinate); |
| if (result != null) { |
| listeningView.addEntityIdToModifyListener(entityName, result.getFormattedValue().trim()); |
| } |
| } catch (DerivedOlapException e) { |
| e.printStackTrace(); |
| } |
| } |
| } |
| } |
| } |