private Chart getConvertedChart(Chart currentChart, String sNewSubType, Orientation newOrientation, String sNewDimension) { Chart helperModel = (Chart) EcoreUtil.copy(currentChart); if ((currentChart instanceof ChartWithAxes)) { if (currentChart.getType().equals(sType)) { if (!currentChart.getSubType().equals(sNewSubType)) { currentChart.setSubType(sNewSubType); EList axes = ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).getAssociatedAxes(); for (int i = 0; i < axes.size(); i++) { if (sNewSubType.equalsIgnoreCase("Percent Stacked")) { ((Axis) axes.get(i)).setPercent(true); } else { ((Axis) axes.get(i)).setPercent(false); } EList seriesdefinitions = ((Axis) axes.get(i)).getSeriesDefinitions(); for (int j = 0; j < seriesdefinitions.size(); j++) { Series series = ((SeriesDefinition) seriesdefinitions.get(j)).getDesignTimeSeries(); if ((sNewSubType.equalsIgnoreCase("Stacked") || sNewSubType .equalsIgnoreCase("Percent Stacked"))) { series.setStacked(true); } else { series.setStacked(false); } } } } } else if (currentChart.getType().equals("Bar Chart") || currentChart.getType().equals("Stock Chart") || currentChart.getType().equals("Scatter Chart")) { if (!currentChart.getType().equals("Bar Chart")) { currentChart.setSampleData(getConvertedSampleData(currentChart.getSampleData())); ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).setType(AxisType.TEXT_LITERAL); } currentChart.setType(sType); currentChart.setSubType(sNewSubType); EList axes = ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).getAssociatedAxes(); for (int i = 0; i < axes.size(); i++) { if (sNewSubType.equalsIgnoreCase("Percent Stacked")) { ((Axis) axes.get(i)).setPercent(true); } else { ((Axis) axes.get(i)).setPercent(false); } EList seriesdefinitions = ((Axis) axes.get(i)).getSeriesDefinitions(); for (int j = 0; j < seriesdefinitions.size(); j++) { Series series = ((SeriesDefinition) seriesdefinitions.get(j)).getDesignTimeSeries(); series = getConvertedSeries(series); if ((sNewSubType.equalsIgnoreCase("Stacked") || sNewSubType.equalsIgnoreCase("Percent Stacked"))) { series.setStacked(true); } else { series.setStacked(false); } ((SeriesDefinition) seriesdefinitions.get(j)).getSeries().clear(); ((SeriesDefinition) seriesdefinitions.get(j)).getSeries().add(series); } } } else { return null; } ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).setCategoryAxis(true); } else {  currentChart = ChartWithAxesImpl.create(); currentChart.setType(sType); currentChart.setSubType(sNewSubType); ((ChartWithAxes) currentChart).setOrientation(newOrientation); currentChart.setDimension(getDimensionFor(sNewDimension));  ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).setOrientation(Orientation.HORIZONTAL_LITERAL); ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).setType(AxisType.TEXT_LITERAL); ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).setCategoryAxis(true);  ((Axis) ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).getAssociatedAxes().get(0)) .setOrientation(Orientation.VERTICAL_LITERAL); ((Axis) ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).getAssociatedAxes().get(0)) .setType(AxisType.LINEAR_LITERAL);   currentChart.setBlock(helperModel.getBlock()); currentChart.setDescription(helperModel.getDescription()); currentChart.setGridColumnCount(helperModel.getGridColumnCount()); currentChart.setSampleData(helperModel.getSampleData()); currentChart.setScript(helperModel.getScript()); currentChart.setSeriesThickness(helperModel.getSeriesThickness()); currentChart.setUnits(helperModel.getUnits());  if (helperModel.getType().equals("Pie Chart")) {  ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).getSeriesDefinitions().clear();   ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).getSeriesDefinitions().add( ((ChartWithoutAxes) helperModel).getSeriesDefinitions().get(0));   ((Axis) ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).getAssociatedAxes().get(0)) .getSeriesDefinitions().clear();   ((Axis) ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).getAssociatedAxes().get(0)) .getSeriesDefinitions().addAll( ((SeriesDefinition) ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)) .getSeriesDefinitions().get(0)).getSeriesDefinitions());   Series series = ((SeriesDefinition) ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)) .getSeriesDefinitions().get(0)).getDesignTimeSeries(); series = getConvertedSeries(series);   ((SeriesDefinition) ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).getSeriesDefinitions() .get(0)).getSeries().clear();   ((SeriesDefinition) ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).getSeriesDefinitions() .get(0)).getSeries().add(series);   EList seriesdefinitions = ((Axis) ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)) .getAssociatedAxes().get(0)).getSeriesDefinitions(); for (int j = 0; j < seriesdefinitions.size(); j++) { series = ((SeriesDefinition) seriesdefinitions.get(j)).getDesignTimeSeries(); series = getConvertedSeries(series); if ((sNewSubType.equalsIgnoreCase("Stacked") || sNewSubType.equalsIgnoreCase("Percent Stacked"))) { series.setStacked(true); } else { series.setStacked(false); }  ((SeriesDefinition) seriesdefinitions.get(j)).getSeries().clear();  ((SeriesDefinition) seriesdefinitions.get(j)).getSeries().add(series); } } else { return null; } } if (currentChart instanceof ChartWithAxes && !((ChartWithAxes) currentChart).getOrientation().equals(newOrientation)) { ((ChartWithAxes) currentChart).setOrientation(newOrientation); } if (!currentChart.getDimension().equals(getDimensionFor(sNewDimension))) { currentChart.setDimension(getDimensionFor(sNewDimension)); } return currentChart; }
private Chart getConvertedChart( Chart currentChart, String sNewSubType, Orientation newOrientation, String sNewDimension ) { Chart helperModel = (Chart) EcoreUtil.copy( currentChart ); if ( ( currentChart instanceof ChartWithAxes ) )  { if ( currentChart.getType( ).equals( TYPE_LITERAL ) )   { if ( !currentChart.getSubType( ).equals( sNewSubType ) )       { currentChart.setSubType( sNewSubType ); EList axes = ( (Axis) ( (ChartWithAxes) currentChart ).getAxes( ) .get( 0 ) ).getAssociatedAxes( ); for ( int i = 0; i < axes.size( ); i++ ) { if ( sNewSubType.equalsIgnoreCase( "Percent Stacked" ) ) { ( (Axis) axes.get( i ) ).setPercent( true ); } else { ( (Axis) axes.get( i ) ).setPercent( false ); } EList seriesdefinitions = ( (Axis) axes.get( i ) ).getSeriesDefinitions( ); for ( int j = 0; j < seriesdefinitions.size( ); j++ ) { Series series = ( (SeriesDefinition) seriesdefinitions.get( j ) ).getDesignTimeSeries( ); if ( ( sNewSubType.equalsIgnoreCase( "Stacked" ) || sNewSubType .equalsIgnoreCase( "Percent Stacked" ) ) ) { series.setStacked( true ); } else { series.setStacked( false ); } } } } } else if ( currentChart.getType( ).equals( BarChart.TYPE_LITERAL ) || currentChart.getType( ).equals( StockChart.TYPE_LITERAL ) || currentChart.getType( ).equals( ScatterChart.TYPE_LITERAL ) ) { if ( !currentChart.getType( ).equals( BarChart.TYPE_LITERAL ) ) { currentChart.setSampleData( getConvertedSampleData( currentChart.getSampleData( ) ) ); ( (Axis) ( (ChartWithAxes) currentChart ).getAxes( ) .get( 0 ) ).setType( AxisType.TEXT_LITERAL ); } currentChart.setType( TYPE_LITERAL ); currentChart.setSubType( sNewSubType ); EList axes = ( (Axis) ( (ChartWithAxes) currentChart ).getAxes( ) .get( 0 ) ).getAssociatedAxes( ); for ( int i = 0; i < axes.size( ); i++ ) { if ( sNewSubType.equalsIgnoreCase( "Percent Stacked" ) ) { ( (Axis) axes.get( i ) ).setPercent( true ); } else { ( (Axis) axes.get( i ) ).setPercent( false ); } EList seriesdefinitions = ( (Axis) axes.get( i ) ).getSeriesDefinitions( ); for ( int j = 0; j < seriesdefinitions.size( ); j++ ) { Series series = ( (SeriesDefinition) seriesdefinitions.get( j ) ).getDesignTimeSeries( ); series = getConvertedSeries( series ); if ( ( sNewSubType.equalsIgnoreCase( "Stacked" ) || sNewSubType.equalsIgnoreCase( "Percent Stacked" ) ) ) { series.setStacked( true ); } else { series.setStacked( false ); } ( (SeriesDefinition) seriesdefinitions.get( j ) ).getSeries( ) .clear( ); ( (SeriesDefinition) seriesdefinitions.get( j ) ).getSeries( ) .add( series ); } } } else { return null; } ( (Axis) ( (ChartWithAxes) currentChart ).getAxes( ).get( 0 ) ).setCategoryAxis( true ); } else {   currentChart = ChartWithAxesImpl.create( ); currentChart.setType( TYPE_LITERAL ); currentChart.setSubType( sNewSubType ); ( (ChartWithAxes) currentChart ).setOrientation( newOrientation ); currentChart.setDimension( getDimensionFor( sNewDimension ) );  ( (Axis) ( (ChartWithAxes) currentChart ).getAxes( ).get( 0 ) ).setOrientation( Orientation.HORIZONTAL_LITERAL ); ( (Axis) ( (ChartWithAxes) currentChart ).getAxes( ).get( 0 ) ).setType( AxisType.TEXT_LITERAL ); ( (Axis) ( (ChartWithAxes) currentChart ).getAxes( ).get( 0 ) ).setCategoryAxis( true );  ( (Axis) ( (Axis) ( (ChartWithAxes) currentChart ).getAxes( ) .get( 0 ) ).getAssociatedAxes( ).get( 0 ) ).setOrientation( Orientation.VERTICAL_LITERAL ); ( (Axis) ( (Axis) ( (ChartWithAxes) currentChart ).getAxes( ) .get( 0 ) ).getAssociatedAxes( ).get( 0 ) ).setType( AxisType.LINEAR_LITERAL );   currentChart.setBlock( helperModel.getBlock( ) ); currentChart.setDescription( helperModel.getDescription( ) ); currentChart.setGridColumnCount( helperModel.getGridColumnCount( ) ); currentChart.setSampleData( helperModel.getSampleData( ) ); currentChart.setScript( helperModel.getScript( ) ); currentChart.setSeriesThickness( helperModel.getSeriesThickness( ) ); currentChart.setUnits( helperModel.getUnits( ) );  if ( helperModel.getType( ).equals( PieChart.TYPE_LITERAL ) ) {  ( (Axis) ( (ChartWithAxes) currentChart ).getAxes( ).get( 0 ) ).getSeriesDefinitions( ) .clear( );   ( (Axis) ( (ChartWithAxes) currentChart ).getAxes( ).get( 0 ) ).getSeriesDefinitions( ) .add( ( (ChartWithoutAxes) helperModel ).getSeriesDefinitions( ) .get( 0 ) );   ( (Axis) ( (Axis) ( (ChartWithAxes) currentChart ).getAxes( ) .get( 0 ) ).getAssociatedAxes( ).get( 0 ) ).getSeriesDefinitions( ) .clear( );   ( (Axis) ( (Axis) ( (ChartWithAxes) currentChart ).getAxes( ) .get( 0 ) ).getAssociatedAxes( ).get( 0 ) ).getSeriesDefinitions( ) .addAll( ( (SeriesDefinition) ( (Axis) ( (ChartWithAxes) currentChart ).getAxes( ) .get( 0 ) ).getSeriesDefinitions( ).get( 0 ) ).getSeriesDefinitions( ) );   Series series = ( (SeriesDefinition) ( (Axis) ( (ChartWithAxes) currentChart ).getAxes( ) .get( 0 ) ).getSeriesDefinitions( ).get( 0 ) ).getDesignTimeSeries( ); series = getConvertedSeries( series );   ( (SeriesDefinition) ( (Axis) ( (ChartWithAxes) currentChart ).getAxes( ) .get( 0 ) ).getSeriesDefinitions( ).get( 0 ) ).getSeries( ) .clear( );   ( (SeriesDefinition) ( (Axis) ( (ChartWithAxes) currentChart ).getAxes( ) .get( 0 ) ).getSeriesDefinitions( ).get( 0 ) ).getSeries( ) .add( series );   EList seriesdefinitions = ( (Axis) ( (Axis) ( (ChartWithAxes) currentChart ).getAxes( ) .get( 0 ) ).getAssociatedAxes( ).get( 0 ) ).getSeriesDefinitions( ); for ( int j = 0; j < seriesdefinitions.size( ); j++ ) { series = ( (SeriesDefinition) seriesdefinitions.get( j ) ).getDesignTimeSeries( ); series = getConvertedSeries( series ); if ( ( sNewSubType.equalsIgnoreCase( "Stacked" ) || sNewSubType.equalsIgnoreCase( "Percent Stacked" ) ) ) { series.setStacked( true ); } else { series.setStacked( false ); }  ( (SeriesDefinition) seriesdefinitions.get( j ) ).getSeries( ) .clear( );  ( (SeriesDefinition) seriesdefinitions.get( j ) ).getSeries( ) .add( series ); } } else { return null; } } if ( currentChart instanceof ChartWithAxes && !( (ChartWithAxes) currentChart ).getOrientation( ) .equals( newOrientation ) ) { ( (ChartWithAxes) currentChart ).setOrientation( newOrientation ); } if ( !currentChart.getDimension( ) .equals( getDimensionFor( sNewDimension ) ) ) { currentChart.setDimension( getDimensionFor( sNewDimension ) ); } return currentChart; }
    private Chart getConvertedChart(Chart currentChart, String sNewSubType, Orientation newOrientation,        String sNewDimension)    {        Chart helperModel = (Chart) EcoreUtil.copy(currentChart);        if ((currentChart instanceof ChartWithAxes)) // Chart is ChartWithAxes        {            if (currentChart.getType().equals(sType)) // Original chart is of this type (LineChart)            {                if (!currentChart.getSubType().equals(sNewSubType)) // Original chart is of the required subtype                {                    currentChart.setSubType(sNewSubType);                    EList axes = ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).getAssociatedAxes();                    for (int i = 0; i < axes.size(); i++)                    {                        if (sNewSubType.equalsIgnoreCase("Percent Stacked")) //$NON-NLS-1$                        {                            ((Axis) axes.get(i)).setPercent(true);                        }                        else                        {                            ((Axis) axes.get(i)).setPercent(false);                        }                        EList seriesdefinitions = ((Axis) axes.get(i)).getSeriesDefinitions();                        for (int j = 0; j < seriesdefinitions.size(); j++)                        {                            Series series = ((SeriesDefinition) seriesdefinitions.get(j)).getDesignTimeSeries();                            if ((sNewSubType.equalsIgnoreCase("Stacked") || sNewSubType //$NON-NLS-1$                                .equalsIgnoreCase("Percent Stacked"))) //$NON-NLS-1$                            {                                series.setStacked(true);                            }                            else                            {                                series.setStacked(false);                            }                        }                    }                }            }            else if (currentChart.getType().equals("Bar Chart") || currentChart.getType().equals("Stock Chart") //$NON-NLS-1$ //$NON-NLS-2$                || currentChart.getType().equals("Scatter Chart")) //$NON-NLS-1$            {                if (!currentChart.getType().equals("Bar Chart")) //$NON-NLS-1$                {                    currentChart.setSampleData(getConvertedSampleData(currentChart.getSampleData()));                    ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).setType(AxisType.TEXT_LITERAL);                }                currentChart.setType(sType);                currentChart.setSubType(sNewSubType);                EList axes = ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).getAssociatedAxes();                for (int i = 0; i < axes.size(); i++)                {                    if (sNewSubType.equalsIgnoreCase("Percent Stacked")) //$NON-NLS-1$                    {                        ((Axis) axes.get(i)).setPercent(true);                    }                    else                    {                        ((Axis) axes.get(i)).setPercent(false);                    }                    EList seriesdefinitions = ((Axis) axes.get(i)).getSeriesDefinitions();                    for (int j = 0; j < seriesdefinitions.size(); j++)                    {                        Series series = ((SeriesDefinition) seriesdefinitions.get(j)).getDesignTimeSeries();                        series = getConvertedSeries(series);                        if ((sNewSubType.equalsIgnoreCase("Stacked") || sNewSubType.equalsIgnoreCase("Percent Stacked"))) //$NON-NLS-1$ //$NON-NLS-2$                        {                            series.setStacked(true);                        }                        else                        {                            series.setStacked(false);                        }                        ((SeriesDefinition) seriesdefinitions.get(j)).getSeries().clear();                        ((SeriesDefinition) seriesdefinitions.get(j)).getSeries().add(series);                    }                }            }            else            {                return null;            }            ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).setCategoryAxis(true);        }        else        {            // Create a new instance of the correct type and set initial properties            currentChart = ChartWithAxesImpl.create();            currentChart.setType(sType);            currentChart.setSubType(sNewSubType);            ((ChartWithAxes) currentChart).setOrientation(newOrientation);            currentChart.setDimension(getDimensionFor(sNewDimension));            ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).setOrientation(Orientation.HORIZONTAL_LITERAL);            ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).setType(AxisType.TEXT_LITERAL);            ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).setCategoryAxis(true);            ((Axis) ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).getAssociatedAxes().get(0))                .setOrientation(Orientation.VERTICAL_LITERAL);            ((Axis) ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).getAssociatedAxes().get(0))                .setType(AxisType.LINEAR_LITERAL);            // Copy generic chart properties from the old chart            currentChart.setBlock(helperModel.getBlock());            currentChart.setDescription(helperModel.getDescription());            currentChart.setGridColumnCount(helperModel.getGridColumnCount());            currentChart.setSampleData(helperModel.getSampleData());            currentChart.setScript(helperModel.getScript());            currentChart.setSeriesThickness(helperModel.getSeriesThickness());            currentChart.setUnits(helperModel.getUnits());            if (helperModel.getType().equals("Pie Chart")) //$NON-NLS-1$            {                // Clear existing series definitions                ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).getSeriesDefinitions().clear();                // Copy base series definitions                ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).getSeriesDefinitions().add(                    ((ChartWithoutAxes) helperModel).getSeriesDefinitions().get(0));                // Clear existing series definitions                ((Axis) ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).getAssociatedAxes().get(0))                    .getSeriesDefinitions().clear();                // Copy orthogonal series definitions                ((Axis) ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).getAssociatedAxes().get(0))                    .getSeriesDefinitions().addAll(                        ((SeriesDefinition) ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0))                            .getSeriesDefinitions().get(0)).getSeriesDefinitions());                // Update the base series                Series series = ((SeriesDefinition) ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0))                    .getSeriesDefinitions().get(0)).getDesignTimeSeries();                series = getConvertedSeries(series);                // Clear existing series                ((SeriesDefinition) ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).getSeriesDefinitions()                    .get(0)).getSeries().clear();                // Add converted series                ((SeriesDefinition) ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0)).getSeriesDefinitions()                    .get(0)).getSeries().add(series);                // Update the orthogonal series                EList seriesdefinitions = ((Axis) ((Axis) ((ChartWithAxes) currentChart).getAxes().get(0))                    .getAssociatedAxes().get(0)).getSeriesDefinitions();                for (int j = 0; j < seriesdefinitions.size(); j++)                {                    series = ((SeriesDefinition) seriesdefinitions.get(j)).getDesignTimeSeries();                    series = getConvertedSeries(series);                    if ((sNewSubType.equalsIgnoreCase("Stacked") || sNewSubType.equalsIgnoreCase("Percent Stacked"))) //$NON-NLS-1$ //$NON-NLS-2$                    {                        series.setStacked(true);                    }                    else                    {                        series.setStacked(false);                    }                    // Clear any existing series                    ((SeriesDefinition) seriesdefinitions.get(j)).getSeries().clear();                    // Add the new series                    ((SeriesDefinition) seriesdefinitions.get(j)).getSeries().add(series);                }            }            else            {                return null;            }        }        if (currentChart instanceof ChartWithAxes            && !((ChartWithAxes) currentChart).getOrientation().equals(newOrientation))        {            ((ChartWithAxes) currentChart).setOrientation(newOrientation);        }        if (!currentChart.getDimension().equals(getDimensionFor(sNewDimension)))        {            currentChart.setDimension(getDimensionFor(sNewDimension));        }        return currentChart;    }