From 9a5aaee9ae21a2492d3da98a5116aed805834c13 Mon Sep 17 00:00:00 2001 From: Jinkun Jang Date: Wed, 13 Mar 2013 02:17:48 +0900 Subject: Tizen 2.1 base --- AUTHORS | 3 + LICENSE.EPL | 261 ++++ NOTICE | 3 + builder/build.properties.clean | 259 ++++ builder/customTargets.xml | 187 +++ org.eclipse.linuxtools.binutils/.classpath | 7 + org.eclipse.linuxtools.binutils/.project | 28 + .../.settings/org.eclipse.jdt.core.prefs | 7 + .../META-INF/MANIFEST.MF | 23 + org.eclipse.linuxtools.binutils/about.html | 26 + org.eclipse.linuxtools.binutils/build.properties | 16 + .../icons/c_file_obj.gif | Bin 0 -> 354 bytes org.eclipse.linuxtools.binutils/plugin.properties | 13 + org.eclipse.linuxtools.binutils/plugin.xml | 15 + ...g.eclipse.linuxtools.binutils.crossCompile.exsd | 109 ++ .../org/eclipse/linuxtools/binutils/Activator.java | 60 + .../link2source/STCSourceNotFoundEditor.java | 232 +++ .../link2source/STCSourceNotFoundEditorInput.java | 155 ++ .../binutils/link2source/STLink2SourceSupport.java | 557 +++++++ .../binutils/utils/DefaultBinutilsFactory.java | 46 + .../binutils/utils/ISTBinutilsFactory.java | 31 + .../binutils/utils/STAddr2LineFactory.java | 36 + .../linuxtools/binutils/utils/STAddr2line.java | 50 + .../binutils/utils/STBinutilsFactoryManager.java | 90 ++ .../binutils/utils/STCPPFiltFactory.java | 38 + .../eclipse/linuxtools/binutils/utils/STNM.java | 110 ++ .../linuxtools/binutils/utils/STNMFactory.java | 29 + .../binutils/utils/STNMSymbolsHandler.java | 23 + .../linuxtools/binutils/utils/STSymbolManager.java | 591 +++++++ .../.classpath | 7 + .../.project | 28 + .../.settings/org.eclipse.jdt.core.prefs | 3 + .../.settings/org.eclipse.jdt.ui.prefs | 3 + .../META-INF/MANIFEST.MF | 24 + .../about.html | 28 + .../build.properties | 8 + .../icons/c_file_obj.gif | Bin 0 -> 617 bytes .../plugin.properties | 12 + .../plugin.xml | 58 + .../AbstractSTAnnotatedSourceEditorInput.java | 82 + .../annotatedsourceeditor/ISTAnnotationColumn.java | 19 + .../ISTTextEditorActionConstants.java | 19 + .../ISTTextEditorActionDefinitionIds.java | 20 + .../STAnnotatedCSourceEditor.java | 449 ++++++ .../STAnnotatedSourceEditorActivator.java | 76 + .../annotatedsourceeditor/STChangeRulerColumn.java | 390 +++++ .../STConstructedTextEditorMessages.properties | 4 + .../STContributedRulerColumn.java | 798 ++++++++++ .../annotatedsourceeditor/STJFaceTextMessages.java | 67 + .../annotatedsourceeditor/STOverviewRuler.java | 1309 ++++++++++++++++ .../annotatedsourceeditor/STRulerColumn.java | 876 +++++++++++ .../annotatedsourceeditor/STRulerMessages.java | 34 + .../STTextEditorMessages.java | 37 + .../actions/AbstractOpenSourceFileAction.java | 93 ++ .../actions/OpenFileFullPathAction.java | 32 + .../actions/OpenWksRelFilePathAction.java | 63 + .../hyperlink/ISTAnnotationHyperlink.java | 17 + .../STAnnotatedSourceEditorPreferencePage.java | 59 + .../.classpath | 7 + org.eclipse.linuxtools.dataviewers.charts/.project | 28 + .../META-INF/MANIFEST.MF | 26 + .../about.html | 26 + .../build.properties | 8 + .../icons/Thumbs.db | Bin 0 -> 3584 bytes .../icons/chart_icon.png | Bin 0 -> 573 bytes .../icons/dexport.gif | Bin 0 -> 142 bytes .../icons/dimport.gif | Bin 0 -> 143 bytes .../icons/eexport.gif | Bin 0 -> 329 bytes .../icons/eimport.gif | Bin 0 -> 327 bytes .../icons/save_chart.gif | Bin 0 -> 583 bytes .../plugin.properties | 14 + .../plugin.xml | 21 + .../linuxtools/dataviewers/charts/Activator.java | 88 ++ .../dataviewers/charts/ChartConstants.java | 85 ++ .../linuxtools/dataviewers/charts/UIHelper.java | 143 ++ .../dataviewers/charts/actions/ChartAction.java | 67 + .../charts/actions/ChartActionRenderer.java | 46 + .../charts/actions/OpenChartAction.java | 77 + .../charts/actions/SaveChartAction.java | 286 ++++ .../dataviewers/charts/actions/SaveXMLAction.java | 133 ++ .../charts/dataengine/BindDataEngine.java | 364 +++++ .../charts/dataengine/FlatFileDataSource.java | 70 + .../dataengine/FlatFileDataSourceFactory.java | 40 + .../dataengine/GroupedRowExpressionsEvaluator.java | 280 ++++ .../dataviewers/charts/dialogs/ChartDialog.java | 427 ++++++ .../dataviewers/charts/provider/ChartFactory.java | 251 +++ .../charts/provider/ChartUpdateNotifier.java | 41 + .../dataviewers/charts/provider/IChartField.java | 30 + .../dataviewers/charts/view/ChartView.java | 204 +++ .../dataviewers/charts/viewer/ChartViewer.java | 252 +++ org.eclipse.linuxtools.dataviewers/.classpath | 11 + org.eclipse.linuxtools.dataviewers/.project | 28 + .../.settings/org.eclipse.jdt.core.prefs | 74 + .../.settings/org.eclipse.jdt.ui.prefs | 3 + .../META-INF/MANIFEST.MF | 23 + org.eclipse.linuxtools.dataviewers/about.html | 28 + .../build.properties | 23 + .../doc/AbstractSTProfViewers.ppt | Bin 0 -> 52736 bytes .../doc/DataViewersFind.html | 69 + .../icons/backward_nav.gif | Bin 0 -> 327 bytes .../icons/bin_obj.gif | Bin 0 -> 156 bytes .../icons/collapse_all.gif | Bin 0 -> 157 bytes .../icons/exec_obj.gif | Bin 0 -> 125 bytes .../icons/expand_all.gif | Bin 0 -> 165 bytes .../icons/export.gif | Bin 0 -> 329 bytes .../icons/filter_ps.gif | Bin 0 -> 219 bytes .../icons/flexperf.gif | Bin 0 -> 1380 bytes .../icons/forward_nav.gif | Bin 0 -> 215 bytes .../icons/function_obj.gif | Bin 0 -> 97 bytes .../icons/info_obj.gif | Bin 0 -> 121 bytes .../icons/left-end.gif | Bin 0 -> 106 bytes org.eclipse.linuxtools.dataviewers/icons/left.gif | Bin 0 -> 98 bytes .../icons/percentage.gif | Bin 0 -> 599 bytes org.eclipse.linuxtools.dataviewers/icons/pie.gif | Bin 0 -> 582 bytes .../icons/printer.gif | Bin 0 -> 1037 bytes .../icons/prop_edt.gif | Bin 0 -> 571 bytes .../icons/right-end.gif | Bin 0 -> 104 bytes org.eclipse.linuxtools.dataviewers/icons/right.gif | Bin 0 -> 98 bytes .../icons/sample.gif | Bin 0 -> 983 bytes .../icons/search.gif | Bin 0 -> 347 bytes org.eclipse.linuxtools.dataviewers/icons/sort.gif | Bin 0 -> 162 bytes org.eclipse.linuxtools.dataviewers/icons/st.gif | Bin 0 -> 329 bytes .../icons/toggle.gif | Bin 0 -> 610 bytes .../icons/variable_obj.gif | Bin 0 -> 78 bytes .../plugin.properties | 12 + .../dataviewers/STDataViewersActivator.java | 85 ++ .../abstractview/AbstractSTDataView.java | 506 ++++++ .../AbstractPercentageDrawerField.java | 99 ++ .../AbstractSTDataViewersField.java | 140 ++ .../abstractviewers/AbstractSTTableViewer.java | 242 +++ .../abstractviewers/AbstractSTTreeViewer.java | 252 +++ .../abstractviewers/AbstractSTViewer.java | 740 +++++++++ .../abstractviewers/ISTDataViewersField.java | 154 ++ .../abstractviewers/STDataViewersCSVExporter.java | 778 ++++++++++ .../STDataViewersCSVExporterConstants.java | 41 + .../STDataViewersColumnLabelProvider.java | 96 ++ .../abstractviewers/STDataViewersComparator.java | 352 +++++ .../STDataViewersHideShowManager.java | 247 +++ .../STDataViewersHyperLinkDrawerField.java | 57 + .../abstractviewers/STDataViewersImages.java | 197 +++ .../abstractviewers/STDataViewersMessages.java | 62 + .../STDataViewersMessages.properties | 37 + .../abstractviewers/STDataViewersSettings.java | 33 + .../abstractviewers/STOwnerDrawLabelProvider.java | 90 ++ .../actions/STCollapseAllTreeAction.java | 47 + .../actions/STCollapseSelectionAction.java | 53 + .../dataviewers/actions/STCopyAction.java | 66 + .../actions/STDataViewersFiltersAction.java | 32 + .../actions/STDataViewersSortAction.java | 73 + .../dataviewers/actions/STExpandAllTreeAction.java | 47 + .../actions/STExpandSelectionAction.java | 53 + .../dataviewers/actions/STExportToCSVAction.java | 78 + .../dataviewers/actions/STHideShowColAction.java | 59 + .../dialogs/STDataViewersExportToCSVDialog.java | 675 ++++++++ .../STDataViewersHideShowColumnsDialog.java | 254 ++++ .../dialogs/STDataViewersSortDialog.java | 361 +++++ .../dataviewers/findreplace/EditorMessages.java | 125 ++ .../findreplace/EditorMessages.properties | 120 ++ .../findreplace/ISTFindReplaceTarget.java | 83 + .../findreplace/RegExContentProposalProvider.java | 375 +++++ .../dataviewers/findreplace/RegExMessages.java | 200 +++ .../findreplace/STFindReplaceAction.java | 330 ++++ .../findreplace/STFindReplaceDialog.java | 1605 ++++++++++++++++++++ .../findreplace/STTableFindReplaceTarget.java | 291 ++++ .../dataviewers/findreplace/STTableViewerRow.java | 198 +++ .../findreplace/STTreeFindReplaceTarget.java | 296 ++++ .../dataviewers/findreplace/STTreeViewerRow.java | 315 ++++ .../listeners/ISpecialDrawerListener.java | 17 + .../listeners/STColumnSizeListener.java | 36 + .../dataviewers/listeners/STDisposeListener.java | 29 + .../dataviewers/listeners/STHeaderListener.java | 66 + .../dataviewers/listeners/STSelectionProvider.java | 63 + org.eclipse.linuxtools.gcov-feature/.project | 17 + .../build.properties | 8 + org.eclipse.linuxtools.gcov-feature/epl-v10.html | 256 ++++ .../feature.properties | 138 ++ org.eclipse.linuxtools.gcov-feature/feature.xml | 59 + org.eclipse.linuxtools.gcov-feature/license.html | 107 ++ org.eclipse.linuxtools.gcov.test/.classpath | 7 + org.eclipse.linuxtools.gcov.test/.project | 28 + .../.settings/org.eclipse.jdt.core.prefs | 7 + .../META-INF/MANIFEST.MF | 9 + org.eclipse.linuxtools.gcov.test/about.html | 33 + org.eclipse.linuxtools.gcov.test/build.properties | 9 + org.eclipse.linuxtools.gcov.test/plugin.properties | 12 + .../eclipse/linuxtools/gcov/test/AllGcovTests.java | 29 + .../gcov/test/GcovGCDARetrieverTest.java | 68 + .../linuxtools/gcov/test/GcovParserTest.java | 59 + .../linuxtools/gcov/test/GcovTestUtils.java | 66 + .../eclipse/linuxtools/gcov/test/GcovViewTest.java | 111 ++ .../eclipse/linuxtools/gcov/test/STJunitUtils.java | 267 ++++ org.eclipse.linuxtools.gcov.test/test.xml | 54 + org.eclipse.linuxtools.gcov.test/test_c/Makefile | 8 + org.eclipse.linuxtools.gcov.test/test_c/a.out | Bin 0 -> 30722 bytes org.eclipse.linuxtools.gcov.test/test_c/fact.c | 19 + org.eclipse.linuxtools.gcov.test/test_c/fact.gcda | Bin 0 -> 168 bytes org.eclipse.linuxtools.gcov.test/test_c/fact.gcno | Bin 0 -> 480 bytes org.eclipse.linuxtools.gcov.test/test_c/main.c | 28 + org.eclipse.linuxtools.gcov.test/test_c/main.gcda | Bin 0 -> 176 bytes org.eclipse.linuxtools.gcov.test/test_c/main.gcno | Bin 0 -> 676 bytes org.eclipse.linuxtools.gcov.test/test_c/mult.c | 21 + org.eclipse.linuxtools.gcov.test/test_c/mult.gcda | Bin 0 -> 152 bytes org.eclipse.linuxtools.gcov.test/test_c/mult.gcno | Bin 0 -> 500 bytes .../test_c/testProcessCovFiles.ref | 30 + .../test_c/testView.ref | 8 + .../test_c/testViewFolder.ref | 9 + .../test_c/testViewFunction.ref | 5 + org.eclipse.linuxtools.gcov.test/test_cpp/Makefile | 8 + org.eclipse.linuxtools.gcov.test/test_cpp/a.out | Bin 0 -> 34593 bytes org.eclipse.linuxtools.gcov.test/test_cpp/fact.cpp | 31 + .../test_cpp/fact.gcda | Bin 0 -> 320 bytes .../test_cpp/fact.gcno | Bin 0 -> 1268 bytes org.eclipse.linuxtools.gcov.test/test_cpp/fact.hpp | 26 + org.eclipse.linuxtools.gcov.test/test_cpp/main.cpp | 30 + .../test_cpp/main.gcda | Bin 0 -> 864 bytes .../test_cpp/main.gcno | Bin 0 -> 8992 bytes org.eclipse.linuxtools.gcov.test/test_cpp/mult.cpp | 29 + .../test_cpp/mult.gcda | Bin 0 -> 280 bytes .../test_cpp/mult.gcno | Bin 0 -> 1140 bytes org.eclipse.linuxtools.gcov.test/test_cpp/mult.hpp | 22 + .../test_cpp/testProcessCovFiles.ref | 148 ++ .../test_cpp/testView.ref | 36 + .../test_cpp/testViewFolder.ref | 39 + .../test_cpp/testViewFunction.ref | 27 + org.eclipse.linuxtools.gcov/.classpath | 7 + org.eclipse.linuxtools.gcov/.project | 28 + .../.settings/org.eclipse.jdt.core.prefs | 7 + org.eclipse.linuxtools.gcov/META-INF/MANIFEST.MF | 32 + org.eclipse.linuxtools.gcov/NOTICE | 6 + org.eclipse.linuxtools.gcov/about.html | 28 + org.eclipse.linuxtools.gcov/build.properties | 8 + org.eclipse.linuxtools.gcov/icons/c_file_obj.gif | Bin 0 -> 1019 bytes .../icons/directory_obj.gif | Bin 0 -> 162 bytes org.eclipse.linuxtools.gcov/icons/function_obj.gif | Bin 0 -> 617 bytes org.eclipse.linuxtools.gcov/icons/src_file_obj.gif | Bin 0 -> 617 bytes org.eclipse.linuxtools.gcov/icons/toggle.gif | Bin 0 -> 610 bytes org.eclipse.linuxtools.gcov/plugin.properties | 16 + org.eclipse.linuxtools.gcov/plugin.xml | 38 + .../src/org/eclipse/linuxtools/gcov/Activator.java | 71 + .../linuxtools/gcov/action/OpenGCAction.java | 166 ++ .../gcov/action/SwitchContentProviderAction.java | 44 + .../linuxtools/gcov/dialog/OpenGCDialog.java | 303 ++++ .../linuxtools/gcov/model/AbstractTreeElement.java | 79 + .../linuxtools/gcov/model/CovFileTreeElement.java | 25 + .../gcov/model/CovFolderTreeElement.java | 24 + .../gcov/model/CovFunctionTreeElement.java | 57 + .../linuxtools/gcov/model/CovRootTreeElement.java | 26 + .../eclipse/linuxtools/gcov/model/TreeElement.java | 27 + .../org/eclipse/linuxtools/gcov/parser/Arc.java | 131 ++ .../org/eclipse/linuxtools/gcov/parser/Block.java | 177 +++ .../eclipse/linuxtools/gcov/parser/CovManager.java | 372 +++++ .../linuxtools/gcov/parser/CoverageInfo.java | 52 + .../org/eclipse/linuxtools/gcov/parser/Folder.java | 65 + .../linuxtools/gcov/parser/GcdaRecordsParser.java | 272 ++++ .../linuxtools/gcov/parser/GcnoFunction.java | 255 ++++ .../linuxtools/gcov/parser/GcnoRecordsParser.java | 241 +++ .../org/eclipse/linuxtools/gcov/parser/Line.java | 50 + .../eclipse/linuxtools/gcov/parser/SourceFile.java | 110 ++ .../linuxtools/gcov/utils/BEDataInputStream.java | 191 +++ .../linuxtools/gcov/utils/GcovStringReader.java | 38 + .../linuxtools/gcov/utils/LEDataInputStream.java | 208 +++ .../linuxtools/gcov/utils/MasksGenerator.java | 15 + .../gcov/utils/STGcovProgramChecker.java | 85 ++ .../gcov/view/CovFileContentProvider.java | 60 + .../gcov/view/CovFolderContentProvider.java | 61 + .../gcov/view/CovFunctionContentProvider.java | 52 + .../org/eclipse/linuxtools/gcov/view/CovView.java | 289 ++++ .../eclipse/linuxtools/gcov/view/CovViewer.java | 119 ++ .../gcov/view/FieldCoveragePercentage.java | 100 ++ .../linuxtools/gcov/view/FieldExecutedLines.java | 68 + .../gcov/view/FieldInstrumentedLines.java | 77 + .../eclipse/linuxtools/gcov/view/FieldName.java | 69 + .../linuxtools/gcov/view/FieldTotalLines.java | 82 + .../annotatedsource/CoverageAnnotationColumn.java | 79 + .../view/annotatedsource/OpenSourceFileAction.java | 136 ++ .../STAnnotatedSourceEditorInput.java | 73 + .../STAnnotatedSourceNotFoundEditor.java | 50 + .../STAnnotatedSourceNotFoundEditorInput.java | 69 + org.tizen.codecoverage.feature/.project | 17 + org.tizen.codecoverage.feature/build.properties | 2 + org.tizen.codecoverage.feature/feature.properties | 41 + org.tizen.codecoverage.feature/feature.xml | 183 +++ org.tizen.codecoverage.update/.project | 17 + org.tizen.codecoverage/.classpath | 7 + org.tizen.codecoverage/.project | 28 + .../.settings/org.eclipse.jdt.core.prefs | 72 + org.tizen.codecoverage/32_TIZEN_SDK_icon.png | Bin 0 -> 5237 bytes org.tizen.codecoverage/META-INF/MANIFEST.MF | 22 + org.tizen.codecoverage/NOTICE | 2 + .../OSGI-INF/l10n/bundle.properties | 2 + org.tizen.codecoverage/about.ini | 32 + org.tizen.codecoverage/about.mappings | 6 + org.tizen.codecoverage/about.properties | 12 + org.tizen.codecoverage/build.properties | 11 + org.tizen.codecoverage/icons/toolbar_icon.gif | Bin 0 -> 610 bytes org.tizen.codecoverage/plugin.xml | 31 + .../src/org/tizen/codecoverage/Activator.java | 70 + .../org/tizen/codecoverage/actions/GcovAction.java | 112 ++ .../org/tizen/codecoverage/helper/GcovHelper.java | 176 +++ package/build.linux | 72 + package/changelog | 15 + package/pkginfo.manifest | 38 + 302 files changed, 28534 insertions(+) create mode 100644 AUTHORS create mode 100644 LICENSE.EPL create mode 100644 NOTICE create mode 100644 builder/build.properties.clean create mode 100644 builder/customTargets.xml create mode 100644 org.eclipse.linuxtools.binutils/.classpath create mode 100644 org.eclipse.linuxtools.binutils/.project create mode 100644 org.eclipse.linuxtools.binutils/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.eclipse.linuxtools.binutils/META-INF/MANIFEST.MF create mode 100644 org.eclipse.linuxtools.binutils/about.html create mode 100644 org.eclipse.linuxtools.binutils/build.properties create mode 100644 org.eclipse.linuxtools.binutils/icons/c_file_obj.gif create mode 100644 org.eclipse.linuxtools.binutils/plugin.properties create mode 100644 org.eclipse.linuxtools.binutils/plugin.xml create mode 100644 org.eclipse.linuxtools.binutils/schema/org.eclipse.linuxtools.binutils.crossCompile.exsd create mode 100644 org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/Activator.java create mode 100644 org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/link2source/STCSourceNotFoundEditor.java create mode 100644 org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/link2source/STCSourceNotFoundEditorInput.java create mode 100644 org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/link2source/STLink2SourceSupport.java create mode 100644 org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/DefaultBinutilsFactory.java create mode 100644 org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/ISTBinutilsFactory.java create mode 100644 org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STAddr2LineFactory.java create mode 100644 org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STAddr2line.java create mode 100644 org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STBinutilsFactoryManager.java create mode 100644 org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STCPPFiltFactory.java create mode 100644 org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STNM.java create mode 100644 org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STNMFactory.java create mode 100644 org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STNMSymbolsHandler.java create mode 100644 org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STSymbolManager.java create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/.classpath create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/.project create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/.settings/org.eclipse.jdt.ui.prefs create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/META-INF/MANIFEST.MF create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/about.html create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/build.properties create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/icons/c_file_obj.gif create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/plugin.properties create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/plugin.xml create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/AbstractSTAnnotatedSourceEditorInput.java create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/ISTAnnotationColumn.java create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/ISTTextEditorActionConstants.java create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/ISTTextEditorActionDefinitionIds.java create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STAnnotatedCSourceEditor.java create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STAnnotatedSourceEditorActivator.java create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STChangeRulerColumn.java create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STConstructedTextEditorMessages.properties create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STContributedRulerColumn.java create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STJFaceTextMessages.java create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STOverviewRuler.java create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STRulerColumn.java create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STRulerMessages.java create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STTextEditorMessages.java create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/actions/AbstractOpenSourceFileAction.java create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/actions/OpenFileFullPathAction.java create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/actions/OpenWksRelFilePathAction.java create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/hyperlink/ISTAnnotationHyperlink.java create mode 100644 org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/preferencespages/STAnnotatedSourceEditorPreferencePage.java create mode 100755 org.eclipse.linuxtools.dataviewers.charts/.classpath create mode 100755 org.eclipse.linuxtools.dataviewers.charts/.project create mode 100755 org.eclipse.linuxtools.dataviewers.charts/META-INF/MANIFEST.MF create mode 100644 org.eclipse.linuxtools.dataviewers.charts/about.html create mode 100755 org.eclipse.linuxtools.dataviewers.charts/build.properties create mode 100755 org.eclipse.linuxtools.dataviewers.charts/icons/Thumbs.db create mode 100755 org.eclipse.linuxtools.dataviewers.charts/icons/chart_icon.png create mode 100644 org.eclipse.linuxtools.dataviewers.charts/icons/dexport.gif create mode 100644 org.eclipse.linuxtools.dataviewers.charts/icons/dimport.gif create mode 100644 org.eclipse.linuxtools.dataviewers.charts/icons/eexport.gif create mode 100644 org.eclipse.linuxtools.dataviewers.charts/icons/eimport.gif create mode 100755 org.eclipse.linuxtools.dataviewers.charts/icons/save_chart.gif create mode 100644 org.eclipse.linuxtools.dataviewers.charts/plugin.properties create mode 100755 org.eclipse.linuxtools.dataviewers.charts/plugin.xml create mode 100755 org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/Activator.java create mode 100755 org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/ChartConstants.java create mode 100644 org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/UIHelper.java create mode 100755 org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/ChartAction.java create mode 100644 org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/ChartActionRenderer.java create mode 100644 org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/OpenChartAction.java create mode 100755 org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/SaveChartAction.java create mode 100644 org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/SaveXMLAction.java create mode 100644 org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/dataengine/BindDataEngine.java create mode 100644 org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/dataengine/FlatFileDataSource.java create mode 100644 org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/dataengine/FlatFileDataSourceFactory.java create mode 100644 org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/dataengine/GroupedRowExpressionsEvaluator.java create mode 100755 org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/dialogs/ChartDialog.java create mode 100755 org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/provider/ChartFactory.java create mode 100644 org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/provider/ChartUpdateNotifier.java create mode 100755 org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/provider/IChartField.java create mode 100755 org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/view/ChartView.java create mode 100755 org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/viewer/ChartViewer.java create mode 100644 org.eclipse.linuxtools.dataviewers/.classpath create mode 100644 org.eclipse.linuxtools.dataviewers/.project create mode 100644 org.eclipse.linuxtools.dataviewers/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.eclipse.linuxtools.dataviewers/.settings/org.eclipse.jdt.ui.prefs create mode 100644 org.eclipse.linuxtools.dataviewers/META-INF/MANIFEST.MF create mode 100644 org.eclipse.linuxtools.dataviewers/about.html create mode 100644 org.eclipse.linuxtools.dataviewers/build.properties create mode 100644 org.eclipse.linuxtools.dataviewers/doc/AbstractSTProfViewers.ppt create mode 100644 org.eclipse.linuxtools.dataviewers/doc/DataViewersFind.html create mode 100644 org.eclipse.linuxtools.dataviewers/icons/backward_nav.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/bin_obj.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/collapse_all.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/exec_obj.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/expand_all.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/export.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/filter_ps.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/flexperf.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/forward_nav.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/function_obj.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/info_obj.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/left-end.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/left.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/percentage.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/pie.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/printer.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/prop_edt.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/right-end.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/right.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/sample.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/search.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/sort.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/st.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/toggle.gif create mode 100644 org.eclipse.linuxtools.dataviewers/icons/variable_obj.gif create mode 100644 org.eclipse.linuxtools.dataviewers/plugin.properties create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/STDataViewersActivator.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractview/AbstractSTDataView.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/AbstractPercentageDrawerField.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/AbstractSTDataViewersField.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/AbstractSTTableViewer.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/AbstractSTTreeViewer.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/AbstractSTViewer.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/ISTDataViewersField.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/STDataViewersCSVExporter.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/STDataViewersCSVExporterConstants.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/STDataViewersColumnLabelProvider.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/STDataViewersComparator.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/STDataViewersHideShowManager.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/STDataViewersHyperLinkDrawerField.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/STDataViewersImages.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/STDataViewersMessages.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/STDataViewersMessages.properties create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/STDataViewersSettings.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/abstractviewers/STOwnerDrawLabelProvider.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/actions/STCollapseAllTreeAction.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/actions/STCollapseSelectionAction.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/actions/STCopyAction.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/actions/STDataViewersFiltersAction.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/actions/STDataViewersSortAction.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/actions/STExpandAllTreeAction.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/actions/STExpandSelectionAction.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/actions/STExportToCSVAction.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/actions/STHideShowColAction.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/dialogs/STDataViewersExportToCSVDialog.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/dialogs/STDataViewersHideShowColumnsDialog.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/dialogs/STDataViewersSortDialog.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/findreplace/EditorMessages.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/findreplace/EditorMessages.properties create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/findreplace/ISTFindReplaceTarget.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/findreplace/RegExContentProposalProvider.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/findreplace/RegExMessages.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/findreplace/STFindReplaceAction.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/findreplace/STFindReplaceDialog.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/findreplace/STTableFindReplaceTarget.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/findreplace/STTableViewerRow.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/findreplace/STTreeFindReplaceTarget.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/findreplace/STTreeViewerRow.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/listeners/ISpecialDrawerListener.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/listeners/STColumnSizeListener.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/listeners/STDisposeListener.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/listeners/STHeaderListener.java create mode 100644 org.eclipse.linuxtools.dataviewers/src/org/eclipse/linuxtools/dataviewers/listeners/STSelectionProvider.java create mode 100755 org.eclipse.linuxtools.gcov-feature/.project create mode 100755 org.eclipse.linuxtools.gcov-feature/build.properties create mode 100755 org.eclipse.linuxtools.gcov-feature/epl-v10.html create mode 100755 org.eclipse.linuxtools.gcov-feature/feature.properties create mode 100755 org.eclipse.linuxtools.gcov-feature/feature.xml create mode 100644 org.eclipse.linuxtools.gcov-feature/license.html create mode 100644 org.eclipse.linuxtools.gcov.test/.classpath create mode 100644 org.eclipse.linuxtools.gcov.test/.project create mode 100644 org.eclipse.linuxtools.gcov.test/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.eclipse.linuxtools.gcov.test/META-INF/MANIFEST.MF create mode 100644 org.eclipse.linuxtools.gcov.test/about.html create mode 100644 org.eclipse.linuxtools.gcov.test/build.properties create mode 100644 org.eclipse.linuxtools.gcov.test/plugin.properties create mode 100755 org.eclipse.linuxtools.gcov.test/src/org/eclipse/linuxtools/gcov/test/AllGcovTests.java create mode 100755 org.eclipse.linuxtools.gcov.test/src/org/eclipse/linuxtools/gcov/test/GcovGCDARetrieverTest.java create mode 100755 org.eclipse.linuxtools.gcov.test/src/org/eclipse/linuxtools/gcov/test/GcovParserTest.java create mode 100755 org.eclipse.linuxtools.gcov.test/src/org/eclipse/linuxtools/gcov/test/GcovTestUtils.java create mode 100755 org.eclipse.linuxtools.gcov.test/src/org/eclipse/linuxtools/gcov/test/GcovViewTest.java create mode 100755 org.eclipse.linuxtools.gcov.test/src/org/eclipse/linuxtools/gcov/test/STJunitUtils.java create mode 100755 org.eclipse.linuxtools.gcov.test/test.xml create mode 100644 org.eclipse.linuxtools.gcov.test/test_c/Makefile create mode 100755 org.eclipse.linuxtools.gcov.test/test_c/a.out create mode 100644 org.eclipse.linuxtools.gcov.test/test_c/fact.c create mode 100644 org.eclipse.linuxtools.gcov.test/test_c/fact.gcda create mode 100644 org.eclipse.linuxtools.gcov.test/test_c/fact.gcno create mode 100644 org.eclipse.linuxtools.gcov.test/test_c/main.c create mode 100644 org.eclipse.linuxtools.gcov.test/test_c/main.gcda create mode 100644 org.eclipse.linuxtools.gcov.test/test_c/main.gcno create mode 100644 org.eclipse.linuxtools.gcov.test/test_c/mult.c create mode 100644 org.eclipse.linuxtools.gcov.test/test_c/mult.gcda create mode 100644 org.eclipse.linuxtools.gcov.test/test_c/mult.gcno create mode 100644 org.eclipse.linuxtools.gcov.test/test_c/testProcessCovFiles.ref create mode 100644 org.eclipse.linuxtools.gcov.test/test_c/testView.ref create mode 100644 org.eclipse.linuxtools.gcov.test/test_c/testViewFolder.ref create mode 100644 org.eclipse.linuxtools.gcov.test/test_c/testViewFunction.ref create mode 100644 org.eclipse.linuxtools.gcov.test/test_cpp/Makefile create mode 100755 org.eclipse.linuxtools.gcov.test/test_cpp/a.out create mode 100644 org.eclipse.linuxtools.gcov.test/test_cpp/fact.cpp create mode 100644 org.eclipse.linuxtools.gcov.test/test_cpp/fact.gcda create mode 100644 org.eclipse.linuxtools.gcov.test/test_cpp/fact.gcno create mode 100644 org.eclipse.linuxtools.gcov.test/test_cpp/fact.hpp create mode 100644 org.eclipse.linuxtools.gcov.test/test_cpp/main.cpp create mode 100644 org.eclipse.linuxtools.gcov.test/test_cpp/main.gcda create mode 100644 org.eclipse.linuxtools.gcov.test/test_cpp/main.gcno create mode 100644 org.eclipse.linuxtools.gcov.test/test_cpp/mult.cpp create mode 100644 org.eclipse.linuxtools.gcov.test/test_cpp/mult.gcda create mode 100644 org.eclipse.linuxtools.gcov.test/test_cpp/mult.gcno create mode 100644 org.eclipse.linuxtools.gcov.test/test_cpp/mult.hpp create mode 100644 org.eclipse.linuxtools.gcov.test/test_cpp/testProcessCovFiles.ref create mode 100644 org.eclipse.linuxtools.gcov.test/test_cpp/testView.ref create mode 100644 org.eclipse.linuxtools.gcov.test/test_cpp/testViewFolder.ref create mode 100644 org.eclipse.linuxtools.gcov.test/test_cpp/testViewFunction.ref create mode 100644 org.eclipse.linuxtools.gcov/.classpath create mode 100644 org.eclipse.linuxtools.gcov/.project create mode 100644 org.eclipse.linuxtools.gcov/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.eclipse.linuxtools.gcov/META-INF/MANIFEST.MF create mode 100644 org.eclipse.linuxtools.gcov/NOTICE create mode 100644 org.eclipse.linuxtools.gcov/about.html create mode 100644 org.eclipse.linuxtools.gcov/build.properties create mode 100644 org.eclipse.linuxtools.gcov/icons/c_file_obj.gif create mode 100644 org.eclipse.linuxtools.gcov/icons/directory_obj.gif create mode 100644 org.eclipse.linuxtools.gcov/icons/function_obj.gif create mode 100644 org.eclipse.linuxtools.gcov/icons/src_file_obj.gif create mode 100644 org.eclipse.linuxtools.gcov/icons/toggle.gif create mode 100644 org.eclipse.linuxtools.gcov/plugin.properties create mode 100644 org.eclipse.linuxtools.gcov/plugin.xml create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/Activator.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/action/OpenGCAction.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/action/SwitchContentProviderAction.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/dialog/OpenGCDialog.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/AbstractTreeElement.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/CovFileTreeElement.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/CovFolderTreeElement.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/CovFunctionTreeElement.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/CovRootTreeElement.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/model/TreeElement.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/Arc.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/Block.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/CovManager.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/CoverageInfo.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/Folder.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/GcdaRecordsParser.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/GcnoFunction.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/GcnoRecordsParser.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/Line.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/parser/SourceFile.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/BEDataInputStream.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/GcovStringReader.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/LEDataInputStream.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/MasksGenerator.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/utils/STGcovProgramChecker.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovFileContentProvider.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovFolderContentProvider.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovFunctionContentProvider.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovView.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/CovViewer.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldCoveragePercentage.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldExecutedLines.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldInstrumentedLines.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldName.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/FieldTotalLines.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/CoverageAnnotationColumn.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/OpenSourceFileAction.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/STAnnotatedSourceEditorInput.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/STAnnotatedSourceNotFoundEditor.java create mode 100644 org.eclipse.linuxtools.gcov/src/org/eclipse/linuxtools/gcov/view/annotatedsource/STAnnotatedSourceNotFoundEditorInput.java create mode 100644 org.tizen.codecoverage.feature/.project create mode 100644 org.tizen.codecoverage.feature/build.properties create mode 100644 org.tizen.codecoverage.feature/feature.properties create mode 100644 org.tizen.codecoverage.feature/feature.xml create mode 100644 org.tizen.codecoverage.update/.project create mode 100644 org.tizen.codecoverage/.classpath create mode 100644 org.tizen.codecoverage/.project create mode 100644 org.tizen.codecoverage/.settings/org.eclipse.jdt.core.prefs create mode 100644 org.tizen.codecoverage/32_TIZEN_SDK_icon.png create mode 100644 org.tizen.codecoverage/META-INF/MANIFEST.MF create mode 100644 org.tizen.codecoverage/NOTICE create mode 100644 org.tizen.codecoverage/OSGI-INF/l10n/bundle.properties create mode 100644 org.tizen.codecoverage/about.ini create mode 100644 org.tizen.codecoverage/about.mappings create mode 100644 org.tizen.codecoverage/about.properties create mode 100644 org.tizen.codecoverage/build.properties create mode 100644 org.tizen.codecoverage/icons/toolbar_icon.gif create mode 100644 org.tizen.codecoverage/plugin.xml create mode 100644 org.tizen.codecoverage/src/org/tizen/codecoverage/Activator.java create mode 100644 org.tizen.codecoverage/src/org/tizen/codecoverage/actions/GcovAction.java create mode 100644 org.tizen.codecoverage/src/org/tizen/codecoverage/helper/GcovHelper.java create mode 100755 package/build.linux create mode 100644 package/changelog create mode 100644 package/pkginfo.manifest diff --git a/AUTHORS b/AUTHORS new file mode 100644 index 0000000..545dff2 --- /dev/null +++ b/AUTHORS @@ -0,0 +1,3 @@ +Kangho Kim +Gun Kim +HyunGoo Kang diff --git a/LICENSE.EPL b/LICENSE.EPL new file mode 100644 index 0000000..3998fce --- /dev/null +++ b/LICENSE.EPL @@ -0,0 +1,261 @@ + + + + + + +Eclipse Public License - Version 1.0 + + + + + + +

Eclipse Public License - v 1.0

+ +

THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE +PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR +DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS +AGREEMENT.

+ +

1. DEFINITIONS

+ +

"Contribution" means:

+ +

a) in the case of the initial Contributor, the initial +code and documentation distributed under this Agreement, and

+

b) in the case of each subsequent Contributor:

+

i) changes to the Program, and

+

ii) additions to the Program;

+

where such changes and/or additions to the Program +originate from and are distributed by that particular Contributor. A +Contribution 'originates' from a Contributor if it was added to the +Program by such Contributor itself or anyone acting on such +Contributor's behalf. Contributions do not include additions to the +Program which: (i) are separate modules of software distributed in +conjunction with the Program under their own license agreement, and (ii) +are not derivative works of the Program.

+ +

"Contributor" means any person or entity that distributes +the Program.

+ +

"Licensed Patents" mean patent claims licensable by a +Contributor which are necessarily infringed by the use or sale of its +Contribution alone or when combined with the Program.

+ +

"Program" means the Contributions distributed in accordance +with this Agreement.

+ +

"Recipient" means anyone who receives the Program under +this Agreement, including all Contributors.

+ +

2. GRANT OF RIGHTS

+ +

a) Subject to the terms of this Agreement, each +Contributor hereby grants Recipient a non-exclusive, worldwide, +royalty-free copyright license to reproduce, prepare derivative works +of, publicly display, publicly perform, distribute and sublicense the +Contribution of such Contributor, if any, and such derivative works, in +source code and object code form.

+ +

b) Subject to the terms of this Agreement, each +Contributor hereby grants Recipient a non-exclusive, worldwide, +royalty-free patent license under Licensed Patents to make, use, sell, +offer to sell, import and otherwise transfer the Contribution of such +Contributor, if any, in source code and object code form. This patent +license shall apply to the combination of the Contribution and the +Program if, at the time the Contribution is added by the Contributor, +such addition of the Contribution causes such combination to be covered +by the Licensed Patents. The patent license shall not apply to any other +combinations which include the Contribution. No hardware per se is +licensed hereunder.

+ +

c) Recipient understands that although each Contributor +grants the licenses to its Contributions set forth herein, no assurances +are provided by any Contributor that the Program does not infringe the +patent or other intellectual property rights of any other entity. Each +Contributor disclaims any liability to Recipient for claims brought by +any other entity based on infringement of intellectual property rights +or otherwise. As a condition to exercising the rights and licenses +granted hereunder, each Recipient hereby assumes sole responsibility to +secure any other intellectual property rights needed, if any. For +example, if a third party patent license is required to allow Recipient +to distribute the Program, it is Recipient's responsibility to acquire +that license before distributing the Program.

+ +

d) Each Contributor represents that to its knowledge it +has sufficient copyright rights in its Contribution, if any, to grant +the copyright license set forth in this Agreement.

+ +

3. REQUIREMENTS

+ +

A Contributor may choose to distribute the Program in object code +form under its own license agreement, provided that:

+ +

a) it complies with the terms and conditions of this +Agreement; and

+ +

b) its license agreement:

+ +

i) effectively disclaims on behalf of all Contributors +all warranties and conditions, express and implied, including warranties +or conditions of title and non-infringement, and implied warranties or +conditions of merchantability and fitness for a particular purpose;

+ +

ii) effectively excludes on behalf of all Contributors +all liability for damages, including direct, indirect, special, +incidental and consequential damages, such as lost profits;

+ +

iii) states that any provisions which differ from this +Agreement are offered by that Contributor alone and not by any other +party; and

+ +

iv) states that source code for the Program is available +from such Contributor, and informs licensees how to obtain it in a +reasonable manner on or through a medium customarily used for software +exchange.

+ +

When the Program is made available in source code form:

+ +

a) it must be made available under this Agreement; and

+ +

b) a copy of this Agreement must be included with each +copy of the Program.

+ +

Contributors may not remove or alter any copyright notices contained +within the Program.

+ +

Each Contributor must identify itself as the originator of its +Contribution, if any, in a manner that reasonably allows subsequent +Recipients to identify the originator of the Contribution.

+ +

4. COMMERCIAL DISTRIBUTION

+ +

Commercial distributors of software may accept certain +responsibilities with respect to end users, business partners and the +like. While this license is intended to facilitate the commercial use of +the Program, the Contributor who includes the Program in a commercial +product offering should do so in a manner which does not create +potential liability for other Contributors. Therefore, if a Contributor +includes the Program in a commercial product offering, such Contributor +("Commercial Contributor") hereby agrees to defend and +indemnify every other Contributor ("Indemnified Contributor") +against any losses, damages and costs (collectively "Losses") +arising from claims, lawsuits and other legal actions brought by a third +party against the Indemnified Contributor to the extent caused by the +acts or omissions of such Commercial Contributor in connection with its +distribution of the Program in a commercial product offering. The +obligations in this section do not apply to any claims or Losses +relating to any actual or alleged intellectual property infringement. In +order to qualify, an Indemnified Contributor must: a) promptly notify +the Commercial Contributor in writing of such claim, and b) allow the +Commercial Contributor to control, and cooperate with the Commercial +Contributor in, the defense and any related settlement negotiations. The +Indemnified Contributor may participate in any such claim at its own +expense.

+ +

For example, a Contributor might include the Program in a commercial +product offering, Product X. That Contributor is then a Commercial +Contributor. If that Commercial Contributor then makes performance +claims, or offers warranties related to Product X, those performance +claims and warranties are such Commercial Contributor's responsibility +alone. Under this section, the Commercial Contributor would have to +defend claims against the other Contributors related to those +performance claims and warranties, and if a court requires any other +Contributor to pay any damages as a result, the Commercial Contributor +must pay those damages.

+ +

5. NO WARRANTY

+ +

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS +PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS +OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT LIMITATION, +ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, MERCHANTABILITY +OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is solely +responsible for determining the appropriateness of using and +distributing the Program and assumes all risks associated with its +exercise of rights under this Agreement , including but not limited to +the risks and costs of program errors, compliance with applicable laws, +damage to or loss of data, programs or equipment, and unavailability or +interruption of operations.

+ +

6. DISCLAIMER OF LIABILITY

+ +

EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT +NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING +WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF +LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING +NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR +DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED +HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.

+ +

7. GENERAL

+ +

If any provision of this Agreement is invalid or unenforceable under +applicable law, it shall not affect the validity or enforceability of +the remainder of the terms of this Agreement, and without further action +by the parties hereto, such provision shall be reformed to the minimum +extent necessary to make such provision valid and enforceable.

+ +

If Recipient institutes patent litigation against any entity +(including a cross-claim or counterclaim in a lawsuit) alleging that the +Program itself (excluding combinations of the Program with other +software or hardware) infringes such Recipient's patent(s), then such +Recipient's rights granted under Section 2(b) shall terminate as of the +date such litigation is filed.

+ +

All Recipient's rights under this Agreement shall terminate if it +fails to comply with any of the material terms or conditions of this +Agreement and does not cure such failure in a reasonable period of time +after becoming aware of such noncompliance. If all Recipient's rights +under this Agreement terminate, Recipient agrees to cease use and +distribution of the Program as soon as reasonably practicable. However, +Recipient's obligations under this Agreement and any licenses granted by +Recipient relating to the Program shall continue and survive.

+ +

Everyone is permitted to copy and distribute copies of this +Agreement, but in order to avoid inconsistency the Agreement is +copyrighted and may only be modified in the following manner. The +Agreement Steward reserves the right to publish new versions (including +revisions) of this Agreement from time to time. No one other than the +Agreement Steward has the right to modify this Agreement. The Eclipse +Foundation is the initial Agreement Steward. The Eclipse Foundation may +assign the responsibility to serve as the Agreement Steward to a +suitable separate entity. Each new version of the Agreement will be +given a distinguishing version number. The Program (including +Contributions) may always be distributed subject to the version of the +Agreement under which it was received. In addition, after a new version +of the Agreement is published, Contributor may elect to distribute the +Program (including its Contributions) under the new version. Except as +expressly stated in Sections 2(a) and 2(b) above, Recipient receives no +rights or licenses to the intellectual property of any Contributor under +this Agreement, whether expressly, by implication, estoppel or +otherwise. All rights in the Program not expressly granted under this +Agreement are reserved.

+ +

This Agreement is governed by the laws of the State of New York and +the intellectual property laws of the United States of America. No party +to this Agreement will bring a legal action under this Agreement more +than one year after the cause of action arose. Each party waives its +rights to a jury trial in any resulting litigation.

+ + + + \ No newline at end of file diff --git a/NOTICE b/NOTICE new file mode 100644 index 0000000..826ae80 --- /dev/null +++ b/NOTICE @@ -0,0 +1,3 @@ +Copyright (c) 2013 Samsung Electronics Co., Ltd. All rights reserved. +Except as noted, this software is licensed under Apache License, Version 2. +Please, see the LICENSE.EPL file for Apache License terms and conditions. \ No newline at end of file diff --git a/builder/build.properties.clean b/builder/build.properties.clean new file mode 100644 index 0000000..6f4998e --- /dev/null +++ b/builder/build.properties.clean @@ -0,0 +1,259 @@ +############################################################################### +# Copyright (c) 2003, 2006 IBM Corporation and others. +# 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: +# IBM Corporation - initial API and implementation +############################################################################### +##################### +# Parameters describing how and where to execute the build. +# Typical users need only update the following properties: +# baseLocation - where things you are building against are installed +# bootclasspath - The base jars to compile against (typicaly rt.jar) +# configs - the list of {os, ws, arch} configurations to build. +# +# Of course any of the settings here can be overridden by spec'ing +# them on the command line (e.g., -DbaseLocation=d:/eclipse + +#The type of the top level element we are building, generally "feature" +topLevelElementType=feature +#The id of the top level element we are building +topLevelElementId=org.tizen.codecoverage.feature + +############# PRODUCT/PACKAGING CONTROL ############# +#runPackager=true + +#Set the name of the archive that will result from the product build. +#archiveNamePrefix= + +# The prefix that will be used in the generated archive. +archivePrefix=codecoverage + +# The location underwhich all of the build output will be collected. +collectingFolder=${archivePrefix} + +# The list of {os, ws, arch} configurations to build. This +# value is a '&' separated list of ',' separate triples. For example, +# configs=win32,win32,x86 & linux,motif,x86 +# By default the value is *,*,* +configs="Do not touch here." +#configs=win32, win32, x86 & \ +# win32,win32,x86_64 & \ +# win32,win32,wpf & \ +# linux, gtk, ppc & \ +# linux, gtk, x86 & \ +# linux, gtk, x86_64 & \ +# linux, motif, x86 & \ +# solaris, motif, sparc & \ +# solaris, gtk, sparc & \ +# aix, motif, ppc & \ +# hpux, motif, ia64_32 & \ +# macosx, carbon, ppc & \ +# macosx, carbon, x86 & \ +# macosx, cocoa, ppc & \ +# macosx, cocoa, x86 & \ +# macosx, cocoa, x86_64 + +# By default PDE creates one archive (result) per entry listed in the configs property. +# Setting this value to true will cause PDE to only create one output containing all +# artifacts for all the platforms listed in the configs property. +# To control the output format for the group, add a "group, group, group - " entry to the +# archivesFormat. +#groupConfigurations=true + +#The format of the archive. By default a zip is created using antZip. +#The list can only contain the configuration for which the desired format is different than zip. +#archivesFormat=win32, win32, x86 - antZip& \ +# linux, gtk, ppc - antZip &\ +# linux, gtk, x86 - antZip& \ +# linux, gtk, x86_64 - antZip& \ +# linux, motif, x86 - antZip& \ +# solaris, motif, sparc - antZip& \ +# solaris, gtk, sparc - antZip& \ +# aix, motif, ppc - antZip& \ +# hpux, motif, PA_RISC - antZip& \ +# macosx, carbon, ppc - antZip + +#Allow cycles involving at most one bundle that needs to be compiled with the rest being binary bundles. +allowBinaryCycles=true + +#Sort bundles depenedencies across all features instead of just within a given feature. +#flattenDependencies = true + +#Parallel compilation, requires flattenedDependencies=true +#parallelCompilation=true +#parallelThreadCount= +#parallelThreadsPerProcessor= + +#Set to true if you want the output to be ready for an update jar (no site.xml generated) +#outputUpdateJars = false + +#Set to true for Jnlp generation +#codebase should be a URL that will be used as the root of all relative URLs in the output. +#generateJnlp=false +#jnlp.codebase= +#jnlp.j2se= +#jnlp.locale= +#jnlp.generateOfflineAllowed=true or false generate attribute in the generated features +#jnlp.configs=${configs} #uncomment to filter the content of the generated jnlp files based on the configuration being built + +#Set to true if you want to sign jars +#signJars=false +#sign.alias= +#sign.keystore= +#sign.storepass= +#sign.keypass= + +#Arguments to send to the zip executable +#zipargs= + +#Arguments to send to the tar executable +#tarargs= + +#Control the creation of a file containing the version included in each configuration - on by default +#generateVersionsLists=false + +############## BUILD NAMING CONTROL ################ +# The directory into which the build elements are fetched and where +# the build takes place. +buildDirectory="Do not touch here" + +# Type of build. Used in naming the build output. Typically this value is +# one of I, N, M, S, ... +buildType="Do not touch here" + +# ID of the build. Used in naming the build output. +buildId="Do not touch here" + +# Label for the build. Used in naming the build output +buildLabel=${buildType}.${buildId} + +# Timestamp for the build. Used in naming the build output +timestamp=007 + +#The value to be used for the qualifier of a plugin or feature when you want to override the value computed by pde. +#The value will only be applied to plugin or features indicating build.properties, qualifier = context +#forceContextQualifier= + +#Enable / disable the generation of a suffix for the features that use .qualifier. +#The generated suffix is computed according to the content of the feature +#generateFeatureVersionSuffix=true + +############# BASE CONTROL ############# +# Settings for the base Eclipse components and Java class libraries +# against which you are building. +# Base location for anything the build needs to compile against. For example, +# in most RCP app or a plug-in, the baseLocation should be the location of a previously +# installed Eclipse against which the application or plug-in code will be compiled and the RCP delta pack. + +base="Do not touch here" +baseLocation="Do not touch here" + + +#Folder containing repositories whose content is needed to compile against +#repoBaseLocation=${base}/repos +#Folder where the content of the repositories from ${repoBaseLocation} will be made available as a form suitable to be compiled against +#transformedRepoLocation=${base}/transformedRepos + +#Os/Ws/Arch/nl of the eclipse specified by baseLocation +baseos=linux +basews=gtk +basearch=x86 + +#this property indicates whether you want the set of plug-ins and features to be considered during the build to be limited to the ones reachable from the features / plugins being built +filteredDependencyCheck=false + +#this property indicates whether the resolution should be done in development mode (i.e. ignore multiple bundles with singletons) +resolution.devMode=false + +#pluginPath is a list of locations in which to find plugins and features. This list is separated by the platform file separator (; or :) +#a location is one of: +#- the location of the jar or folder that is the plugin or feature : /path/to/foo.jar or /path/to/foo +#- a directory that contains a /plugins or /features subdirectory +#- the location of a feature.xml, or for 2.1 style plugins, the plugin.xml or fragment.xml +#pluginPath= + +skipBase=true +eclipseURL= +eclipseBuildId= +eclipseBaseURL=${eclipseURL}/eclipse-platform-${eclipseBuildId}-win32.zip + + +############# MAP FILE CONTROL ################ +# This section defines CVS tags to use when fetching the map files from the repository. +# If you want to fetch the map file from repository / location, change the getMapFiles target in the customTargets.xml + +skipMaps=true +mapsRepo=:pserver:anonymous@example.com/path/to/repo +mapsRoot=path/to/maps +mapsCheckoutTag=HEAD + +#tagMaps=true +mapsTagTag=v${buildId} + + +############ REPOSITORY CONTROL ############### +# This section defines properties parameterizing the repositories where plugins, fragments +# bundles and features are being obtained from. + +# The tags to use when fetching elements to build. +# By default thebuilder will use whatever is in the maps. +# This value takes the form of a comma separated list of repository identifier (like used in the map files) and the +# overriding value +# For example fetchTag=CVS=HEAD, SVN=v20050101 +# fetchTag=HEAD +skipFetch=true + + +############# P2 OPTIONS ############## +#p2.gathering = true +#p2.compress=true + +############# JAVA COMPILER OPTIONS ############## +# The location of the Java jars to compile against. Typically the rt.jar for your JDK/JRE +#bootclasspath=${java.home}/lib/rt.jar + +# specific JRE locations to compile against. These values are used to compile bundles specifying a +# Bundle-RequiredExecutionEnvironment. Uncomment and set values for environments that you support +#CDC-1.0/Foundation-1.0= /path/to/rt.jar +#CDC-1.1/Foundation-1.1= +#OSGi/Minimum-1.0= +#OSGi/Minimum-1.1= +#JRE-1.1= +#J2SE-1.2= +#J2SE-1.3= +#J2SE-1.4= +#J2SE-1.5= +#JavaSE-1.6= +#PersonalJava-1.1= +#PersonalJava-1.2= +#CDC-1.0/PersonalBasis-1.0= +#CDC-1.0/PersonalJava-1.0= +#CDC-1.1/PersonalBasis-1.1= +#CDC-1.1/PersonalJava-1.1= + +# Specify the output format of the compiler log when eclipse jdt is used +logExtension=.log + +# Whether or not to include debug info in the output jars +javacDebugInfo=false + +# Whether or not to fail the build if there are compiler errors +javacFailOnError=true + +# Enable or disable verbose mode of the compiler +javacVerbose=true + +# Extra arguments for the compiler. These are specific to the java compiler being used. +#compilerArg= + +# Default value for the version of the source code. This value is used when compiling plug-ins that do not set the Bundle-RequiredExecutionEnvironment or set javacSource in build.properties +javacSource=1.6 + +# Default value for the version of the byte code targeted. This value is used when compiling plug-ins that do not set the Bundle-RequiredExecutionEnvironment or set javacTarget in build.properties. +javacTarget=1.6 + + diff --git a/builder/customTargets.xml b/builder/customTargets.xml new file mode 100644 index 0000000..6a42e92 --- /dev/null +++ b/builder/customTargets.xml @@ -0,0 +1,187 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.linuxtools.binutils/.classpath b/org.eclipse.linuxtools.binutils/.classpath new file mode 100644 index 0000000..1ca8caa --- /dev/null +++ b/org.eclipse.linuxtools.binutils/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.linuxtools.binutils/.project b/org.eclipse.linuxtools.binutils/.project new file mode 100644 index 0000000..1a43e12 --- /dev/null +++ b/org.eclipse.linuxtools.binutils/.project @@ -0,0 +1,28 @@ + + + org.eclipse.linuxtools.binutils + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.linuxtools.binutils/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.linuxtools.binutils/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..d8d8799 --- /dev/null +++ b/org.eclipse.linuxtools.binutils/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,7 @@ +#Thu Jan 15 16:35:12 CET 2009 +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.problem.assertIdentifier=error +org.eclipse.jdt.core.compiler.problem.enumIdentifier=error +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/org.eclipse.linuxtools.binutils/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.binutils/META-INF/MANIFEST.MF new file mode 100644 index 0000000..26fbc39 --- /dev/null +++ b/org.eclipse.linuxtools.binutils/META-INF/MANIFEST.MF @@ -0,0 +1,23 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %bundleName +Bundle-SymbolicName: org.eclipse.linuxtools.binutils;singleton:=true +Bundle-Version: 4.0.0.qualifier +Bundle-Activator: org.eclipse.linuxtools.binutils.Activator +Bundle-Vendor: %bundleProvider +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.core.filesystem, + org.eclipse.debug.ui, + org.eclipse.ui.ide, + org.eclipse.cdt.core, + org.eclipse.cdt.debug.core, + org.eclipse.cdt.ui, + org.eclipse.jface.text, + org.eclipse.ui.workbench.texteditor +Bundle-ActivationPolicy: lazy +Export-Package: org.eclipse.linuxtools.binutils, + org.eclipse.linuxtools.binutils.link2source, + org.eclipse.linuxtools.binutils.utils +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-Localization: plugin diff --git a/org.eclipse.linuxtools.binutils/about.html b/org.eclipse.linuxtools.binutils/about.html new file mode 100644 index 0000000..23506a4 --- /dev/null +++ b/org.eclipse.linuxtools.binutils/about.html @@ -0,0 +1,26 @@ + + + + + +About + +

About This Content

+ +

June 5, 2006

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + \ No newline at end of file diff --git a/org.eclipse.linuxtools.binutils/build.properties b/org.eclipse.linuxtools.binutils/build.properties new file mode 100644 index 0000000..75e3b73 --- /dev/null +++ b/org.eclipse.linuxtools.binutils/build.properties @@ -0,0 +1,16 @@ +source.. = src/ +output.. = bin/ +bin.includes = META-INF/,\ + .,\ + plugin.xml,\ + icons/,\ + about.html,\ + plugin.properties +src.includes = src/,\ + plugin.xml,\ + icons/,\ + build.properties,\ + bin/,\ + META-INF/,\ + .project,\ + .classpath diff --git a/org.eclipse.linuxtools.binutils/icons/c_file_obj.gif b/org.eclipse.linuxtools.binutils/icons/c_file_obj.gif new file mode 100644 index 0000000..bd603cf Binary files /dev/null and b/org.eclipse.linuxtools.binutils/icons/c_file_obj.gif differ diff --git a/org.eclipse.linuxtools.binutils/plugin.properties b/org.eclipse.linuxtools.binutils/plugin.properties new file mode 100644 index 0000000..8115a91 --- /dev/null +++ b/org.eclipse.linuxtools.binutils/plugin.properties @@ -0,0 +1,13 @@ +#****************************************************************************** +# Copyright (c) 2009 STMicroelectronics. +# 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: +# Xavier Raynaud - initial API and implementation +#******************************************************************************* +bundleProvider = Eclipse Linux Tools +bundleName = Binutils Plug-in (Incubation) +sourceNotFoundEditorName = Source Not Found \ No newline at end of file diff --git a/org.eclipse.linuxtools.binutils/plugin.xml b/org.eclipse.linuxtools.binutils/plugin.xml new file mode 100644 index 0000000..6d92b16 --- /dev/null +++ b/org.eclipse.linuxtools.binutils/plugin.xml @@ -0,0 +1,15 @@ + + + + + + + + + + diff --git a/org.eclipse.linuxtools.binutils/schema/org.eclipse.linuxtools.binutils.crossCompile.exsd b/org.eclipse.linuxtools.binutils/schema/org.eclipse.linuxtools.binutils.crossCompile.exsd new file mode 100644 index 0000000..6489e99 --- /dev/null +++ b/org.eclipse.linuxtools.binutils/schema/org.eclipse.linuxtools.binutils.crossCompile.exsd @@ -0,0 +1,109 @@ + + + + + + + + + [Enter description of this extension point.] + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + [Enter the first release in which this extension point appears.] + + + + + + + + + [Enter extension point usage example here.] + + + + + + + + + [Enter API information here.] + + + + + + + + + [Enter information about supplied implementation of this extension point.] + + + + + diff --git a/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/Activator.java b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/Activator.java new file mode 100644 index 0000000..04c8eec --- /dev/null +++ b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/Activator.java @@ -0,0 +1,60 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Xavier Raynaud - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.binutils; + +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + /** The plug-in ID */ + public static final String PLUGIN_ID = "org.eclipse.linuxtools.binutils"; + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + +} diff --git a/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/link2source/STCSourceNotFoundEditor.java b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/link2source/STCSourceNotFoundEditor.java new file mode 100644 index 0000000..89770a4 --- /dev/null +++ b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/link2source/STCSourceNotFoundEditor.java @@ -0,0 +1,232 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Xavier Raynaud - initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.binutils.link2source; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Iterator; + +import org.eclipse.cdt.debug.core.CDebugCorePlugin; +import org.eclipse.cdt.debug.core.sourcelookup.MappingSourceContainer; +import org.eclipse.cdt.debug.internal.core.sourcelookup.MapEntrySourceContainer; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector; +import org.eclipse.debug.core.sourcelookup.ISourceContainer; +import org.eclipse.debug.ui.sourcelookup.CommonSourceNotFoundEditor; +import org.eclipse.jface.preference.PreferenceDialog; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.ui.IEditorInput; + +/** + * Editor that lets you select a replacement for the missing source file + * and modifies the source locator accordingly. + * + */ +public class STCSourceNotFoundEditor extends CommonSourceNotFoundEditor { + + private final static String foundMappingsContainerName = "Found Mappings"; //$NON-NLS-1$ + + + private Button locateFileButton; + private Button editLookupButton; + + /** Constructor */ + public STCSourceNotFoundEditor() { + } + + public void createPartControl(Composite parent) { + super.createPartControl(parent); + } + + private IPath getMissingFile() { + IEditorInput i = this.getEditorInput(); + if (i instanceof STCSourceNotFoundEditorInput) { + STCSourceNotFoundEditorInput input = (STCSourceNotFoundEditorInput) i; + return input.getSourcePath(); + } + return null; + } + + private int getLineNumber() { + IEditorInput i = this.getEditorInput(); + if (i instanceof STCSourceNotFoundEditorInput) { + STCSourceNotFoundEditorInput input = (STCSourceNotFoundEditorInput) i; + return input.getLineNumber(); + } + return -1; + } + + private IProject getProject() { + IEditorInput i = this.getEditorInput(); + if (i instanceof STCSourceNotFoundEditorInput) { + STCSourceNotFoundEditorInput input = (STCSourceNotFoundEditorInput) i; + return input.getProject(); + } + return null; + } + + public void setInput(IEditorInput input) { + super.setInput(input); + syncButtons(); + } + + private boolean isValidMissingFile() { + IPath p = getMissingFile(); + boolean v = (p != null && p.toString().length() > 0); + return v; + } + + + private void syncButtons() { + boolean v = isValidMissingFile(); + if (locateFileButton != null) + locateFileButton.setVisible(v); + if (editLookupButton != null) + editLookupButton.setVisible(v); + } + + protected String getText() { + boolean v = isValidMissingFile(); + if (v) { + return "Can't find a source file at \"" + + getMissingFile() + + "\" \n"; + } else { + return "No source available for \"\""; + } + } + + protected void createButtons(Composite parent) { + { + GridData data; + locateFileButton = new Button(parent, SWT.PUSH); + data = new GridData(); + data.grabExcessHorizontalSpace = false; + data.grabExcessVerticalSpace = false; + locateFileButton.setLayoutData(data); + locateFileButton.setText("Locate File..."); //$NON-NLS-1$ + locateFileButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent evt) { + locateFile(); + } + }); + } + + { + GridData data; + editLookupButton = new Button(parent, SWT.PUSH); + data = new GridData(); + data.grabExcessHorizontalSpace = false; + data.grabExcessVerticalSpace = false; + editLookupButton.setLayoutData(data); + editLookupButton.setText("Edit Source Lookup Path..."); + editLookupButton.addSelectionListener(new SelectionAdapter() { + public void widgetSelected(SelectionEvent evt) { + editSourceLookupPath(); + } + }); + } + syncButtons(); + } + + + /* (non-Javadoc) + * @see org.eclipse.debug.ui.sourcelookup.CommonSourceNotFoundEditor#editSourceLookupPath() + */ + @Override + protected void editSourceLookupPath() { + PreferenceDialog d = org.eclipse.ui.dialogs.PreferencesUtil.createPreferenceDialogOn(null, "org.eclipse.cdt.debug.ui.SourcePreferencePage", null, null); + if (d.open() == PreferenceDialog.OK) { + closeEditor(); + openSourceFileAtLocation(getProject(), getMissingFile(), getLineNumber()); + } + } + + private void addSourceMappingToDirector(IPath missingPath, IPath newSourcePath, AbstractSourceLookupDirector director) throws CoreException { + + ArrayList containerList = new ArrayList(Arrays.asList( + director.getSourceContainers() + )); + boolean hasFoundMappings = false; + MappingSourceContainer foundMappings = null; + for (Iterator iter = containerList.iterator(); iter.hasNext() && !hasFoundMappings;) { + ISourceContainer container = iter.next(); + if (container instanceof MappingSourceContainer) + { + hasFoundMappings = container.getName().equals(foundMappingsContainerName); + if (hasFoundMappings) + foundMappings = (MappingSourceContainer) container; + } + } + + if (!hasFoundMappings) { + foundMappings = new MappingSourceContainer(foundMappingsContainerName); + foundMappings.init(director); + containerList.add(foundMappings); + } + + foundMappings.addMapEntry(new MapEntrySourceContainer(missingPath, newSourcePath)); + director.setSourceContainers(containerList.toArray(new ISourceContainer[containerList.size()])); + } + + private void addSourceMappingToCommon(IPath missingPath, IPath newSourcePath) throws CoreException { + AbstractSourceLookupDirector director = CDebugCorePlugin.getDefault().getCommonSourceLookupDirector(); + addSourceMappingToDirector(missingPath, newSourcePath, director); + CDebugCorePlugin.getDefault().savePluginPreferences(); + } + + protected void locateFile() { + FileDialog dialog = new FileDialog(getEditorSite().getShell(), SWT.NONE); + IPath missingPath = getMissingFile(); + dialog.setFilterNames(new String[] {"Missing Source File"}); + dialog.setFilterExtensions(new String[] {"*." + missingPath.getFileExtension()}); //$NON-NLS-1$ + String res = dialog.open(); + if (res != null) { + Path newPath = new Path(res); + + if (newPath.lastSegment().equalsIgnoreCase(missingPath.lastSegment())) { + + if (missingPath.segmentCount() > 1) { + int missingPathSegCount = missingPath.segmentCount() - 2; + int newPathSegCount = newPath.segmentCount() - 2; + while (missingPathSegCount >= 0 && newPathSegCount >= 0) { + if (!newPath.segment(newPathSegCount).equalsIgnoreCase(missingPath.segment(missingPathSegCount))) + break; + newPathSegCount--; + missingPathSegCount--; + } + IPath compPath = missingPath.removeLastSegments(missingPath.segmentCount() - missingPathSegCount - 1); + IPath newSourcePath = newPath.removeLastSegments(newPath.segmentCount() - newPathSegCount - 1); + try { + addSourceMappingToCommon(compPath, newSourcePath); + } catch (CoreException e) {} + + } + openSourceFileAtLocation(getProject(), newPath, getLineNumber()); + closeEditor(); + } + } + } + + protected void openSourceFileAtLocation(IProject project, IPath sourceLoc, int lineNumber){ + STLink2SourceSupport.sharedInstance.openSourceFileAtLocation(project, sourceLoc, lineNumber); + } +} diff --git a/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/link2source/STCSourceNotFoundEditorInput.java b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/link2source/STCSourceNotFoundEditorInput.java new file mode 100644 index 0000000..38e76b8 --- /dev/null +++ b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/link2source/STCSourceNotFoundEditorInput.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Xavier Raynaud - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.binutils.link2source; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.linuxtools.binutils.Activator; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IPersistableElement; + + +/** + * Editor Input used for source not found + * + * @author Xavier Raynaud + */ +public class STCSourceNotFoundEditorInput implements IEditorInput { + + private final IProject project; + private final IPath sourcePath; + private final int lineNumber; + + + /** + * Constructor + * @param binaryPath + * @param sourcePath + * @param lineNumber + */ + public STCSourceNotFoundEditorInput(IProject project, IPath sourcePath, + int lineNumber) { + this.project = project; + this.sourcePath = sourcePath; + this.lineNumber = lineNumber; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#exists() + */ + public boolean exists() { + return false; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#getImageDescriptor() + */ + public ImageDescriptor getImageDescriptor() { + return Activator.imageDescriptorFromPlugin(Activator.PLUGIN_ID, "icons/c_file_obj.gif"); + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#getName() + */ + public String getName() { + return sourcePath.lastSegment() + ":" + lineNumber; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#getPersistable() + */ + public IPersistableElement getPersistable() { + return null; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.IEditorInput#getToolTipText() + */ + public String getToolTipText() { + return "Source not found"; + } + + /* + * (non-Javadoc) + * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class) + */ + @SuppressWarnings("unchecked") + public Object getAdapter(Class adapter) { + return null; + } + + /** + * @return the project + */ + public IProject getProject() { + return project; + } + + /** + * @return the sourcePath + */ + public IPath getSourcePath() { + return sourcePath; + } + + /** + * @return the lineNumber + */ + public int getLineNumber() { + return lineNumber; + } + + + /* (non-Javadoc) + * @see java.lang.Object#hashCode() + */ + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((project == null) ? 0 : project.hashCode()); + result = prime * result + + ((sourcePath == null) ? 0 : sourcePath.hashCode()); + return result; + } + + /* (non-Javadoc) + * @see java.lang.Object#equals(java.lang.Object) + */ + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + final STCSourceNotFoundEditorInput other = (STCSourceNotFoundEditorInput) obj; + if (project == null) { + if (other.project != null) + return false; + } else if (!project.equals(other.project)) + return false; + if (sourcePath == null) { + if (other.sourcePath != null) + return false; + } else if (!sourcePath.equals(other.sourcePath)) + return false; + return true; + } + +} diff --git a/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/link2source/STLink2SourceSupport.java b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/link2source/STLink2SourceSupport.java new file mode 100644 index 0000000..d11e957 --- /dev/null +++ b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/link2source/STLink2SourceSupport.java @@ -0,0 +1,557 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Xavier Raynaud - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.binutils.link2source; + +import java.io.File; +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + +import org.eclipse.cdt.core.IAddress; +import org.eclipse.cdt.core.IAddressFactory; +import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; +import org.eclipse.cdt.core.IBinaryParser.ISymbol; +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.model.IOutputEntry; +import org.eclipse.cdt.core.model.ISourceRoot; +import org.eclipse.cdt.debug.core.CDebugCorePlugin; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.utils.Addr64; +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.core.resources.IContainer; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.debug.core.sourcelookup.AbstractSourceLookupDirector; +import org.eclipse.debug.core.sourcelookup.ISourceContainer; +import org.eclipse.debug.core.sourcelookup.containers.LocalFileStorage; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.linuxtools.binutils.Activator; +import org.eclipse.linuxtools.binutils.utils.STSymbolManager; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.ide.FileStoreEditorInput; +import org.eclipse.ui.part.FileEditorInput; +import org.eclipse.ui.texteditor.IDocumentProvider; +import org.eclipse.ui.texteditor.ITextEditor; + + +/** + * This class provides a support for link-to-source + * + * @author Xavier Raynaud + */ +public class STLink2SourceSupport { + + /** Shared instance of this class + * Note: perhaps it's better to put all methods static ? + */ + public static final STLink2SourceSupport sharedInstance = new STLink2SourceSupport(); + + protected STLink2SourceSupport() { + } + + /** + * Open a C Editor at the location of the given symbol + * @param symbol + * @return true if the link-to-source was successful, false otherwise + */ + public boolean openSourceFileAtSymbol(ISymbol symbol) { + if (symbol == null) return false; + return openSourceFileAtSymbol(symbol.getBinaryObject(), symbol); + } + + /** + * Open a C Editor at the given location + * @param binaryLoc a path to a binary file + * @param addr2lineOutput a location, as returned by addr2line (/path/to/file:linenumber) + * @return true if the link-to-source was successful, false otherwise + * @throws IOException + */ + public boolean openSourceFileAtLocation(String binaryLoc, String addr2lineOutput) throws IOException { + if (binaryLoc == null) return false; + return openSourceFileAtLocation(new Path(binaryLoc), addr2lineOutput); + } + + /** + * Open a C Editor at the given location + * @param binaryLoc a path to a binary file + * @param sourceLoc the location of the source file + * @param lineNumber + * @return true if the link-to-source was successful, false otherwise + * @throws IOException + */ + public boolean openSourceFileAtLocation(String binaryLoc, String sourceLoc, String lineNumber) throws IOException { + if (binaryLoc == null) return false; + return openSourceFileAtLocation(new Path(binaryLoc), sourceLoc, lineNumber); + } + + /** + * Open a C Editor at the given location + * @param binaryLoc a path to a binary file + * @param sourceLoc the location of the source file + * @param lineNumber + * @return true if the link-to-source was successful, false otherwise + * @throws IOException + */ + public boolean openSourceFileAtLocation(String binaryLoc, String sourceLoc, int lineNumber) throws IOException { + if (binaryLoc == null) return false; + return openSourceFileAtLocation(new Path(binaryLoc), sourceLoc, lineNumber); + } + + /** + * Open a C Editor at the given address + * @param binaryLoc a path to a binary file + * @param address + * @return true if the link-to-source was successful, false otherwise + * @throws IOException + */ + public boolean openSourceFileAtAddress(String binaryLoc, long address) throws IOException { + if (binaryLoc == null) return false; + return openSourceFileAtAddress(new Path(binaryLoc), address); + } + + /** + * Open a C Editor at the given address + * @param binaryLoc a path to a binary file + * @param address + * @return true if the link-to-source was successful, false otherwise + * @throws IOException + */ + public boolean openSourceFileAtAddress(String binaryLoc, String address) throws IOException { + if (binaryLoc == null) return false; + return openSourceFileAtAddress(new Path(binaryLoc), address); + + } + + + + + + /** + * Open a C Editor at the given location + * @param binaryLoc a path to a binary file + * @param addr2lineOutput a location, as returned by addr2line (/path/to/file:linenumber) + * @return true if the link-to-source was successful, false otherwise + * @throws IOException + */ + public boolean openSourceFileAtLocation(IPath binaryLoc, String addr2lineOutput) throws IOException { + String filename = getFileName(addr2lineOutput); + int lineNumber = getLineNumber(addr2lineOutput); + return openSourceFileAtLocation(binaryLoc, filename, lineNumber); + + } + + /** + * Open a C Editor at the given location + * @param binaryLoc a path to a binary file + * @param sourceLoc the location of the source file + * @param lineNumber + * @return true if the link-to-source was successful, false otherwise + * @throws IOException + */ + public boolean openSourceFileAtLocation(IPath binaryLoc, String sourceLoc, String lineNumber) throws IOException { + int _lineNumber = -1; + try { + _lineNumber = Integer.parseInt(lineNumber); + } catch (Exception _) { + } + return openSourceFileAtLocation(binaryLoc, sourceLoc, _lineNumber); + } + + /** + * Open a C Editor at the given location + * @param binaryLoc a path to a binary file + * @param sourceLoc the location of the source file + * @param lineNumber + * @return true if the link-to-source was successful, false otherwise + * @throws IOException + */ + public boolean openSourceFileAtLocation(IPath binaryLoc, String sourceLoc, int lineNumber) throws IOException { + if (sourceLoc == null) return false; + IPath p = new Path(sourceLoc); + return openSourceFileAtLocation(binaryLoc, p, lineNumber); + } + + /** + * Open a C Editor at the given location + * @param binaryLoc a path to a binary file + * @param sourceLoc the location of the source file + * @param lineNumber + * @return true if the link-to-source was successful, false otherwise + * @throws IOException + */ + public boolean openSourceFileAtLocation(IPath binaryLoc, IPath sourceLoc, int lineNumber) { + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + IFile binary = root.getFileForLocation(binaryLoc); + IProject project = null; + if (binary != null) project = binary.getProject(); + return openFileImpl(project, sourceLoc, lineNumber); + } + + /** + * Open a C Editor at the given location + * @param project the parent project + * @param sourceLoc the location of the source file + * @param lineNumber + * @return true if the link-to-source was successful, false otherwise + * @throws IOException + */ + public boolean openSourceFileAtLocation(IProject project, String sourceLoc, int lineNumber) throws IOException { + if (sourceLoc == null) return false; + IPath p = new Path(sourceLoc); + return openFileImpl(project, p, lineNumber); + } + + /** + * Open a C Editor at the given location + * @param project the parent project + * @param sourceLoc the location of the source file + * @param lineNumber + * @return true if the link-to-source was successful, false otherwise + * @throws IOException + */ + public boolean openSourceFileAtLocation(IProject project, IPath sourceLoc, int lineNumber) { + return openFileImpl(project, sourceLoc, lineNumber); + } + + /** + * Open a C Editor at the given address + * @param binaryLoc a path to a binary file + * @param address + * @return true if the link-to-source was successful, false otherwise + * @throws IOException + */ + public boolean openSourceFileAtAddress(IPath binaryLoc, long address) throws IOException { + IBinaryObject bf = STSymbolManager.sharedInstance.getBinaryObject(binaryLoc); + if (bf != null) { + return openSourceFileAtAddress(bf, address); + } + return false; + } + + /** + * Open a C Editor at the given address + * @param binaryLoc a path to a binary file + * @param address + * @return true if the link-to-source was successful, false otherwise + * @throws IOException + */ + public boolean openSourceFileAtAddress(IPath binaryLoc, String address) throws IOException { + IBinaryObject bf = STSymbolManager.sharedInstance.getBinaryObject(binaryLoc); + if (bf != null) { + return openSourceFileAtAddress(bf, address); + } + return false; + } + + + + + + /* + * Method inspired from org.eclipse.cdt.utils.Addr2line.getFileName(IAddress) + */ + private String getFileName(String loc) { + String filename = null; + int index1, index2; + if (loc != null && (index1 = loc.lastIndexOf(':')) != -1) { + // we do this because addr2line on win produces + // + index2 = loc.indexOf(':'); + if (index1 == index2) { + index2 = 0; + } else { + index2--; + } + filename = loc.substring(index2, index1); + } + return filename; + } + + + /* + * Method inspired from org.eclipse.cdt.utils.Addr2line.getFileName(IAddress) + */ + private int getLineNumber(String loc) { + if (loc != null) { + int colon = loc.lastIndexOf(':'); + String number = loc.substring(colon + 1); + if (!number.startsWith("0")) { //$NON-NLS-1$ + try { + return Integer.parseInt(number); + } catch(Exception ex) { + return -1; + } + } + } + return -1; + } + + + /** + * Opens a C Editor pointing to the given symbol + * @param binary + * @param symbol + * @return true if the link-to-source was successful, false otherwise + */ + public boolean openSourceFileAtSymbol(IBinaryObject binary, ISymbol symbol) { + if (symbol == null) return false; + String loc = STSymbolManager.sharedInstance.getLine(symbol); + return openSourceFileAtLocation(binary, loc); + } + + /** + * Opens a C Editor pointing to the given location + * @param binary + * @param addr2lineOutput a location, as returned by addr2line (/path/to/file:linenumber) + * @return true if the link-to-source was successful, false otherwise + */ + public boolean openSourceFileAtLocation(IBinaryObject binary, String addr2lineOutput) { + String filename = getFileName(addr2lineOutput); + int lineNumber = getLineNumber(addr2lineOutput); + return openSourceFileAtLocation(binary, filename, lineNumber); + } + + /** + * Open a C Editor at the given location + * @param binary a binary file + * @param sourceLoc the location of the source file + * @param lineNumber + * @return true if the link-to-source was successful, false otherwise + */ + public boolean openSourceFileAtLocation(IBinaryObject binary, String sourceLoc, String lineNumber) { + int i = -1; + try { + i = Integer.parseInt(lineNumber); + } catch (Exception _) { + } + return openSourceFileAtLocation(binary, sourceLoc, i); + } + + /** + * Open a C Editor at the given location + * @param binary a binary file + * @param sourceLoc the location of the source file + * @param lineNumber + * @return true if the link-to-source was successful, false otherwise + */ + public boolean openSourceFileAtLocation(IBinaryObject binary, String sourceLoc, int lineNumber) { + if (sourceLoc == null) return false; + IPath p = new Path(sourceLoc); + return openSourceFileAtLocation(binary.getPath(), p, lineNumber); + } + + /** + * Open a C Editor at the given address + * @param binary a binary file + * @param address + * @return true if the link-to-source was successful, false otherwise + */ + public boolean openSourceFileAtAddress(IBinaryObject binary, IAddress address) { + if (binary == null) return false; + String loc = STSymbolManager.sharedInstance.getLine(binary, address); + return openSourceFileAtLocation(binary, loc); + } + + /** + * Open a C Editor at the given address + * @param binary a binary file + * @param address + * @return true if the link-to-source was successful, false otherwise + */ + public boolean openSourceFileAtAddress(IBinaryObject binary, long address) { + String addr = Long.toString(address); + return openSourceFileAtAddress(binary, addr); + } + + /** + * Open a C Editor at the given address + * @param binary a binary file + * @param address + * @return true if the link-to-source was successful, false otherwise + */ + public boolean openSourceFileAtAddress(IBinaryObject binary, String address) { + if (binary == null) return false; + IAddressFactory factory = binary.getAddressFactory(); + IAddress addr; + if (factory == null) { + addr = new Addr64(address); + } else { + addr = factory.createAddress(address); + } + return openSourceFileAtAddress(binary, addr); + } + + private boolean openFileImpl(IProject project, IPath sourceLoc, int lineNumber) { + if (sourceLoc == null || "??".equals(sourceLoc.toString())) return false; + try { + IEditorInput editorInput = getEditorInput(sourceLoc, project); + IWorkbenchPage p= CUIPlugin.getActivePage(); + if (p != null) { + if (editorInput == null) { + p.openEditor( + new STCSourceNotFoundEditorInput(project, sourceLoc, lineNumber), + "org.eclipse.linuxtools.binutils.link2source.STCSourceNotFoundEditor", + true); + } else { + IEditorPart editor = p.openEditor(editorInput, CUIPlugin.EDITOR_ID, true); + if (lineNumber > 0 && editor instanceof ITextEditor){ + IDocumentProvider provider= ((ITextEditor)editor).getDocumentProvider(); + IDocument document= provider.getDocument(editor.getEditorInput()); + try { + int start = document.getLineOffset(lineNumber-1); + ((ITextEditor)editor).selectAndReveal(start, 0); + IWorkbenchPage page= editor.getSite().getPage(); + page.activate(editor); + return true; + } catch (BadLocationException x) { + // ignore + } + } + } + } + } + catch (Exception _) { + } + return false; + } + + public IEditorInput getEditorInput(IPath p, IProject project) { + IFile f = getFileForPath(p, project); + if (f != null && f.exists()) { + return new FileEditorInput(f); + } + if (p.isAbsolute()) { + File file = p.toFile(); + if (file.exists()) { + try { + IFileStore ifs = EFS.getStore(file.toURI()); + return new FileStoreEditorInput(ifs); + } catch (CoreException _) { + Activator.getDefault().getLog().log(_.getStatus()); + } + } + } + return findFileInCommonSourceLookup(p); + } + + private IEditorInput findFileInCommonSourceLookup(IPath path) + { + try { + AbstractSourceLookupDirector director = CDebugCorePlugin.getDefault().getCommonSourceLookupDirector(); + ISourceContainer[] c = director.getSourceContainers(); + for (ISourceContainer sourceContainer : c) { + Object[] o = sourceContainer.findSourceElements(path.toOSString()); + for (Object object : o) { + if (object instanceof IFile) { + return new FileEditorInput((IFile)object); + } else if (object instanceof LocalFileStorage) { + LocalFileStorage storage = (LocalFileStorage) object; + IFileStore ifs = EFS.getStore(storage.getFile().toURI()); + return new FileStoreEditorInput(ifs); + } + } + } + } catch (Exception _) { + // do nothing + } + return null; + } + + private IFile getFileForPath(IPath path, IProject project) { + IFile f = getFileForPathImpl(path, project); + if (f == null) { + Set allProjects = new HashSet(); + try { + getAllReferencedProjects(allProjects, project); + } catch (CoreException _) { + Activator.getDefault().getLog().log(_.getStatus()); + } + if (allProjects != null) { + for (IProject project2 : allProjects) { + f = getFileForPathImpl(path, project2); + if (f != null) break; + } + } + } + return f; + } + + + private IFile getFileForPathImpl(IPath path, IProject project) { + IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); + if (path.isAbsolute()) { + IFile c = root.getFileForLocation(path); + return c; + } + if (project != null && project.exists()) { + ICProject cproject = CoreModel.getDefault().create(project); + if (cproject != null) { + try { + ISourceRoot[] roots = cproject.getAllSourceRoots(); + for (ISourceRoot sourceRoot : roots) { + IResource r = sourceRoot.getResource(); + if (r instanceof IContainer) { + IContainer parent = (IContainer) r; + IResource res = parent.findMember(path); + if (res != null && res.exists() && res instanceof IFile) { + IFile file = (IFile) res; + return file; + } + } + } + + IOutputEntry entries[] = cproject.getOutputEntries(); + for (IOutputEntry pathEntry : entries) { + IPath p = pathEntry.getPath(); + IResource r = root.findMember(p); + if (r instanceof IContainer) { + IContainer parent = (IContainer) r; + IResource res = parent.findMember(path); + if (res != null && res.exists() && res instanceof IFile) { + IFile file = (IFile) res; + return file; + } + } + } + + } catch (CModelException _) { + Activator.getDefault().getLog().log(_.getStatus()); + } + } + } + return null; + } + + private void getAllReferencedProjects(Set all, IProject project) throws CoreException { + if (project != null) { + IProject[] refs = project.getReferencedProjects(); + for (int i = 0; i < refs.length; i++) { + if (!all.contains(refs[i]) && refs[i].exists() && refs[i].isOpen()) { + all.add(refs[i]); + getAllReferencedProjects(all, refs[i]); + } + } + } + } + +} diff --git a/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/DefaultBinutilsFactory.java b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/DefaultBinutilsFactory.java new file mode 100644 index 0000000..488ffaf --- /dev/null +++ b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/DefaultBinutilsFactory.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Xavier Raynaud - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.binutils.utils; + +import java.io.IOException; + +import org.eclipse.cdt.utils.Addr2line; +import org.eclipse.cdt.utils.CPPFilt; + +/** + * Default binutils factory + * @author Xavier Raynaud + */ +public class DefaultBinutilsFactory implements ISTBinutilsFactory { + + @Override + public Addr2line getAddr2line(String path) throws IOException { + return new Addr2line(path); + } + + @Override + public CPPFilt getCPPFilt() throws IOException { + return new CPPFilt(); + } + + @Override + public STNM getNM(String path, STNMSymbolsHandler handler) throws IOException { + return new STNM("nm", null, path, handler); + } + + /** + * No availability test for default binutils. + */ + @Override + public boolean testAvailability() { + return true; + } +} diff --git a/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/ISTBinutilsFactory.java b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/ISTBinutilsFactory.java new file mode 100644 index 0000000..c805cd4 --- /dev/null +++ b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/ISTBinutilsFactory.java @@ -0,0 +1,31 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Xavier Raynaud - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.binutils.utils; + +import java.io.IOException; + +import org.eclipse.cdt.utils.Addr2line; +import org.eclipse.cdt.utils.CPPFilt; + +/** + * binutils factory (especially used for cross-compile tools) + * @author Xavier Raynaud + */ +public interface ISTBinutilsFactory { + + Addr2line getAddr2line(String path) throws IOException; + + CPPFilt getCPPFilt() throws IOException; + + STNM getNM(String path, STNMSymbolsHandler handler) throws IOException; + + boolean testAvailability(); +} diff --git a/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STAddr2LineFactory.java b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STAddr2LineFactory.java new file mode 100644 index 0000000..16d8353 --- /dev/null +++ b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STAddr2LineFactory.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Xavier Raynaud - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.binutils.utils; + +import java.io.IOException; + +import org.eclipse.cdt.utils.Addr2line; + + +/** + * addr2line factory for all toolsets. + * + * @author Xavier Raynaud + */ +public class STAddr2LineFactory { + + /** + * @param cpuType + * @param programPath + * @return an instance of addr2line for the given program + * @throws IOException + */ + public static Addr2line getAddr2line(String cpuType, String programPath) throws IOException { + ISTBinutilsFactory factory = STBinutilsFactoryManager.sharedInstance.getBinutilsFactory(cpuType); + return factory.getAddr2line(programPath); + } + +} diff --git a/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STAddr2line.java b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STAddr2line.java new file mode 100644 index 0000000..a72b17f --- /dev/null +++ b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STAddr2line.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Xavier Raynaud - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.binutils.utils; + +import java.io.IOException; + +import org.eclipse.cdt.core.IAddress; +import org.eclipse.cdt.utils.Addr2line; + +/** + * Addr2line implementation, compatible with "hostname:file:linenumber" + * format of addr2line output. + * @author Xavier Raynaud + * + */ +public class STAddr2line extends Addr2line { + + /** + * Constructor + * @param cmd the command to run + * @param file the binary file + * @throws IOException + */ + public STAddr2line(String cmd, String file) throws IOException { + super(cmd, file); + } + + /* (non-Javadoc) + * @see org.eclipse.cdt.utils.Addr2line#getLine(org.eclipse.cdt.core.IAddress) + */ + @Override + public String getLine(IAddress address) throws IOException { + String s = super.getLine(address); + int index1 = s.lastIndexOf(':'); + int index2 = s.indexOf(':'); + if (index1 != index2 && index2 != 2) { + s = s.substring(index2+1); + } + return s; + } + +} diff --git a/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STBinutilsFactoryManager.java b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STBinutilsFactoryManager.java new file mode 100644 index 0000000..a2064d9 --- /dev/null +++ b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STBinutilsFactoryManager.java @@ -0,0 +1,90 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Xavier Raynaud - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.binutils.utils; + +import java.util.HashMap; +import java.util.Map; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.Platform; +import org.eclipse.linuxtools.binutils.Activator; + + +/** + * This class is on charge of managing "org.eclipse.linuxtools.binutils.crossCompilerBinutils" extension point. + * @author Xavier Raynaud + * + */ +public class STBinutilsFactoryManager { + + public static final STBinutilsFactoryManager sharedInstance = new STBinutilsFactoryManager(); + + /** + * Map of CPU/ISTBinutilsFactory + */ + private final Map map = new HashMap(); + + /** + * Default factory + */ + private DefaultBinutilsFactory defaultFactory; + + /** + * Private constructor: this class is implemented as a Singleton + */ + private STBinutilsFactoryManager() { + } + + /** + * Try to find an extension point matching the given cpu; + * Then test availability of the tools. + * If no match, return default binutils factory + */ + private ISTBinutilsFactory getBinutilsFactoryImpl(String cpu) { + try { + IExtensionRegistry reg = Platform.getExtensionRegistry(); + IExtensionPoint ep = reg.getExtensionPoint("org.eclipse.linuxtools.binutils.crossCompilerBinutils"); + IExtension[] exts = ep.getExtensions(); + for (IExtension extension : exts) { + IConfigurationElement[] elems = extension.getConfigurationElements(); + for (IConfigurationElement configurationElement : elems) { + String s = configurationElement.getAttribute("CPU"); + if (cpu.equals(s)) { + ISTBinutilsFactory factory = (ISTBinutilsFactory) configurationElement.createExecutableExtension("binutilsFactory"); + if (factory.testAvailability()) return factory; + } + } + } + } catch (CoreException e) { + Activator.getDefault().getLog().log(e.getStatus()); + } + if (defaultFactory == null) defaultFactory = new DefaultBinutilsFactory(); + return defaultFactory; + } + + /** + * Get a ISTBinutilsFactory matching the given cpu id + * Returns the default one if no match. + */ + public ISTBinutilsFactory getBinutilsFactory(String cpu) { + ISTBinutilsFactory factory = map.get(cpu); + if (factory == null) { + factory = getBinutilsFactoryImpl(cpu); + map.put(cpu, factory); + } + return factory; + } + +} diff --git a/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STCPPFiltFactory.java b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STCPPFiltFactory.java new file mode 100644 index 0000000..56940a6 --- /dev/null +++ b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STCPPFiltFactory.java @@ -0,0 +1,38 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Xavier Raynaud - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.binutils.utils; + +import java.io.IOException; + +import org.eclipse.cdt.utils.CPPFilt; + +/** + * c++filt factory for all toolsets. + * + * @author Xavier Raynaud + */ +public class STCPPFiltFactory { + + + /** + * @param cpuType + * @return an instance of cppfile for the given cpu type + * @throws IOException + */ + public static CPPFilt getCPPFilt(String cpuType) throws IOException { + ISTBinutilsFactory factory = STBinutilsFactoryManager.sharedInstance.getBinutilsFactory(cpuType); + return factory.getCPPFilt(); + } + + + + +} diff --git a/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STNM.java b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STNM.java new file mode 100644 index 0000000..e106c18 --- /dev/null +++ b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STNM.java @@ -0,0 +1,110 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Xavier Raynaud - initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.binutils.utils; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +import org.eclipse.cdt.utils.spawner.ProcessFactory; + +/** + * This class launches NM and parses output + */ +public class STNM { + + private static Pattern undef_pattern = null; + private static Pattern normal_pattern = null; + + private final STNMSymbolsHandler handler; + + /** + * Constructor + * @param command the nm to call + * @param params nm params + * @param file file to parse + * @throws IOException + */ + public STNM(String command, String[] params, String file, STNMSymbolsHandler handler) throws IOException { + this.handler = handler; + if (handler != null) init(command, params, file); + } + + private void init(String command, String[] params, String file) throws IOException { + String[] args = null; + if (params == null || params.length == 0) { + args = new String[] {command, file}; //$NON-NLS-1$ + } else { + args = new String[params.length + 2]; + args[0] = command; + args[params.length+1] = file; + System.arraycopy(params, 0, args, 1, params.length); + } + Process process = ProcessFactory.getFactory().exec(args); + parseOutput(process.getInputStream()); + process.destroy(); + } + + + private void parseOutput(InputStream stream) throws IOException { + BufferedReader reader = new BufferedReader( + new InputStreamReader(stream)); + String line; + + // See matcher.java for regular expression string data definitions. + + if (undef_pattern == null) { + undef_pattern = Pattern.compile("^\\s+U\\s+(\\S+)"); //$NON-NLS-1$ + } + + if (normal_pattern == null) { + normal_pattern = Pattern.compile("^(\\S+)\\s+([AaTtBbDd])\\s+(\\S+)"); //$NON-NLS-1$ + } + while ((line = reader.readLine()) != null) { + Matcher undef_matcher = undef_pattern.matcher(line); + Matcher normal_matcher = normal_pattern.matcher(line); + try { + if (undef_matcher.matches()) { + handler.foundUndefSymbol(undef_matcher.group(1)); + } else if (normal_matcher.matches()) { + char type = normal_matcher.group(2).charAt(0); + String name = normal_matcher.group(3); + String address =normal_matcher.group(1); + + switch (type) { + case 'T': + case 't': + handler.foundTextSymbol(name, address); + break; + case 'B': + case 'b': + handler.foundBssSymbol(name, address); + break; + case 'D': + case 'd': + handler.foundDataSymbol(name, address); + break; + } + } + } catch (NumberFormatException e) { + // ignore. + } catch (IndexOutOfBoundsException e) { + // ignore + } + } + + } + +} diff --git a/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STNMFactory.java b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STNMFactory.java new file mode 100644 index 0000000..0819484 --- /dev/null +++ b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STNMFactory.java @@ -0,0 +1,29 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Xavier Raynaud - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.binutils.utils; + +import java.io.IOException; + +public class STNMFactory { + + /** + * @param cpuType + * @param programPath + * @return an instance of nm for the given program + * @throws IOException + */ + public static STNM getNM(String cpuType, String programPath, STNMSymbolsHandler handler) throws IOException { + ISTBinutilsFactory factory = STBinutilsFactoryManager.sharedInstance.getBinutilsFactory(cpuType); + return factory.getNM(programPath, handler); + } + + +} diff --git a/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STNMSymbolsHandler.java b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STNMSymbolsHandler.java new file mode 100644 index 0000000..6ecb081 --- /dev/null +++ b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STNMSymbolsHandler.java @@ -0,0 +1,23 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Xavier Raynaud - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.binutils.utils; + +public interface STNMSymbolsHandler { + + public void foundUndefSymbol(String symbol); + + public void foundTextSymbol(String symbol, String address); + + public void foundBssSymbol(String symbol, String address); + + public void foundDataSymbol(String symbol, String address); + +} diff --git a/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STSymbolManager.java b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STSymbolManager.java new file mode 100644 index 0000000..2eb3f67 --- /dev/null +++ b/org.eclipse.linuxtools.binutils/src/org/eclipse/linuxtools/binutils/utils/STSymbolManager.java @@ -0,0 +1,591 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Xavier Raynaud - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.binutils.utils; + + +import java.io.IOException; +import java.util.HashMap; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.Map.Entry; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.IAddress; +import org.eclipse.cdt.core.IBinaryParser; +import org.eclipse.cdt.core.IBinaryParser.IBinaryFile; +import org.eclipse.cdt.core.IBinaryParser.IBinaryObject; +import org.eclipse.cdt.core.IBinaryParser.ISymbol; +import org.eclipse.cdt.core.model.CModelException; +import org.eclipse.cdt.core.model.CoreModel; +import org.eclipse.cdt.core.model.CoreModelUtil; +import org.eclipse.cdt.core.model.IBinary; +import org.eclipse.cdt.core.model.ICProject; +import org.eclipse.cdt.core.settings.model.ICConfigurationDescription; +import org.eclipse.cdt.core.settings.model.ICProjectDescription; +import org.eclipse.cdt.utils.Addr2line; +import org.eclipse.cdt.utils.CPPFilt; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtension; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Status; +import org.eclipse.linuxtools.binutils.Activator; + + +/** + * This class Is a utility on top of c++filt and addr2line. + * + * It allows an easy conversion between address and source location, + * and between mangled and demangled symbols. + * + * @author Xavier Raynaud + */ +public class STSymbolManager { + + /** + * Auto dispose timeout: + * If some tools has been unused since more that this time (in ms), + * they are disposed. + */ + private final static long AUTO_DISPOSE_TIMEOUT = 30000; + + /** + * Singleton instance + */ + public final static STSymbolManager sharedInstance = new STSymbolManager(); + + private final class AutoDisposeAddr2line { + private Addr2line addr2line; + private long startTime; + } + + private final class AutoDisposeCPPFilt { + private CPPFilt cppfilt; + private long startTime; + } + + /** Map of all living instance of addr2line */ + private final HashMap addr2lines = new HashMap(); + /** Map of all living instance of cppfilt */ + private final HashMap cppfilts = new HashMap(); + + /** + * Constructor + */ + private STSymbolManager() { + Runnable worker = new Runnable() { + public void run() { + try { + do { + try { + Thread.sleep(AUTO_DISPOSE_TIMEOUT); + } catch (InterruptedException e) { + break; + } + cleanup(); + } while (true); + } catch (Exception _) { + Status s = new Status(Status.ERROR, Activator.PLUGIN_ID, _.getMessage(), _); + Activator.getDefault().getLog().log(s); + } + } + }; + new Thread(worker, "ST System Analysis Symbol Manager").start(); //$NON-NLS-1$ + // TODO: perhaps this thread has to be lazy-created ? + // and perhaps this thread has to destroy itself when it is no longer used ? + } + + /** + * each {@link #AUTO_DISPOSE_TIMEOUT} ms, the unused addr2line and c++filt programs + * are disposed. + */ + private synchronized void cleanup() { + long currentTime = System.currentTimeMillis(); + Iterator > iter = addr2lines.entrySet().iterator(); + while (iter.hasNext()) { + Entry entry = iter.next(); + AutoDisposeAddr2line ada2l = entry.getValue(); + long diff = currentTime-ada2l.startTime; + if (diff > AUTO_DISPOSE_TIMEOUT) { + ada2l.addr2line.dispose(); + ada2l.addr2line = null; + iter.remove(); + } + } + + Iterator > iter2 = cppfilts.entrySet().iterator(); + while (iter2.hasNext()) { + Entry entry = iter2.next(); + AutoDisposeCPPFilt adcppf = entry.getValue(); + long diff = currentTime-adcppf.startTime; + if (diff > AUTO_DISPOSE_TIMEOUT) { + if (adcppf.cppfilt != null) { + adcppf.cppfilt.dispose(); + adcppf.cppfilt = null; + } + iter2.remove(); + } + } + } + + + /** + * Demangle the given symbol + * @param symbol + * @return + */ + public synchronized String demangle(ISymbol symbol) { + String cpu = symbol.getBinaryObject().getCPU(); + String symbolName = symbol.getName(); + return demangleImpl(symbolName, cpu); + } + + /** + * Demangle the given symbol + * @param program + * @param symbolName + * @return + */ + public synchronized String demangle(IBinaryObject program, String symbolName) { + String cpu = program.getCPU(); + return demangleImpl(symbolName, cpu); + } + + + /** + * Demangle the given symbol + * @param symbol + * @return + */ + private synchronized String demangleImpl(String symbolName, String cpu) { + CPPFilt cppfilt = getCppFilt(cpu); + if (cppfilt != null && (symbolName.startsWith("_Z") || symbolName.startsWith("_G"))) { + try { + symbolName = cppfilt.getFunction(symbolName); + } catch (IOException _) { + // TODO: log the error ? + } + } + return symbolName; + } + + + /** + * @param symbol + * @return the location (as returned by addr2line, e.g. file:line) of the given address + */ + public synchronized String getLine(ISymbol symbol) { + IBinaryObject binary = symbol.getBinaryObject(); + IAddress address = symbol.getAddress(); + return getLine(binary, address); + } + + + /** + * @param program + * @param address + * @return the location (as returned by addr2line, e.g. file:line) of the given address + */ + public synchronized String getLine(IBinaryObject program, IAddress address) { + Addr2line addr2line = getAddr2line(program); + if (addr2line == null) return "??:0"; + try { + return addr2line.getLine(address); + } catch (IOException _) { + // TODO: log the error ?; + // Perhaps log the error only once, because + // this method is called many many times... + return "??:0"; + } + } + + /** + * @param program + * @param address an address, in hex, octal or decimal format (0xabcdef, 07654, 12345) + * @return the location (as returned by addr2line, e.g. file:line) of the given address + */ + public synchronized String getLine(IBinaryObject program, String address) { + IAddress addr = program.getAddressFactory().createAddress(address); + return getLine(program, addr); + } + + /** + * @param program + * @param address + * @return the location (as returned by addr2line, e.g. file:line) of the given address + */ + public synchronized String getLine(IBinaryObject program, long address) { + IAddress addr = program.getAddressFactory().createAddress(Long.toString(address)); + return getLine(program, addr); + } + + /** + * @param program + * @param address + * @return the line number of the given address + */ + public synchronized int getLineNumber(IBinaryObject program, IAddress address) { + Addr2line addr2line = getAddr2line(program); + if (addr2line == null) return -1; + try { + return addr2line.getLineNumber(address); + } catch (IOException _) { + // TODO: log the error ?; + // Perhaps log the error only once, because + // this method is called many many times... + return -1; + } + } + + /** + * @param program + * @param address + * @return the line number of the given address + */ + public synchronized int getLineNumber(IBinaryObject program, String address) { + IAddress addr = program.getAddressFactory().createAddress(address); + return getLineNumber(program, addr); + } + + /** + * @param program + * @param address + * @return the line number of the given address + */ + public synchronized int getLineNumber(IBinaryObject program, long address) { + IAddress addr = program.getAddressFactory().createAddress(Long.toString(address)); + return getLineNumber(program, addr); + } + + /** + * + * @param symbol + * @return the line number of the given symbol + */ + public int getLineNumber(ISymbol symbol) { + IBinaryObject obj = symbol.getBinaryObject(); + IAddress address = symbol.getAddress(); + return getLineNumber(obj,address); + } + + /** + * + * @param program + * @param address + * @return the file name of the given address + */ + public synchronized String getFileName(IBinaryObject program, IAddress address) { + Addr2line addr2line = getAddr2line(program); + if (addr2line == null) return null; + try { + return addr2line.getFileName(address); + } catch (IOException _) { + // TODO: log the error ?; + // Perhaps log the error only once, because + // this method is called many many times... + return null; + } + } + + /** + * + * @param program + * @param address + * @return the file name of the given address + */ + public synchronized String getFileName(IBinaryObject program, String address) { + IAddress addr = program.getAddressFactory().createAddress(address); + return getFileName(program, addr); + } + + /** + * + * @param program + * @param address + * @return the file name of the given address + */ + public synchronized String getFileName(IBinaryObject program, long address) { + IAddress addr = program.getAddressFactory().createAddress(Long.toString(address)); + return getFileName(program, addr); + } + + /** + * + * @param symbol + * @return the filename of the given symbol + */ + public String getFilename(ISymbol symbol) { + IBinaryObject obj = symbol.getBinaryObject(); + IAddress address = symbol.getAddress(); + return getFileName(obj,address); + } + + + /** + * @param program + * @param address an address + * @return the function name of the given address, based on addr2line output + */ + public synchronized String getFunctionName(IBinaryObject program, long address) { + IAddress addr = program.getAddressFactory().createAddress(Long.toString(address)); + return getFunctionName(program, addr); + } + + /** + * @param program + * @param address an address, in hex, octal or decimal format (0xabcdef, 07654, 12345) + * @return the function name of the given address, based on addr2line output + */ + public synchronized String getFunctionName(IBinaryObject program, String address) { + IAddress addr = program.getAddressFactory().createAddress(address); + return getFunctionName(program, addr); + } + + /** + * @param program + * @param address an address + * @return the function name of the given address, based on addr2line output + */ + public synchronized String getFunctionName(IBinaryObject program, IAddress address) { + Addr2line addr2line = getAddr2line(program); + if (addr2line == null) return null; + try { + return addr2line.getFunction(address); + } catch (IOException _) { + // TODO: log the error ?; + // Perhaps log the error only once, because + // this method is called many many times... + return null; + } + } + + + /** + * Gets the c++filt support for the given program + * Note that the instance if kept in a local hashmap, and discarded after 30 seconds of inactivity. + * @param program + * @return an instance of CPPFilt suitable for the given program + */ + private synchronized CPPFilt getCppFilt(String cpu) { + AutoDisposeCPPFilt adCppfilt = cppfilts.get(cpu); + if (adCppfilt == null) { + adCppfilt = new AutoDisposeCPPFilt(); + cppfilts.put(cpu, adCppfilt); + } + if (adCppfilt.cppfilt == null) { + try { + adCppfilt.cppfilt = STCPPFiltFactory.getCPPFilt(cpu); + } catch (IOException _) { + // TODO: log the error ?; + // Perhaps log the error only once, because + // this method is called many many times... + return null; + } + } + adCppfilt.startTime = System.currentTimeMillis(); + return adCppfilt.cppfilt; + } + + /** + * Gets the addr2line support for the given program + * Note that the instance if kept in a local hashmap, and discarded after 30 seconds of inactivity. + * @param program + * @return an instance of Addr2line suitable for the given program + */ + private synchronized Addr2line getAddr2line(IBinaryObject program) { + AutoDisposeAddr2line adAddr2line = addr2lines.get(program); + if (adAddr2line == null) { + adAddr2line = new AutoDisposeAddr2line(); + addr2lines.put(program, adAddr2line); + } + if (adAddr2line.addr2line == null) { + try { + adAddr2line.addr2line = STAddr2LineFactory.getAddr2line(program.getCPU(), program.getPath().toOSString()); + } catch (IOException _) { + // TODO: log the error ?; + // Perhaps log the error only once, because + // this method is called many many times... + return null; + } + } + adAddr2line.startTime = System.currentTimeMillis(); + return adAddr2line.addr2line; + } + + /** + * Gets the IBinaryObject corresponding to the given path (absolute path in filesystem). + * If a IBinaryObject corresponding to the given path has been already built by eclipse, return it. + * Otherwise build a new IBinaryObject, according to project preferences. + * Note that it may return null if the path is invalid, or is not a valid binary file. + * @param path + * @return a IBinaryObject + */ + public IBinaryObject getBinaryObject(String loc) { + IPath path = new Path(loc); + return getBinaryObject(path); + } + + + /** + * Gets the IBinaryObject corresponding to the given path (absolute path in filesystem). + * If a IBinaryObject corresponding to the given path has been already built by eclipse, return it. + * Otherwise build a new IBinaryObject, according to project preferences. + * Note that it may return null if the path is invalid, or is not a valid binary file. + * @param path + * @return a IBinaryObject + */ + public IBinaryObject getBinaryObject(IPath path) { + + return getBinaryObject(path, null); + } + + /** + * Gets the IBinaryObject corresponding to the given path (absolute path in filesystem). + * If a IBinaryObject corresponding to the given path has been already built by eclipse, return it. + * Otherwise build a new IBinaryObject, according to project preferences. + * Note that it may return null if the path is invalid, or is not a valid binary file. + * @param path + * @param default parser + * @return a IBinaryObject + */ + public IBinaryObject getBinaryObject(IPath path, IBinaryParser defaultparser) { + IFile c = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path); + List parsers; + if (c != null) { + IBinaryObject object = getAlreadyExistingBinaryObject(c); + if (object != null) return object; + parsers = getBinaryParser(c.getProject()); + } else { + parsers = new LinkedList(); + } + + if (defaultparser == null) { + try { + defaultparser = CCorePlugin.getDefault().getDefaultBinaryParser(); + } catch (CoreException _) { + Activator.getDefault().getLog().log(_.getStatus()); + } + } + if (defaultparser != null) { + parsers.add(defaultparser); + } + return buildBinaryObject(path, parsers); + } + + /** + * Validate the binary file. + * In particular, verify that this binary file can be decoded. + * @param o + * @return the binary object, or null. + */ + private IBinaryObject validateBinary(IBinaryFile o) { + if (o instanceof IBinaryObject) { + IBinaryObject object = (IBinaryObject) o; + String s = null; + try { + s = object.getCPU(); // + } catch (Exception _) {} + if (s.length() > 0) { + return object; + } + } + return null; + } + + private IBinaryObject buildBinaryObject(IPath path, List parsers) { + for (IBinaryParser iBinaryParser : parsers) { + IBinaryObject o = buildBinaryObject(path, iBinaryParser); + if (o != null) return o; + } + return null; + } + + /** + * Build a binary object with the given file and parser. + * Also verify that the builded binary object is valid (@see #validateBinary) + */ + private IBinaryObject buildBinaryObject(IPath path, IBinaryParser parser) { + if (parser == null) return null; + IBinaryFile bf = null; + try { + bf = parser.getBinary(path); + } catch (IOException _) { + // do nothing ? + } + return validateBinary(bf); + } + + /** + * Ask the workbench to find if a binary object already exist for the given file + */ + private IBinaryObject getAlreadyExistingBinaryObject(IFile c) { + IProject project = c.getProject(); + if (project != null && project.exists()) { + ICProject cproject = CoreModel.getDefault().create(project); + if (cproject != null) { + try { + IBinary[] b = cproject.getBinaryContainer() + .getBinaries(); + for (IBinary binary : b) { + IResource r = binary.getResource(); + if (r.equals(c)) { + IBinaryObject binaryObject = (IBinaryObject) binary.getAdapter(IBinaryObject.class); + return validateBinary(binaryObject); + } + } + } catch (CModelException _) { + } + } + } + return null; + } + + /** + * Retrieve the list of binary parsers defined for the given project + */ + private List getBinaryParser(IProject project) { + List parsers = new LinkedList(); + + ICProjectDescription projDesc = CCorePlugin.getDefault().getProjectDescription(project); + if (projDesc == null) return parsers; + ICConfigurationDescription[] cfgs = projDesc.getConfigurations(); + String[] binaryParserIds = CoreModelUtil.getBinaryParserIds(cfgs); + + IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(CCorePlugin.PLUGIN_ID, CCorePlugin.BINARY_PARSER_SIMPLE_ID); + for (String id : binaryParserIds) { + IExtension extension = extensionPoint.getExtension(id); + if (extension != null) { + IConfigurationElement element[] = extension.getConfigurationElements(); + for (IConfigurationElement element2 : element) { + if (element2.getName().equalsIgnoreCase("cextension")) { //$NON-NLS-1$ + try { + IBinaryParser parser = (IBinaryParser) element2.createExecutableExtension("run"); //$NON-NLS-1$ + if (parser != null) parsers.add(parser); + } catch (CoreException _) { + // TODO: handle exception ? + } + } + } + } + } + return parsers; + } + + +} diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/.classpath b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/.classpath new file mode 100644 index 0000000..751c8f2 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/.project b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/.project new file mode 100644 index 0000000..0e6347d --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/.project @@ -0,0 +1,28 @@ + + + org.eclipse.linuxtools.dataviewers.annotatedsourceeditor + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..5466d96 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,3 @@ +#Tue Jun 03 09:41:19 CEST 2008 +eclipse.preferences.version=1 +instance/org.eclipse.core.net/org.eclipse.core.net.hasMigrated=true diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/.settings/org.eclipse.jdt.ui.prefs b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/.settings/org.eclipse.jdt.ui.prefs new file mode 100644 index 0000000..fbc03a9 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/.settings/org.eclipse.jdt.ui.prefs @@ -0,0 +1,3 @@ +#Tue Jun 03 09:41:19 CEST 2008 +eclipse.preferences.version=1 +internal.default.compliance=default diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/META-INF/MANIFEST.MF new file mode 100644 index 0000000..b32e17f --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/META-INF/MANIFEST.MF @@ -0,0 +1,24 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %bundleName +Bundle-SymbolicName: org.eclipse.linuxtools.dataviewers.annotatedsourceeditor;singleton:=true +Bundle-Version: 4.1.0.qualifier +Bundle-Activator: org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.STAnnotatedSourceEditorActivator +Bundle-Vendor: %bundleProvider +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.core.filesystem, + org.eclipse.ui.ide, + org.eclipse.jface.text, + org.eclipse.ui.editors, + org.eclipse.cdt.ui, + org.eclipse.ui.workbench.texteditor, + org.eclipse.core.resources, + org.eclipse.cdt.core +Export-Package: org.eclipse.linuxtools.dataviewers.annotatedsourceeditor, + org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.actions, + org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.hyperlink, + org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.preferencespages +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ActivationPolicy: lazy +Bundle-Localization: plugin diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/about.html b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/about.html new file mode 100644 index 0000000..c258ef5 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/about.html @@ -0,0 +1,28 @@ + + + + +About + + +

About This Content

+ +

June 5, 2006

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + + \ No newline at end of file diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/build.properties b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/build.properties new file mode 100644 index 0000000..d9e2367 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/build.properties @@ -0,0 +1,8 @@ +source.. = src/ +output.. = bin/ +bin.includes = .,\ + META-INF/,\ + icons/,\ + plugin.xml,\ + about.html,\ + plugin.properties diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/icons/c_file_obj.gif b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/icons/c_file_obj.gif new file mode 100644 index 0000000..8fd6adb Binary files /dev/null and b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/icons/c_file_obj.gif differ diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/plugin.properties b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/plugin.properties new file mode 100644 index 0000000..ad2f7d2 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/plugin.properties @@ -0,0 +1,12 @@ +#****************************************************************************** +# Copyright (c) 2009 STMicroelectronics. +# 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: +# STMicroelectronics - initial API and implementation +#******************************************************************************* +bundleProvider = Eclipse Linux Tools +bundleName = Annotated Source Editor Plug-in (Incubation) \ No newline at end of file diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/plugin.xml b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/plugin.xml new file mode 100644 index 0000000..9cf43ea --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/plugin.xml @@ -0,0 +1,58 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/AbstractSTAnnotatedSourceEditorInput.java b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/AbstractSTAnnotatedSourceEditorInput.java new file mode 100644 index 0000000..1a4a0f5 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/AbstractSTAnnotatedSourceEditorInput.java @@ -0,0 +1,82 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.annotatedsourceeditor; + +import java.util.ArrayList; + +import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.swt.graphics.Color; +import org.eclipse.ui.ide.FileStoreEditorInput; + +public abstract class AbstractSTAnnotatedSourceEditorInput extends FileStoreEditorInput{ + private ArrayList columns; + + public AbstractSTAnnotatedSourceEditorInput(IFileStore fileStore) { + super(fileStore); + } + + /** gets how many STColumn exist + * + * @return + */ + public int getColumnCount(){ + if (columns == null){ + columns = getColumns(); + } + return columns!=null ? columns.size() : 0; + } + + /** gets the title of a ST Column + * + * @param column + * @return + */ + public String getTitle(ISTAnnotationColumn column){ + if (columns == null){ + columns = getColumns(); + } + return column!=null ? column.getTitle() : null; + } + + /** gets the background column of a editor line + * + * @param line + * @return + */ + public abstract Color getColor(int line); + + public String getAnnotation(int line, ISTAnnotationColumn column){ + if (columns == null){ + columns = getColumns(); + } + return column!=null ? column.getAnnotation(line) : null; + } + + public String getLongDescription(int line, ISTAnnotationColumn column){ + if (columns == null){ + columns = getColumns(); + } + return column!=null ? column.getLongDescription(line) : null; + } + + public String getTooltip(int line, ISTAnnotationColumn column){ + if (columns == null){ + columns = getColumns(); + } + return column!=null ? column.getTooltip(line) : null; + } + + /** gets the ISTAnnotationColumn objects list + * + * @return + */ + public abstract ArrayList getColumns(); +} diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/ISTAnnotationColumn.java b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/ISTAnnotationColumn.java new file mode 100644 index 0000000..0d7291e --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/ISTAnnotationColumn.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.annotatedsourceeditor; + +public interface ISTAnnotationColumn { + String getTitle(); + String getAnnotation(int line); + String getTooltip(int line); + String getLongDescription(int line); + String getHeaderTooltip(); +} diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/ISTTextEditorActionConstants.java b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/ISTTextEditorActionConstants.java new file mode 100644 index 0000000..9e24ca9 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/ISTTextEditorActionConstants.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.annotatedsourceeditor; + +import org.eclipse.ui.texteditor.ITextEditorActionConstants; + +public interface ISTTextEditorActionConstants extends + ITextEditorActionConstants { + + String ST_TOGGLE= "ST.Toggle"; //$NON-NLS-1$ +} diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/ISTTextEditorActionDefinitionIds.java b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/ISTTextEditorActionDefinitionIds.java new file mode 100644 index 0000000..88915bb --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/ISTTextEditorActionDefinitionIds.java @@ -0,0 +1,20 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.annotatedsourceeditor; + +import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; + +public interface ISTTextEditorActionDefinitionIds extends + ITextEditorActionDefinitionIds { + + String ST_TOGGLE= "org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.STColumnToggle"; //$NON-NLS-1$ + +} diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STAnnotatedCSourceEditor.java b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STAnnotatedCSourceEditor.java new file mode 100644 index 0000000..3b77d6c --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STAnnotatedCSourceEditor.java @@ -0,0 +1,449 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.annotatedsourceeditor; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.cdt.internal.ui.editor.CEditor; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.SafeRunner; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IMenuManager; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.Position; +import org.eclipse.jface.text.source.Annotation; +import org.eclipse.jface.text.source.AnnotationModel; +import org.eclipse.jface.text.source.CompositeRuler; +import org.eclipse.jface.text.source.IChangeRulerColumn; +import org.eclipse.jface.text.source.IOverviewRuler; +import org.eclipse.jface.text.source.ISharedTextColors; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.IVerticalRuler; +import org.eclipse.jface.text.source.IVerticalRulerColumn; +import org.eclipse.jface.util.SafeRunnable; +import org.eclipse.jface.window.DefaultToolTip; +import org.eclipse.jface.window.ToolTip; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.LineBackgroundEvent; +import org.eclipse.swt.custom.LineBackgroundListener; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.custom.StyledTextContent; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontData; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.editors.text.EditorsUI; +import org.eclipse.ui.internal.editors.text.EditorsPlugin; +import org.eclipse.ui.internal.texteditor.AnnotationColumn; +import org.eclipse.ui.internal.texteditor.LineNumberColumn; +import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor; +import org.eclipse.ui.texteditor.AnnotationPreference; +import org.eclipse.ui.texteditor.ITextEditorActionConstants; +import org.eclipse.ui.texteditor.MarkerAnnotationPreferences; +import org.eclipse.ui.texteditor.ResourceAction; +import org.eclipse.ui.texteditor.rulers.IColumnSupport; +import org.eclipse.ui.texteditor.rulers.IContributedRulerColumn; +import org.eclipse.ui.texteditor.rulers.RulerColumnDescriptor; +import org.eclipse.ui.texteditor.rulers.RulerColumnRegistry; + + +public class STAnnotatedCSourceEditor extends CEditor implements LineBackgroundListener { + private final static String ST_RULER= "STRuler"; + + protected STContributedRulerColumn fAbstractSTRulerColumn; + + private IColumnSupport fColumnSupport; + + private LineNumberColumn fLineColumn; + + private STContributedRulerColumn fColumn; + + private StyledText fCachedTextWidget; + + private AbstractSTAnnotatedSourceEditorInput fInput; + + private ArrayList fListColumns; + + private STChangeRulerColumn fSTChangeRulerColumn; + + @Override + public void createPartControl(Composite parent){ + if (fInput == null){ + super.createPartControl(parent); + return; + } + + GridLayout layout= new GridLayout(); + layout.numColumns=fInput.getColumnCount()+1; + layout.horizontalSpacing=0; + parent.setLayout(layout); + GridData gd =new GridData(); + gd.grabExcessHorizontalSpace =false; + gd.grabExcessVerticalSpace =true; + + parent.setLayoutData(gd ); + + Composite fParentSv= new Composite(parent, SWT.NONE); + gd = new GridData(GridData.FILL_BOTH); + gd.horizontalSpan =fInput.getColumnCount()+1; + gd.horizontalIndent=gd.verticalIndent=0; + fParentSv.setLayoutData(gd); + FillLayout fillLayout= new FillLayout(SWT.HORIZONTAL|SWT.VERTICAL); + fillLayout.marginWidth=fillLayout.marginHeight=0; + fParentSv.setLayout(fillLayout); + + super.createPartControl(fParentSv); + + STColumnSupport columnSupport= (STColumnSupport)getAdapter(IColumnSupport.class); + RulerColumnRegistry registry = RulerColumnRegistry.getDefault(); + + for(int i=1;i<=fInput.getColumnCount();i++){ + RulerColumnDescriptor abstractSTColumnDescriptor= registry.getColumnDescriptor(STContributedRulerColumn.ID); + columnSupport.addSTColumn((CompositeRuler)getVerticalRuler(), abstractSTColumnDescriptor,fListColumns.get(i-1)); + + } + + CompositeRuler vr = (CompositeRuler)super.getVerticalRuler(); + int count = 0; + Font font = parent.getFont(); + FontData fd = font.getFontData()[0]; + fd.setStyle(SWT.BOLD); + for(Iterator iter = vr.getDecoratorIterator();iter.hasNext();){ + IVerticalRulerColumn column = (IVerticalRulerColumn)iter.next(); + if (column instanceof STContributedRulerColumn){ + STContributedRulerColumn fSTColumn = (STContributedRulerColumn)column; + Label label = new Label(parent, SWT.BORDER); + gd = new GridData(); + count++; + if (count==1) gd.horizontalIndent=VERTICAL_RULER_WIDTH+5; + else gd.horizontalIndent=0; + gd.widthHint = fSTColumn.getWidth(); + label.setFont(new Font(label.getDisplay(), fd)); + label.setLayoutData(gd); + label.moveAbove(fParentSv); + label.setText(fSTColumn.getAnnotationColumn(0).getTitle()); + fSTColumn.setLabelColumn(label); + + if (fSTColumn.isShowingSTRuler()){ + ToolTipSupport.enableFor(fSTColumn); + } + } + } + + Label label = new Label(parent, SWT.BORDER); + gd = new GridData(); + gd.horizontalAlignment = SWT.FILL; + gd.grabExcessHorizontalSpace = true; + label.setFont(new Font(label.getDisplay(), fd)); + label.setLayoutData(gd); + label.moveAbove(fParentSv); + label.setText(getTitle()); + + showLinesColored(); + + if (getViewer() != null){ + ISourceViewer sv = getViewer(); + + if (sv.getTextWidget() != null){ + + fCachedTextWidget = sv.getTextWidget(); + fCachedTextWidget.addLineBackgroundListener(this); + } + } + } + + @Override + protected void rulerContextMenuAboutToShow(IMenuManager menu) { + super.rulerContextMenuAboutToShow(menu); + + CompositeRuler vr = (CompositeRuler)super.getVerticalRuler(); + + for(Iterator iter = vr.getDecoratorIterator();iter.hasNext();){ + IVerticalRulerColumn column = (IVerticalRulerColumn)iter.next(); + if (column instanceof STContributedRulerColumn){ + STContributedRulerColumn fSTColumn = (STContributedRulerColumn)column; + IAction stprofcolAction = getAction(ISTTextEditorActionConstants.ST_TOGGLE); + stprofcolAction.setChecked(fSTColumn != null && fSTColumn.isShowingSTRuler()); + } + else if (column instanceof LineNumberColumn){ + LineNumberColumn fLineColumn = (LineNumberColumn)column; + IAction lineNumberAction= getAction(ITextEditorActionConstants.LINENUMBERS_TOGGLE); + lineNumberAction.setChecked(fLineColumn != null && fLineColumn.isShowingLineNumbers()); + } + } + + if (fInput != null){ + IAction stAction= getAction(ISTTextEditorActionConstants.ST_TOGGLE); + menu.appendToGroup(ITextEditorActionConstants.GROUP_RULERS, stAction); + } + + + + } + + @SuppressWarnings("unchecked") + @Override + public Object getAdapter(Class required) { + if (IColumnSupport.class.equals(required)) { + if (fColumnSupport == null) + fColumnSupport= createSTColumnSupport(); + return fColumnSupport; + } + + return super.getAdapter(required); + } + + protected IColumnSupport createSTColumnSupport() { + return new STColumnSupport(this,RulerColumnRegistry.getDefault()); + } + + protected class STColumnSupport extends AbstractDecoratedTextEditor.ColumnSupport{ + private final STAnnotatedCSourceEditor fEditor; + private final RulerColumnRegistry fRegistry; + private final ArrayList fColumns; + + public STColumnSupport(STAnnotatedCSourceEditor editor, RulerColumnRegistry registry) { + super(editor, registry); + fEditor = editor; + fRegistry = registry; + fColumns= new ArrayList(); + } + + private int computeIndex(CompositeRuler ruler, RulerColumnDescriptor descriptor) { + int index= 0; + List all= fRegistry.getColumnDescriptors(); + int newPos= all.indexOf(descriptor); + for (Iterator it= ruler.getDecoratorIterator(); it.hasNext();) { + IVerticalRulerColumn column= (IVerticalRulerColumn) it.next(); + if (column instanceof IContributedRulerColumn) { + RulerColumnDescriptor rcd= ((IContributedRulerColumn)column).getDescriptor(); + if (rcd != null && all.indexOf(rcd) > newPos) + break; + } else if ("org.eclipse.jface.text.source.projection.ProjectionRulerColumn".equals(column.getClass().getName())) { //$NON-NLS-1$ + // projection column is always the rightmost column + break; + } + index++; + } + return index; + } + + public void addSTColumn(final CompositeRuler ruler, final RulerColumnDescriptor descriptor,final ISTAnnotationColumn annotationColumn) { + + final int idx= computeIndex(ruler, descriptor); + + SafeRunnable runnable= new SafeRunnable() { + public void run() throws Exception { + IContributedRulerColumn column= descriptor.createColumn(fEditor); + fColumns.add(annotationColumn); + initializeColumn(column); + ruler.addDecorator(idx, column); + } + }; + SafeRunner.run(runnable); + } + + protected void initializeColumn(IContributedRulerColumn column) { + super.initializeColumn(column); + RulerColumnDescriptor descriptor= column.getDescriptor(); + IVerticalRuler ruler= getVerticalRuler(); + if (ruler instanceof CompositeRuler) { + if (AnnotationColumn.ID.equals(descriptor.getId())) { + ((AnnotationColumn)column).setDelegate(createAnnotationRulerColumn((CompositeRuler) ruler)); + } else if (LineNumberColumn.ID.equals(descriptor.getId())) { + fLineColumn= ((LineNumberColumn) column); + fLineColumn.setForwarder(new LineNumberColumn.ICompatibilityForwarder() { + public IVerticalRulerColumn createLineNumberRulerColumn() { + return fEditor.createLineNumberRulerColumn(); + } + public boolean isQuickDiffEnabled() { + return fEditor.isPrefQuickDiffAlwaysOn(); + } + public boolean isLineNumberRulerVisible() { + return fEditor.isLineNumberRulerVisible(); + } + }); + } + if (STContributedRulerColumn.ID.equals(descriptor.getId())){ + fColumn = ((STContributedRulerColumn) column); + //this is a workaround... + fColumn.setForwarder(new STContributedRulerColumn.ICompatibilityForwarder() { + public IVerticalRulerColumn createSTRulerColumn() { + if (fColumns != null && fColumns.size() > 0){ + IVerticalRulerColumn fDelegate = fEditor.createSTRulerColumn(fColumns.get(fColumns.size()-1)); + return fDelegate; + } + return null; + } + public boolean isQuickDiffEnabled() { + return fEditor.isPrefQuickDiffAlwaysOn(); + } + public boolean isSTRulerVisible() { + return fEditor.isSTRulerVisible(); + } + }); + } + } + } + } + + protected IVerticalRulerColumn createSTRulerColumn(ISTAnnotationColumn annotationColumn) { + fSTChangeRulerColumn= new STChangeRulerColumn(getSharedColors(),annotationColumn); + ((IChangeRulerColumn) fSTChangeRulerColumn).setHover(createChangeHover()); + initializeLineNumberRulerColumn(fLineNumberRulerColumn); + + return fSTChangeRulerColumn; + } + + public void lineGetBackground(LineBackgroundEvent event) { + if (fInput != null){ + StyledTextContent c = (StyledTextContent)event.data; + int line = c.getLineAtOffset(event.lineOffset); + event.lineBackground = fInput.getColor(line); + } + } + + @Override + protected void doSetInput(IEditorInput input) throws CoreException { + super.doSetInput(input); + + if (input!=null && input instanceof AbstractSTAnnotatedSourceEditorInput){ + fInput = (AbstractSTAnnotatedSourceEditorInput)input; + fListColumns = fInput.getColumns(); + } + } + + @Override + protected void createActions() { + super.createActions(); + + ResourceAction action; + + action= new ResourceAction(STTextEditorMessages.getBundleForConstructedKeys(), "Editor.ToggleSTColumnAction.", IAction.AS_CHECK_BOX) { //$NON-NLS-1$ + @Override + public void run() { + toggleSTRuler(); + } + }; + + if (fInput != null){ + action.setActionDefinitionId(ISTTextEditorActionDefinitionIds.ST_TOGGLE); + setAction(ISTTextEditorActionConstants.ST_TOGGLE, action); + } + } + + private void toggleSTRuler() { + // globally + IPreferenceStore store= EditorsUI.getPreferenceStore(); + store.setValue(ST_RULER, !isSTRulerVisible()); + } + + protected boolean isSTRulerVisible() { + IPreferenceStore store= getPreferenceStore(); + return store != null ? store.getBoolean(ST_RULER) : true; + } + + private static class ToolTipSupport extends DefaultToolTip{ + private STContributedRulerColumn control; + class ToolTipArea{ + int line; + ISTAnnotationColumn ac; + + ToolTipArea(int line,ISTAnnotationColumn ac){ + this.line = line; + this.ac = ac; + } + + public String getToolTip(){ + return ac.getTooltip(line); + } + + } + + protected ToolTipSupport(STContributedRulerColumn control, int style,boolean manualActivation) { + super(control.getControl(), style, manualActivation); + this.control = control; + } + + protected Object getToolTipArea(Event event) { + + int line = control.toDocumentLineNumber(event.y); + + return new ToolTipArea(line,control.getAnnotationColumn(line)); + } + + protected Composite createToolTipContentArea(Event event, + Composite parent) { + Composite comp = new Composite(parent, SWT.NONE); + comp.setLayout(new FillLayout()); + Label b = new Label(comp,SWT.NONE); + ToolTipArea area = (ToolTipArea)getToolTipArea(event); + if (area != null && area.getToolTip().trim().length()>0){ + b.setText(area.getToolTip()); + } + return comp; + } + + public static void enableFor(STContributedRulerColumn control) { + new ToolTipSupport(control, ToolTip.NO_RECREATE, false); + } + } + + protected IOverviewRuler createOverviewRuler(ISharedTextColors sharedColors) { + IOverviewRuler ruler= new STOverviewRuler(getAnnotationAccess(), VERTICAL_RULER_WIDTH, sharedColors); + MarkerAnnotationPreferences fAnnotationPreferences = EditorsPlugin.getDefault().getMarkerAnnotationPreferences(); + Iterator e= fAnnotationPreferences.getAnnotationPreferences().iterator(); + while (e.hasNext()) { + AnnotationPreference preference= (AnnotationPreference) e.next(); + if (preference.contributesToHeader()) + ruler.addHeaderAnnotationType(preference.getAnnotationType()); + } + return ruler; + + } + + private void showLinesColored(){ + STOverviewRuler or = (STOverviewRuler)getOverviewRuler(); + AnnotationModel am = (AnnotationModel)or.getModel(); + IDocument doc = getSourceViewer().getDocument(); + int lines = doc.getNumberOfLines(); + + for(int i=0;i - initial API and implementation + +********************************************************************** +*********/ +package org.eclipse.linuxtools.dataviewers.annotatedsourceeditor; + +import org.eclipse.ui.editors.text.EditorsUI; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class STAnnotatedSourceEditorActivator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.linuxtools.dataviewers.annotatedsourceeditor"; + + private static final String ANNOTATION_TYPE = ".coloredLines"; + + // The shared instance + private static STAnnotatedSourceEditorActivator plugin; + + /** + * The constructor + */ + public STAnnotatedSourceEditorActivator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + EditorsUI.getPreferenceStore().setValue("STRuler",true); + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static STAnnotatedSourceEditorActivator getDefault() { + return plugin; + } + + public static String getAnnotationType() + { + return ANNOTATION_TYPE; + } + + public static String getUniqueIdentifier() + { + return PLUGIN_ID; + } + +} diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STChangeRulerColumn.java b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STChangeRulerColumn.java new file mode 100644 index 0000000..fa2e057 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STChangeRulerColumn.java @@ -0,0 +1,390 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.annotatedsourceeditor; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.jface.internal.text.revisions.RevisionPainter; +import org.eclipse.jface.internal.text.source.DiffPainter; +import org.eclipse.jface.text.revisions.IRevisionListener; +import org.eclipse.jface.text.revisions.IRevisionRulerColumn; +import org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension; +import org.eclipse.jface.text.revisions.RevisionInformation; +import org.eclipse.jface.text.source.CompositeRuler; +import org.eclipse.jface.text.source.IAnnotationHover; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.jface.text.source.IChangeRulerColumn; +import org.eclipse.jface.text.source.ILineRange; +import org.eclipse.jface.text.source.ISharedTextColors; +import org.eclipse.jface.text.source.IVerticalRulerInfo; +import org.eclipse.jface.text.source.IVerticalRulerInfoExtension; +import org.eclipse.jface.text.source.IVerticalRulerListener; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; + +/** + * A vertical ruler column displaying line numbers and serving as a UI for quick diff. + * Clients usually instantiate and configure object of this class. + * + * @since 3.0 + */ +public final class STChangeRulerColumn extends STRulerColumn implements IVerticalRulerInfo, IVerticalRulerInfoExtension, IChangeRulerColumn, IRevisionRulerColumn, IRevisionRulerColumnExtension { + /** The ruler's annotation model. */ + private IAnnotationModel fAnnotationModel; + /** true if changes should be displayed using character indications instead of background colors. */ + private boolean fCharacterDisplay; + /** + * The revision painter strategy. + * + * @since 3.2 + */ + private final RevisionPainter fRevisionPainter; + /** + * The diff information painter strategy. + * + * @since 3.2 + */ + private final DiffPainter fDiffPainter; + /** + * Whether to show number or to behave like a change ruler column. + * @since 3.3 + */ + private boolean fShowSTRuler= true; + + /** + * Creates a new instance. + * + * @param sharedColors the shared colors provider to use + */ + public STChangeRulerColumn(ISharedTextColors sharedColors,ISTAnnotationColumn ac) { + super(ac); + Assert.isNotNull(sharedColors); + fRevisionPainter= new RevisionPainter(this, sharedColors); + fDiffPainter= new DiffPainter(this, sharedColors); + } + + /* + * @see org.eclipse.jface.text.source.LineNumberRulerColumn#createControl(org.eclipse.jface.text.source.CompositeRuler, org.eclipse.swt.widgets.Composite) + */ + public Control createControl(CompositeRuler parentRuler, Composite parentControl) { + Control control= super.createControl(parentRuler, parentControl); + fRevisionPainter.setParentRuler(parentRuler); + fDiffPainter.setParentRuler(parentRuler); + return control; + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRulerInfo#getLineOfLastMouseButtonActivity() + */ + public int getLineOfLastMouseButtonActivity() { + return getParentRuler().getLineOfLastMouseButtonActivity(); + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRulerInfo#toDocumentLineNumber(int) + */ + public int toDocumentLineNumber(int y_coordinate) { + return getParentRuler().toDocumentLineNumber(y_coordinate); + } + + /* + * @see IVerticalRulerColumn#setModel(IAnnotationModel) + */ + public void setModel(IAnnotationModel model) { + setAnnotationModel(model); + fRevisionPainter.setModel(model); + fDiffPainter.setModel(model); + updateNumberOfDigits(); + computeIndentations(); + layout(true); + postRedraw(); + } + + private void setAnnotationModel(IAnnotationModel model) { + if (fAnnotationModel != model) + fAnnotationModel= model; + } + + + /** + * Sets the display mode of the ruler. If character mode is set to true, diff + * information will be displayed textually on the line number ruler. + * + * @param characterMode true if diff information is to be displayed textually. + */ + public void setDisplayMode(boolean characterMode) { + if (characterMode != fCharacterDisplay) { + fCharacterDisplay= characterMode; + updateNumberOfDigits(); + computeIndentations(); + layout(true); + } + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#getModel() + */ + public IAnnotationModel getModel() { + return fAnnotationModel; + } + + /* + * @see org.eclipse.jface.text.source.LineNumberRulerColumn#createDisplayString(int) + */ + protected String createDisplayString(int line) { + StringBuffer buffer= new StringBuffer(); + if (fShowSTRuler) + buffer.append(super.createDisplayString(line)); + if (fCharacterDisplay && getModel() != null) + buffer.append(fDiffPainter.getDisplayCharacter(line)); + return buffer.toString(); + } + + /* + * @see org.eclipse.jface.text.source.LineNumberRulerColumn#computeNumberOfDigits() + */ + protected int computeNumberOfDigits() { + int digits; + if (fCharacterDisplay && getModel() != null) { + if (fShowSTRuler) + digits= super.computeNumberOfDigits() + 1; + else + digits= 1; + } else { + if (fShowSTRuler) + digits= super.computeNumberOfDigits(); + else + digits= 0; + } + if (fRevisionPainter.hasInformation()) + digits+= fRevisionPainter.getRequiredWidth(); + return digits; + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#addVerticalRulerListener(org.eclipse.jface.text.source.IVerticalRulerListener) + */ + public void addVerticalRulerListener(IVerticalRulerListener listener) { + throw new UnsupportedOperationException(); + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#removeVerticalRulerListener(org.eclipse.jface.text.source.IVerticalRulerListener) + */ + public void removeVerticalRulerListener(IVerticalRulerListener listener) { + throw new UnsupportedOperationException(); + } + + /* + * @see org.eclipse.jface.text.source.LineNumberRulerColumn#doPaint(org.eclipse.swt.graphics.GC) + */ + void doPaint(GC gc, ILineRange visibleLines) { + Color foreground= gc.getForeground(); + if (visibleLines != null) { + if (fRevisionPainter.hasInformation()) + fRevisionPainter.paint(gc, visibleLines); + else if (fDiffPainter.hasInformation()) // don't paint quick diff colors if revisions are painted + fDiffPainter.paint(gc, visibleLines); + } + gc.setForeground(foreground); + if (fShowSTRuler || fCharacterDisplay) + super.doPaint(gc, visibleLines); + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#getHover() + */ + public IAnnotationHover getHover() { + int activeLine= getParentRuler().getLineOfLastMouseButtonActivity(); + if (fRevisionPainter.hasHover(activeLine)) + return fRevisionPainter.getHover(); + if (fDiffPainter.hasHover(activeLine)) + return fDiffPainter.getHover(); + return null; + } + + /* + * @see org.eclipse.jface.text.source.IChangeRulerColumn#setHover(org.eclipse.jface.text.source.IAnnotationHover) + */ + public void setHover(IAnnotationHover hover) { + fRevisionPainter.setHover(hover); + fDiffPainter.setHover(hover); + } + + /* + * @see org.eclipse.jface.text.source.IChangeRulerColumn#setBackground(org.eclipse.swt.graphics.Color) + */ + public void setBackground(Color background) { + super.setBackground(background); + fRevisionPainter.setBackground(background); + fDiffPainter.setBackground(background); + } + + /* + * @see org.eclipse.jface.text.source.IChangeRulerColumn#setAddedColor(org.eclipse.swt.graphics.Color) + */ + public void setAddedColor(Color addedColor) { + fDiffPainter.setAddedColor(addedColor); + } + + /* + * @see org.eclipse.jface.text.source.IChangeRulerColumn#setChangedColor(org.eclipse.swt.graphics.Color) + */ + public void setChangedColor(Color changedColor) { + fDiffPainter.setChangedColor(changedColor); + } + + /* + * @see org.eclipse.jface.text.source.IChangeRulerColumn#setDeletedColor(org.eclipse.swt.graphics.Color) + */ + public void setDeletedColor(Color deletedColor) { + fDiffPainter.setDeletedColor(deletedColor); + } + + /* + * @see org.eclipse.jface.text.revisions.IRevisionRulerColumn#setRevisionInformation(org.eclipse.jface.text.revisions.RevisionInformation) + */ + public void setRevisionInformation(RevisionInformation info) { + fRevisionPainter.setRevisionInformation(info); + updateNumberOfDigits(); + computeIndentations(); + layout(true); + postRedraw(); + } + + /* + * @see org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension#getRevisionSelectionProvider() + * @since 3.2 + */ + public ISelectionProvider getRevisionSelectionProvider() { + return fRevisionPainter.getRevisionSelectionProvider(); + } + + /* + * @see org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension#setRenderingMode(org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension.RenderingMode) + * @since 3.3 + */ + public void setRevisionRenderingMode(RenderingMode renderingMode) { + fRevisionPainter.setRenderingMode(renderingMode); + } + + /** + * Sets the line number display mode. + * + * @param showNumbers true to show numbers, false to only show + * diff / revision info. + * @since 3.3 + */ + public void showLineNumbers(boolean showNumbers) { + if (fShowSTRuler != showNumbers) { + fShowSTRuler= showNumbers; + updateNumberOfDigits(); + computeIndentations(); + layout(true); + } + } + + /* + * @see org.eclipse.jface.text.source.LineNumberRulerColumn#getWidth() + * @since 3.3 + */ + public int getWidth() { + int width= super.getWidth(); + return width > 0 ? width : 8; // minimal width to display quick diff / revisions if no textual info is shown + } + + /** + * Returns true if the ruler is showing line numbers, false + * otherwise + * + * @return true if line numbers are shown, false otherwise + * @since 3.3 + */ + public boolean isShowingSTRuler() { + return fShowSTRuler; + } + + /** + * Returns true if the ruler is showing revision information, false + * otherwise + * + * @return true if revision information is shown, false otherwise + * @since 3.3 + */ + public boolean isShowingRevisionInformation() { + return fRevisionPainter.hasInformation(); + } + + /** + * Returns true if the ruler is showing change information, false + * otherwise + * + * @return true if change information is shown, false otherwise + * @since 3.3 + */ + public boolean isShowingChangeInformation() { + return fDiffPainter.hasInformation(); + } + + /* + * @see org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension#showRevisionAuthor(boolean) + * @since 3.3 + */ + public void showRevisionAuthor(boolean show) { + fRevisionPainter.showRevisionAuthor(show); + updateNumberOfDigits(); + computeIndentations(); + layout(true); + postRedraw(); + } + + /* + * @see org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension#showRevisionId(boolean) + * @since 3.3 + */ + public void showRevisionId(boolean show) { + fRevisionPainter.showRevisionId(show); + updateNumberOfDigits(); + computeIndentations(); + layout(true); + postRedraw(); + } + + /* + * @see org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension#addRevisionListener(org.eclipse.jface.text.revisions.IRevisionListener) + * @since 3.3 + */ + public void addRevisionListener(IRevisionListener listener) { + fRevisionPainter.addRevisionListener(listener); + } + + /* + * @see org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension#removeRevisionListener(org.eclipse.jface.text.revisions.IRevisionListener) + * @since 3.3 + */ + public void removeRevisionListener(IRevisionListener listener) { + fRevisionPainter.removeRevisionListener(listener); + } + + /* + * @see org.eclipse.jface.text.source.LineNumberRulerColumn#handleDispose() + * @since 3.3 + */ + protected void handleDispose() { + fRevisionPainter.setParentRuler(null); + fRevisionPainter.setModel(null); + fDiffPainter.setParentRuler(null); + fDiffPainter.setModel(null); + super.handleDispose(); + } +} diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STConstructedTextEditorMessages.properties b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STConstructedTextEditorMessages.properties new file mode 100644 index 0000000..0c9d76c --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STConstructedTextEditorMessages.properties @@ -0,0 +1,4 @@ +Editor.ToggleSTColumnAction.label=Show Annotation &Columns +Editor.ToggleSTColumnAction.description=Show Annotation Columns +Editor.STColumnAction.tooltip=Display the Annotation Column Ruler +Editor.STColumnAction.image= diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STContributedRulerColumn.java b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STContributedRulerColumn.java new file mode 100644 index 0000000..0836fd7 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STContributedRulerColumn.java @@ -0,0 +1,798 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.annotatedsourceeditor; + + +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.jface.dialogs.MessageDialogWithToggle; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.jface.preference.PreferenceConverter; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.revisions.IRevisionRulerColumn; +import org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension; +import org.eclipse.jface.text.revisions.RevisionInformation; +import org.eclipse.jface.text.revisions.IRevisionRulerColumnExtension.RenderingMode; +import org.eclipse.jface.text.source.AnnotationModel; +import org.eclipse.jface.text.source.CompositeRuler; +import org.eclipse.jface.text.source.IAnnotationHover; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.jface.text.source.IAnnotationModelExtension; +import org.eclipse.jface.text.source.IChangeRulerColumn; +import org.eclipse.jface.text.source.ILineDifferExtension; +import org.eclipse.jface.text.source.ILineDifferExtension2; +import org.eclipse.jface.text.source.ISharedTextColors; +import org.eclipse.jface.text.source.ISourceViewer; +import org.eclipse.jface.text.source.IVerticalRulerColumn; +import org.eclipse.jface.text.source.IVerticalRulerInfo; +import org.eclipse.jface.text.source.IVerticalRulerInfoExtension; +import org.eclipse.jface.text.source.IVerticalRulerListener; +import org.eclipse.jface.util.IPropertyChangeListener; +import org.eclipse.jface.util.PropertyChangeEvent; +import org.eclipse.jface.viewers.ISelectionProvider; +import org.eclipse.jface.window.Window; +import org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.preferencespages.STAnnotatedSourceEditorPreferencePage; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Label; +import org.eclipse.ui.editors.text.EditorsUI; +import org.eclipse.ui.internal.editors.text.EditorsPlugin; +import org.eclipse.ui.internal.texteditor.PropertyEventDispatcher; +import org.eclipse.ui.texteditor.AbstractDecoratedTextEditor; +import org.eclipse.ui.texteditor.AbstractDecoratedTextEditorPreferenceConstants; +import org.eclipse.ui.texteditor.AbstractTextEditor; +import org.eclipse.ui.texteditor.AnnotationPreference; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.ITextEditorExtension; +import org.eclipse.ui.texteditor.ITextEditorExtension2; +import org.eclipse.ui.texteditor.MarkerAnnotationPreferences; +import org.eclipse.ui.texteditor.quickdiff.QuickDiff; +import org.eclipse.ui.texteditor.rulers.AbstractContributedRulerColumn; + + +public class STContributedRulerColumn extends AbstractContributedRulerColumn implements IVerticalRulerInfo, IVerticalRulerInfoExtension { + /** + * Forwarder for preference checks and ruler creation. Needed to maintain the forwarded APIs in + * {@link AbstractDecoratedTextEditor}. + */ + public static interface ICompatibilityForwarder { + IVerticalRulerColumn createSTRulerColumn(); + boolean isQuickDiffEnabled(); + boolean isSTRulerVisible(); + } + + public static final String ID= "org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.column"; //$NON-NLS-1$ + + private static final String FG_COLOR_KEY= AbstractDecoratedTextEditorPreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR; + private static final String BG_COLOR_KEY= AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND; + private static final String USE_DEFAULT_BG_KEY= AbstractTextEditor.PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT; + private final static String ST_KEY= STAnnotatedSourceEditorPreferencePage.EDITOR_ST_RULER; + private final static String REVISION_ASK_BEFORE_QUICKDIFF_SWITCH_KEY= AbstractDecoratedTextEditorPreferenceConstants.REVISION_ASK_BEFORE_QUICKDIFF_SWITCH; + + private IVerticalRulerColumn fDelegate; + /** + * The annotation preferences. + */ + private final MarkerAnnotationPreferences fAnnotationPreferences= EditorsPlugin.getDefault().getMarkerAnnotationPreferences(); + + /** + * Preference dispatcher that registers a single listener so we don't have to manage every + * single preference listener. + */ + private PropertyEventDispatcher fDispatcher; + private ISourceViewer fViewer; + private ICompatibilityForwarder fForwarder; + + + private Label labelColumn; + + /* + * @see org.eclipse.jface.text.source.IVerticalRulerColumn#createControl(org.eclipse.jface.text.source.CompositeRuler, org.eclipse.swt.widgets.Composite) + */ + public Control createControl(CompositeRuler parentRuler, Composite parentControl) { + Assert.isTrue(fDelegate != null); + ITextViewer viewer= parentRuler.getTextViewer(); + Assert.isLegal(viewer instanceof ISourceViewer); + fViewer= (ISourceViewer) viewer; + initialize(); + Control control= fDelegate.createControl(parentRuler, parentControl); + return control; + } + + public void setLabelColumn(Label label){ + labelColumn = label; + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRulerColumn#getControl() + */ + public Control getControl() { + return fDelegate.getControl(); + } + + public ISTAnnotationColumn getAnnotationColumn(int line){ + if (fDelegate instanceof STChangeRulerColumn){ + return ((STChangeRulerColumn)fDelegate).getSTAnnotationColumn(); + } + return null; + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRulerColumn#getWidth() + */ + public int getWidth() { + return fDelegate.getWidth(); + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRulerColumn#redraw() + */ + public void redraw() { + fDelegate.redraw(); + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRulerColumn#setFont(org.eclipse.swt.graphics.Font) + */ + public void setFont(Font font) { + fDelegate.setFont(font); + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRulerColumn#setModel(org.eclipse.jface.text.source.IAnnotationModel) + */ + public void setModel(IAnnotationModel model) { + if (getQuickDiffPreference()) + fDelegate.setModel(model); + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRulerInfo#getLineOfLastMouseButtonActivity() + */ + public int getLineOfLastMouseButtonActivity() { + if (fDelegate instanceof IVerticalRulerInfo) + ((IVerticalRulerInfo) fDelegate).getLineOfLastMouseButtonActivity(); + return -1; + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRulerInfo#toDocumentLineNumber(int) + */ + public int toDocumentLineNumber(int y_coordinate) { + if (fDelegate instanceof IVerticalRulerInfo) + return ((IVerticalRulerInfo) fDelegate).toDocumentLineNumber(y_coordinate); + return -1; + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#addVerticalRulerListener(org.eclipse.jface.text.source.IVerticalRulerListener) + */ + public void addVerticalRulerListener(IVerticalRulerListener listener) { + if (fDelegate instanceof IVerticalRulerInfoExtension) + ((IVerticalRulerInfoExtension) fDelegate).addVerticalRulerListener(listener); + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#getHover() + */ + public IAnnotationHover getHover() { + if (fDelegate instanceof IVerticalRulerInfoExtension) + return ((IVerticalRulerInfoExtension) fDelegate).getHover(); + return null; + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#getModel() + */ + public IAnnotationModel getModel() { + if (fDelegate instanceof IVerticalRulerInfoExtension) + return ((IVerticalRulerInfoExtension) fDelegate).getModel(); + return null; + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRulerInfoExtension#removeVerticalRulerListener(org.eclipse.jface.text.source.IVerticalRulerListener) + */ + public void removeVerticalRulerListener(IVerticalRulerListener listener) { + if (fDelegate instanceof IVerticalRulerInfoExtension) + ((IVerticalRulerInfoExtension) fDelegate).removeVerticalRulerListener(listener); + } + + /* + * @see org.eclipse.ui.texteditor.rulers.AbstractContributedRulerColumn#columnRemoved() + */ + public void columnRemoved() { + if (fDispatcher != null) { + fDispatcher.dispose(); + fDispatcher= null; + } + } + + private IPreferenceStore getPreferenceStore() { + return EditorsUI.getPreferenceStore(); + } + + private ISharedTextColors getSharedColors() { + return EditorsUI.getSharedTextColors(); + } + + /** + * Initializes the given line number ruler column from the preference store. + */ + private void initialize() { + final IPreferenceStore store= getPreferenceStore(); + if (store == null) + return; + + // initial set up + updateForegroundColor(store, fDelegate); + updateBackgroundColor(store, fDelegate); + + updateLineNumbersVisibility(fDelegate); + updateQuickDiffVisibility(fDelegate); + updateCharacterMode(store, fDelegate); + updateRevisionRenderingMode(store, fDelegate); + updateRevisionAuthorVisibility(store, fDelegate); + updateRevisionIdVisibility(store, fDelegate); + + Map annotationPrefs= getAnnotationPreferenceMap(); + final AnnotationPreference changedPref= annotationPrefs.get("org.eclipse.ui.workbench.texteditor.quickdiffChange"); //$NON-NLS-1$ + final AnnotationPreference addedPref= annotationPrefs.get("org.eclipse.ui.workbench.texteditor.quickdiffAddition"); //$NON-NLS-1$ + final AnnotationPreference deletedPref= annotationPrefs.get("org.eclipse.ui.workbench.texteditor.quickdiffDeletion"); //$NON-NLS-1$ + updateChangedColor(changedPref, store, fDelegate); + updateAddedColor(addedPref, store, fDelegate); + updateDeletedColor(deletedPref, store, fDelegate); + + if (fDelegate != null) + fDelegate.redraw(); + + // listen to changes + fDispatcher= new PropertyEventDispatcher(store); + + fDispatcher.addPropertyChangeListener(FG_COLOR_KEY, new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + updateForegroundColor(store, fDelegate); + fDelegate.redraw(); + } + }); + IPropertyChangeListener backgroundHandler= new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + updateBackgroundColor(store, fDelegate); + fDelegate.redraw(); + } + }; + fDispatcher.addPropertyChangeListener(BG_COLOR_KEY, backgroundHandler); + fDispatcher.addPropertyChangeListener(USE_DEFAULT_BG_KEY, backgroundHandler); + + fDispatcher.addPropertyChangeListener(ST_KEY, new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + // only handle quick diff on/off information, but not ruler visibility (handled by AbstractDecoratedTextEditor) + + updateLineNumbersVisibility(fDelegate); + } + }); + + fDispatcher.addPropertyChangeListener(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_CHARACTER_MODE, new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + updateCharacterMode(store, fDelegate); + } + }); + + fDispatcher.addPropertyChangeListener(AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_RENDERING_MODE, new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + updateRevisionRenderingMode(store, fDelegate); + } + }); + + fDispatcher.addPropertyChangeListener(AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_SHOW_AUTHOR, new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + updateRevisionAuthorVisibility(store, fDelegate); + } + }); + + fDispatcher.addPropertyChangeListener(AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_SHOW_REVISION, new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + updateRevisionIdVisibility(store, fDelegate); + } + }); + + fDispatcher.addPropertyChangeListener(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_ALWAYS_ON, new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + updateQuickDiffVisibility(fDelegate); + } + }); + + if (changedPref != null) { + fDispatcher.addPropertyChangeListener(changedPref.getColorPreferenceKey(), new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + updateChangedColor(changedPref, store, fDelegate); + fDelegate.redraw(); + } + }); + } + if (addedPref != null) { + fDispatcher.addPropertyChangeListener(addedPref.getColorPreferenceKey(), new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + updateAddedColor(addedPref, store, fDelegate); + fDelegate.redraw(); + } + }); + } + if (deletedPref != null) { + fDispatcher.addPropertyChangeListener(deletedPref.getColorPreferenceKey(), new IPropertyChangeListener() { + public void propertyChange(PropertyChangeEvent event) { + updateDeletedColor(deletedPref, store, fDelegate); + fDelegate.redraw(); + } + }); + } + } + + private Map getAnnotationPreferenceMap() { + Map annotationPrefs= new HashMap(); + Iterator iter= fAnnotationPreferences.getAnnotationPreferences().iterator(); + while (iter.hasNext()) { + AnnotationPreference pref= (AnnotationPreference) iter.next(); + Object type= pref.getAnnotationType(); + annotationPrefs.put(type, pref); + } + return annotationPrefs; + } + + private void updateForegroundColor(IPreferenceStore store, IVerticalRulerColumn column) { + RGB rgb= getColorFromStore(store, FG_COLOR_KEY); + if (rgb == null) + rgb= new RGB(0, 0, 0); + ISharedTextColors sharedColors= getSharedColors(); + if (column instanceof STRulerColumn) + ((STRulerColumn) column).setForeground(sharedColors.getColor(rgb)); + } + + private void updateBackgroundColor(IPreferenceStore store, IVerticalRulerColumn column) { + // background color: same as editor, or system default + RGB rgb; + if (store.getBoolean(USE_DEFAULT_BG_KEY)) + rgb= null; + else + rgb= getColorFromStore(store, BG_COLOR_KEY); + ISharedTextColors sharedColors= getSharedColors(); + if (column instanceof STRulerColumn) + ((STRulerColumn) column).setBackground(sharedColors.getColor(rgb)); + } + + private void updateChangedColor(AnnotationPreference pref, IPreferenceStore store, IVerticalRulerColumn column) { + if (pref != null && column instanceof IChangeRulerColumn) { + RGB rgb= getColorFromAnnotationPreference(store, pref); + ((IChangeRulerColumn) column).setChangedColor(getSharedColors().getColor(rgb)); + } + } + + private void updateAddedColor(AnnotationPreference pref, IPreferenceStore store, IVerticalRulerColumn column) { + if (pref != null && column instanceof IChangeRulerColumn) { + RGB rgb= getColorFromAnnotationPreference(store, pref); + ((IChangeRulerColumn) column).setAddedColor(getSharedColors().getColor(rgb)); + } + } + + private void updateDeletedColor(AnnotationPreference pref, IPreferenceStore store, IVerticalRulerColumn column) { + if (pref != null && column instanceof IChangeRulerColumn) { + RGB rgb= getColorFromAnnotationPreference(store, pref); + ((IChangeRulerColumn) column).setDeletedColor(getSharedColors().getColor(rgb)); + } + } + + private void updateCharacterMode(IPreferenceStore store, IVerticalRulerColumn column) { + if (column instanceof STChangeRulerColumn) { + STChangeRulerColumn lncrc= (STChangeRulerColumn) column; + lncrc.setDisplayMode(store.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_CHARACTER_MODE)); + } + } + + private void updateLineNumbersVisibility(IVerticalRulerColumn column) { + if (column instanceof STChangeRulerColumn){ + if (labelColumn != null){ + labelColumn.setVisible(getLineNumberPreference()); + Label labelName = (Label)labelColumn.getParent().getChildren()[labelColumn.getParent().getChildren().length-2]; + labelName.setVisible(labelColumn.isVisible()); + + } + ((STChangeRulerColumn) column).showLineNumbers(getLineNumberPreference()); + } + } + + private void updateRevisionRenderingMode(IPreferenceStore store, IVerticalRulerColumn column) { + if (column instanceof IRevisionRulerColumnExtension) { + String option= store.getString(AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_RENDERING_MODE); + RenderingMode[] modes= { IRevisionRulerColumnExtension.AUTHOR, IRevisionRulerColumnExtension.AGE, IRevisionRulerColumnExtension.AUTHOR_SHADED_BY_AGE }; + for (int i= 0; i < modes.length; i++) { + if (modes[i].name().equals(option)) { + ((IRevisionRulerColumnExtension) column).setRevisionRenderingMode(modes[i]); + return; + } + } + } + } + + private void updateRevisionAuthorVisibility(IPreferenceStore store, IVerticalRulerColumn column) { + if (column instanceof IRevisionRulerColumnExtension) { + boolean show= store.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_SHOW_AUTHOR); + ((IRevisionRulerColumnExtension) column).showRevisionAuthor(show); + } + } + + private void updateRevisionIdVisibility(IPreferenceStore store, IVerticalRulerColumn column) { + if (column instanceof IRevisionRulerColumnExtension) { + boolean show= store.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.REVISION_RULER_SHOW_REVISION); + ((IRevisionRulerColumnExtension) column).showRevisionId(show); + } + } + + private void updateQuickDiffVisibility(IVerticalRulerColumn column) { + boolean show= getQuickDiffPreference(); + if (show == isShowingChangeInformation()) + return; + + if (show) + installChangeRulerModel(column); + else + uninstallChangeRulerModel(column); + } + + /** + * Returns whether the line number ruler column should be + * visible according to the preference store settings. Subclasses may override this + * method to provide a custom preference setting. + * + * @return true if the line numbers should be visible + */ + private boolean getLineNumberPreference() { + if (fForwarder != null) + return fForwarder.isSTRulerVisible(); + IPreferenceStore store= getPreferenceStore(); + return store != null ? store.getBoolean(ST_KEY) : false; + } + + /** + * Returns whether quick diff info should be visible upon opening an editor + * according to the preference store settings. + * + * @return true if the line numbers should be visible + */ + private boolean getQuickDiffPreference() { + if (fForwarder != null) + return fForwarder.isQuickDiffEnabled(); + IPreferenceStore store= getPreferenceStore(); + boolean setting= store != null ? store.getBoolean(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_ALWAYS_ON) : false; + if (!setting) + return false; + + boolean modifiable; + ITextEditor editor= getEditor(); + if (editor instanceof ITextEditorExtension2) { + ITextEditorExtension2 ext= (ITextEditorExtension2) editor; + modifiable= ext.isEditorInputModifiable(); + } else if (editor instanceof ITextEditorExtension) { + ITextEditorExtension ext= (ITextEditorExtension) editor; + modifiable= ext.isEditorInputReadOnly(); + } else if (editor != null) { + modifiable= editor.isEditable(); + } else { + modifiable= true; + } + return modifiable; + } + + /** + * Extracts the color preference for the given preference from the given store. + * If the given store indicates that the default value is to be used, or + * the value stored in the preferences store is null, + * the value is taken from the AnnotationPreference's default + * color value. + *

+ * The return value is + *

+ * + * @param store the preference store + * @param pref the annotation preference + * @return the RGB color preference, not null + */ + private static RGB getColorFromAnnotationPreference(IPreferenceStore store, AnnotationPreference pref) { + String key= pref.getColorPreferenceKey(); + RGB rgb= null; + if (store.contains(key)) { + if (store.isDefault(key)) + rgb= pref.getColorPreferenceValue(); + else + rgb= PreferenceConverter.getColor(store, key); + } + if (rgb == null) + rgb= pref.getColorPreferenceValue(); + return rgb; + } + + private static RGB getColorFromStore(IPreferenceStore store, String key) { + RGB rgb= null; + if (store.contains(key)) { + if (store.isDefault(key)) + rgb= PreferenceConverter.getDefaultColor(store, key); + else + rgb= PreferenceConverter.getColor(store, key); + } + return rgb; + } + + /** + * Ensures that quick diff information is displayed and the quick diff provider is the one with + * the specified id. If a different quick diff provider is in use, the user may be asked whether + * he wants to switch. + * + * @param diffProviderId the quick diff provider id to use + * @return true if quick diff could be enabled for the given id, + * false otherwise + */ + private boolean ensureQuickDiffProvider(String diffProviderId) { + if (!isShowingChangeInformation()) + installChangeRulerModel(fDelegate); // FIXME pass provider id + + IAnnotationModel annotationModel= fViewer.getAnnotationModel(); + IAnnotationModel oldDiffer= getDiffer(); + if (oldDiffer == null && annotationModel != null) + return false; // quick diff is enabled, but no differ? not working for whatever reason + + if (annotationModel == null) + annotationModel= new AnnotationModel(); + if (!(annotationModel instanceof IAnnotationModelExtension)) + return false; + + QuickDiff util= new QuickDiff(); + Object oldDifferId= util.getConfiguredQuickDiffProvider(oldDiffer); + if (oldDifferId.equals(diffProviderId)) { + if (oldDiffer instanceof ILineDifferExtension) + ((ILineDifferExtension) oldDiffer).resume(); + return true; + } + + // Check whether the desired provider is available at all + IAnnotationModel newDiffer= util.createQuickDiffAnnotationModel(getEditor(), diffProviderId); + if (util.getConfiguredQuickDiffProvider(newDiffer).equals(oldDifferId)) { + if (oldDiffer instanceof ILineDifferExtension) + ((ILineDifferExtension) oldDiffer).resume(); + return true; + } + + // quick diff is showing with the wrong provider - ask the user whether he wants to switch + IPreferenceStore store= EditorsUI.getPreferenceStore(); + if (oldDiffer != null && !store.getString(REVISION_ASK_BEFORE_QUICKDIFF_SWITCH_KEY).equals(MessageDialogWithToggle.ALWAYS)) { + MessageDialogWithToggle toggleDialog= MessageDialogWithToggle.openOkCancelConfirm( + fViewer.getTextWidget().getShell(), + STRulerMessages.AbstractDecoratedTextEditor_revision_quickdiff_switch_title, + STRulerMessages.AbstractDecoratedTextEditor_revision_quickdiff_switch_message, + STRulerMessages.AbstractDecoratedTextEditor_revision_quickdiff_switch_rememberquestion, + true, + store, + REVISION_ASK_BEFORE_QUICKDIFF_SWITCH_KEY); + if (toggleDialog.getReturnCode() != Window.OK) + return false; + } + + IAnnotationModelExtension modelExtension=(IAnnotationModelExtension) annotationModel; + modelExtension.removeAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID); + + + modelExtension.addAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID, newDiffer); + + if (fDelegate instanceof IChangeRulerColumn) + ((IChangeRulerColumn) fDelegate).setModel(annotationModel); // picks up the new model attachment + + return true; + } + + /** + * Installs the differ annotation model with the current quick diff display. + * + * @param column the column to install the model on + */ + private void installChangeRulerModel(IVerticalRulerColumn column) { + if (column instanceof IChangeRulerColumn) { + IAnnotationModel model= getAnnotationModelWithDiffer(); + ((IChangeRulerColumn) column).setModel(model); + if (model != null) { + ISourceViewer viewer= fViewer; + if (viewer != null && viewer.getAnnotationModel() == null) + viewer.showAnnotations(true); + } + } + } + + /** + * Uninstalls the differ annotation model from the current quick diff display. + * + * @param column the column to remove the model from + */ + private void uninstallChangeRulerModel(IVerticalRulerColumn column) { + if (column instanceof IChangeRulerColumn) + ((IChangeRulerColumn) column).setModel(null); + IAnnotationModel model= getDiffer(); + if (model instanceof ILineDifferExtension) + ((ILineDifferExtension) model).suspend(); + + ISourceViewer viewer= fViewer; + if (viewer != null && viewer.getAnnotationModel() == null) + viewer.showAnnotations(false); + } + + /** + * Returns the annotation model that contains the quick diff annotation model. + *

+ * Extracts the line differ from the displayed document's annotation model. If none can be found, + * a new differ is created and attached to the annotation model.

+ * + * @return the annotation model that contains the line differ, or null if none could be found or created + * @see IChangeRulerColumn#QUICK_DIFF_MODEL_ID + */ + private IAnnotationModel getAnnotationModelWithDiffer() { + ISourceViewer viewer= fViewer; + if (viewer == null) + return null; + + IAnnotationModel m= viewer.getAnnotationModel(); + IAnnotationModelExtension model= null; + if (m instanceof IAnnotationModelExtension) + model= (IAnnotationModelExtension) m; + + IAnnotationModel differ= getDiffer(); + // create diff model if it doesn't + if (differ == null) { + IPreferenceStore store= getPreferenceStore(); + if (store != null) { + String defaultId= store.getString(AbstractDecoratedTextEditorPreferenceConstants.QUICK_DIFF_DEFAULT_PROVIDER); + differ= new QuickDiff().createQuickDiffAnnotationModel(getEditor(), defaultId); + if (differ != null) { + if (model == null) + model= new AnnotationModel(); + model.addAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID, differ); + } + } + } else if (differ instanceof ILineDifferExtension2) { + if (((ILineDifferExtension2) differ).isSuspended()) + ((ILineDifferExtension) differ).resume(); + } else if (differ instanceof ILineDifferExtension) { + ((ILineDifferExtension) differ).resume(); + } + + return (IAnnotationModel)model; + } + + /** + * Extracts the line differ from the displayed document's annotation model. If none can be found, + * null is returned. + * + * @return the line differ, or null if none could be found + */ + private IAnnotationModel getDiffer() { + // get annotation model extension + ISourceViewer viewer= fViewer; + if (viewer == null) + return null; + + IAnnotationModel m= viewer.getAnnotationModel(); + if (m == null && fDelegate instanceof IChangeRulerColumn) + m= ((IChangeRulerColumn)fDelegate).getModel(); + + if (!(m instanceof IAnnotationModelExtension)) + return null; + + IAnnotationModelExtension model= (IAnnotationModelExtension)m; + + // get diff model if it exists already + return model.getAnnotationModel(IChangeRulerColumn.QUICK_DIFF_MODEL_ID); + } + + /** + * Sets the forwarder. Used by {@link AbstractDecoratedTextEditor} to maintain the contract of + * its {@link AbstractDecoratedTextEditor#createLineNumberRulerColumn} method. + * + * @param forwarder the forwarder + */ + public void setForwarder(ICompatibilityForwarder forwarder) { + fForwarder= forwarder; + fDelegate= forwarder.createSTRulerColumn(); + } + + /** + * Initializes the given line number ruler column from the preference store. + * + * @param rulerColumn the ruler column to be initialized + */ + public void initializeSTRulerColumn(STRulerColumn rulerColumn) { + IPreferenceStore store= getPreferenceStore(); + if (store != null) { + updateForegroundColor(store, rulerColumn); + updateBackgroundColor(store, rulerColumn); + updateLineNumbersVisibility(rulerColumn); + rulerColumn.redraw(); + } + } + + /** + * Returns true if the ruler is showing line numbers, false if it + * is only showing change information. + * + * @return true if line numbers are shown, false otherwise + */ + public boolean isShowingSTRuler() { + boolean b = fDelegate instanceof STRulerColumn && ((STChangeRulerColumn) fDelegate).isShowingSTRuler(); + return b; + } + + /** + * Returns true if the ruler is showing change information, false + * if it is only showing line numbers. + * + * @return true if change information is shown, false otherwise + */ + public boolean isShowingChangeInformation() { + return fDelegate instanceof STChangeRulerColumn && ((STChangeRulerColumn) fDelegate).isShowingChangeInformation(); + } + + /** + * Shows revision information on the receiver. + * + * @param info the revision information to show + * @param quickDiffProviderId the id of the corresponding quick diff provider + */ + public void showRevisionInformation(RevisionInformation info, String quickDiffProviderId) { + if (!ensureQuickDiffProvider(quickDiffProviderId)) + return; + + if (fDelegate instanceof IRevisionRulerColumn) + ((IRevisionRulerColumn) fDelegate).setRevisionInformation(info); + } + + /** + * Hides revision information. + */ + public void hideRevisionInformation() { + if (fDelegate instanceof IRevisionRulerColumn) + ((IRevisionRulerColumn) fDelegate).setRevisionInformation(null); + } + + /** + * Returns true if the ruler is showing revision information, false + * if it is only showing line numbers. + * + * @return true if revision information is shown, false otherwise + */ + public boolean isShowingRevisionInformation() { + if (fDelegate instanceof STChangeRulerColumn) + return ((STChangeRulerColumn) fDelegate).isShowingRevisionInformation(); + return false; + } + + /** + * Returns the selection provider of the revision column, null if none is + * available. + * + * @return the revision selection provider + */ + public ISelectionProvider getRevisionSelectionProvider() { + if (fDelegate instanceof IRevisionRulerColumnExtension) + return ((IRevisionRulerColumnExtension) fDelegate).getRevisionSelectionProvider(); + return null; + } + + +} diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STJFaceTextMessages.java b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STJFaceTextMessages.java new file mode 100644 index 0000000..410b5cf --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STJFaceTextMessages.java @@ -0,0 +1,67 @@ +/******************************************************************************* +02: * Copyright (c) 2000, 2005 IBM Corporation and others. +03: * All rights reserved. This program and the accompanying materials +04: * are made available under the terms of the Eclipse Public License v1.0 +05: * which accompanies this distribution, and is available at +06: * http://www.eclipse.org/legal/epl-v10.html +07: * +08: * Contributors: +09: * IBM Corporation - initial API and implementation +10: *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.annotatedsourceeditor; + +import java.text.MessageFormat; +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +/** + * Accessor for the JFaceTextMessages.properties file in + * package org.eclipse.jface.text. + * @since 2.0 + */ +class STJFaceTextMessages { + + /** The resource bundle name. */ + private static final String RESOURCE_BUNDLE= "org.eclipse.jface.text.JFaceTextMessages";//$NON-NLS-1$ + + /** The resource bundle. */ + private static ResourceBundle fgResourceBundle= ResourceBundle.getBundle(RESOURCE_BUNDLE); + + /** + * Prohibits the creation of accessor objects. + */ + private STJFaceTextMessages() { + } + + /** + * Returns the string found in the resource bundle under the given key or a place holder string. + * + * @param key the look up key + * @return the value found under the given key + */ + public static String getString(String key) { + try { + return fgResourceBundle.getString(key); + } catch (MissingResourceException e) { + return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$ + } + } + + /** + * Gets a string from the resource bundle and formats it with the argument + * + * @param key the string used to get the bundle value, must not be null + * @param args arguments used when formatting the string + * @return the formatted string + * @since 3.0 + */ + public static String getFormattedString(String key, Object[] args) { + String format= null; + try { + format= fgResourceBundle.getString(key); + } catch (MissingResourceException e) { + return "!" + key + "!";//$NON-NLS-2$ //$NON-NLS-1$ + } + return MessageFormat.format(format, args); + } +} diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STOverviewRuler.java b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STOverviewRuler.java new file mode 100644 index 0000000..cf7f084 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STOverviewRuler.java @@ -0,0 +1,1309 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.annotatedsourceeditor; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.custom.ViewForm; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.MouseAdapter; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseMoveListener; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; + +import org.eclipse.jface.text.JFaceTextUtil; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextListener; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.ITextViewerExtension5; +import org.eclipse.jface.text.Position; +import org.eclipse.jface.text.Region; +import org.eclipse.jface.text.TextEvent; +import org.eclipse.jface.text.source.Annotation; +import org.eclipse.jface.text.source.IAnnotationAccess; +import org.eclipse.jface.text.source.IAnnotationAccessExtension; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.jface.text.source.IAnnotationModelListener; +import org.eclipse.jface.text.source.IOverviewRuler; +import org.eclipse.jface.text.source.ISharedTextColors; +import org.eclipse.jface.text.source.projection.AnnotationBag; + +public class STOverviewRuler implements IOverviewRuler { + + /** + * Internal listener class. + */ + class InternalListener implements ITextListener, IAnnotationModelListener { + + /* + * @see ITextListener#textChanged + */ + public void textChanged(TextEvent e) { + if (fTextViewer != null && e.getDocumentEvent() == null && e.getViewerRedrawState()) { + // handle only changes of visible document + redraw(); + } + } + + /* + * @see IAnnotationModelListener#modelChanged(IAnnotationModel) + */ + public void modelChanged(IAnnotationModel model) { + update(); + } + } + + /** + * Enumerates the annotations of a specified type and characteristics + * of the associated annotation model. + */ + class FilterIterator implements Iterator { + + final static int TEMPORARY= 1 << 1; + final static int PERSISTENT= 1 << 2; + final static int IGNORE_BAGS= 1 << 3; + + private Iterator fIterator; + private Object fType; + private Annotation fNext; + private int fStyle; + + /** + * Creates a new filter iterator with the given specification. + * + * @param annotationType the annotation type + * @param style the style + */ + public FilterIterator(Object annotationType, int style) { + fType= annotationType; + fStyle= style; + if (fModel != null) { + fIterator= fModel.getAnnotationIterator(); + skip(); + } + } + + /** + * Creates a new filter iterator with the given specification. + * + * @param annotationType the annotation type + * @param style the style + * @param iterator the iterator + */ + public FilterIterator(Object annotationType, int style, Iterator iterator) { + fType= annotationType; + fStyle= style; + fIterator= iterator; + skip(); + } + + private void skip() { + + boolean temp= (fStyle & TEMPORARY) != 0; + boolean pers= (fStyle & PERSISTENT) != 0; + boolean ignr= (fStyle & IGNORE_BAGS) != 0; + + while (fIterator.hasNext()) { + Annotation next= (Annotation) fIterator.next(); + + if (next.isMarkedDeleted()) + continue; + + if (ignr && (next instanceof AnnotationBag)) + continue; + + fNext= next; + Object annotationType= next.getType(); + if (fType == null || isSubtype(annotationType)) { + if (temp && pers) return; + if (pers && next.isPersistent()) return; + if (temp && !next.isPersistent()) return; + } + } + fNext= null; + } + + private boolean isSubtype(Object annotationType) { + if (fAnnotationAccess instanceof IAnnotationAccessExtension) { + IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess; + return extension.isSubtype(annotationType, fType); + } + return fType.equals(annotationType); + } + + /* + * @see Iterator#hasNext() + */ + public boolean hasNext() { + return fNext != null; + } + /* + * @see Iterator#next() + */ + public Annotation next() { + try { + return fNext; + } finally { + if (fIterator != null) + skip(); + } + } + /* + * @see Iterator#remove() + */ + public void remove() { + throw new UnsupportedOperationException(); + } + } + + /** + * The painter of the overview ruler's header. + */ + class HeaderPainter implements PaintListener { + + private Color fIndicatorColor; + private Color fSeparatorColor; + + /** + * Creates a new header painter. + */ + public HeaderPainter() { + fSeparatorColor= fSharedTextColors.getColor(ViewForm.borderInsideRGB); + } + + /** + * Sets the header color. + * + * @param color the header color + */ + public void setColor(Color color) { + fIndicatorColor= color; + } + + private void drawBevelRect(GC gc, int x, int y, int w, int h, Color topLeft, Color bottomRight) { + gc.setForeground(topLeft == null ? fSeparatorColor : topLeft); + gc.drawLine(x, y, x + w -1, y); + gc.drawLine(x, y, x, y + h -1); + + gc.setForeground(bottomRight == null ? fSeparatorColor : bottomRight); + gc.drawLine(x + w, y, x + w, y + h); + gc.drawLine(x, y + h, x + w, y + h); + } + + public void paintControl(PaintEvent e) { + + Point s= fHeader.getSize(); + + if (fIndicatorColor != null) { + e.gc.setBackground(fIndicatorColor); + Rectangle r= new Rectangle(INSET, (s.y - (2*ANNOTATION_HEIGHT)) / 2, s.x - (2*INSET), 2*ANNOTATION_HEIGHT); + e.gc.fillRectangle(r); + Display d= fHeader.getDisplay(); + if (d != null) +// drawBevelRect(e.gc, r.x, r.y, r.width -1, r.height -1, d.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW), d.getSystemColor(SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW)); + drawBevelRect(e.gc, r.x, r.y, r.width -1, r.height -1, null, null); + } + + e.gc.setForeground(fSeparatorColor); + e.gc.setLineWidth(1); + e.gc.drawLine(0, s.y -1, s.x -1, s.y -1); + } + } + + private static final int INSET= 2; + private static final int ANNOTATION_HEIGHT= 1; + private static boolean ANNOTATION_HEIGHT_SCALABLE= true; + + + /** The model of the overview ruler */ + private IAnnotationModel fModel; + /** The view to which this ruler is connected */ + private ITextViewer fTextViewer; + /** The ruler's canvas */ + private Canvas fCanvas; + /** The ruler's header */ + private Canvas fHeader; + /** The buffer for double buffering */ + private Image fBuffer; + /** The internal listener */ + private InternalListener fInternalListener= new InternalListener(); + /** The width of this vertical ruler */ + private int fWidth; + /** The hit detection cursor */ + private Cursor fHitDetectionCursor; + /** The last cursor */ + private Cursor fLastCursor; + /** The line of the last mouse button activity */ + private int fLastMouseButtonActivityLine= -1; + /** The actual annotation height */ + private int fAnnotationHeight= -1; + /** The annotation access */ + private IAnnotationAccess fAnnotationAccess; + /** The header painter */ + private HeaderPainter fHeaderPainter; + /** + * The list of annotation types to be shown in this ruler. + * @since 3.0 + */ + private Set fConfiguredAnnotationTypes= new HashSet(); + /** + * The list of annotation types to be shown in the header of this ruler. + * @since 3.0 + */ + private Set fConfiguredHeaderAnnotationTypes= new HashSet(); + /** The mapping between annotation types and colors */ + private Map fAnnotationTypes2Colors= new HashMap(); + + /** The mapping between annotation and colors */ + private Map fAnnotationColors = new HashMap(); + + /** The color manager */ + private ISharedTextColors fSharedTextColors; + /** + * All available annotation types sorted by layer. + * + * @since 3.0 + */ + private List fAnnotationsSortedByLayer= new ArrayList(); + /** + * All available layers sorted by layer. + * This list may contain duplicates. + * @since 3.0 + */ + private List fLayersSortedByLayer= new ArrayList(); + /** + * Map of allowed annotation types. + * An allowed annotation type maps to true, a disallowed + * to false. + * @since 3.0 + */ + private Map fAllowedAnnotationTypes= new HashMap(); + /** + * Map of allowed header annotation types. + * An allowed annotation type maps to true, a disallowed + * to false. + * @since 3.0 + */ + private Map fAllowedHeaderAnnotationTypes= new HashMap(); + /** + * The cached annotations. + * @since 3.0 + */ + private List fCachedAnnotations= new ArrayList(); + + + /** + * Constructs a overview ruler of the given width using the given annotation access and the given + * color manager. + * + * @param annotationAccess the annotation access + * @param width the width of the vertical ruler + * @param sharedColors the color manager + */ + public STOverviewRuler(IAnnotationAccess annotationAccess, int width, ISharedTextColors sharedColors) { + fAnnotationAccess= annotationAccess; + fWidth= width; + fSharedTextColors= sharedColors; + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRulerInfo#getControl() + */ + public Control getControl() { + return fCanvas; + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRulerInfo#getWidth() + */ + public int getWidth() { + return fWidth; + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRuler#setModel(org.eclipse.jface.text.source.IAnnotationModel) + */ + public void setModel(IAnnotationModel model) { + if (model != fModel || model != null) { + + if (fModel != null) + fModel.removeAnnotationModelListener(fInternalListener); + + fModel= model; + + if (fModel != null) + fModel.addAnnotationModelListener(fInternalListener); + + update(); + } + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRuler#createControl(org.eclipse.swt.widgets.Composite, org.eclipse.jface.text.ITextViewer) + */ + public Control createControl(Composite parent, ITextViewer textViewer) { + + fTextViewer= textViewer; + + fHitDetectionCursor= new Cursor(parent.getDisplay(), SWT.CURSOR_HAND); + + fHeader= new Canvas(parent, SWT.NONE); + + fCanvas= new Canvas(parent, SWT.NO_BACKGROUND); + + fCanvas.addPaintListener(new PaintListener() { + public void paintControl(PaintEvent event) { + if (fTextViewer != null) + doubleBufferPaint(event.gc); + } + }); + + fCanvas.addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent event) { + handleDispose(); + fTextViewer= null; + } + }); + + fCanvas.addMouseListener(new MouseAdapter() { + public void mouseDown(MouseEvent event) { + handleMouseDown(event); + } + }); + + fCanvas.addMouseMoveListener(new MouseMoveListener() { + public void mouseMove(MouseEvent event) { + handleMouseMove(event); + } + }); + + if (fTextViewer != null) + fTextViewer.addTextListener(fInternalListener); + + return fCanvas; + } + + /** + * Disposes the ruler's resources. + */ + private void handleDispose() { + + if (fTextViewer != null) { + fTextViewer.removeTextListener(fInternalListener); + fTextViewer= null; + } + + if (fModel != null) + fModel.removeAnnotationModelListener(fInternalListener); + + if (fBuffer != null) { + fBuffer.dispose(); + fBuffer= null; + } + + if (fHitDetectionCursor != null) { + fHitDetectionCursor.dispose(); + fHitDetectionCursor= null; + } + + fConfiguredAnnotationTypes.clear(); + fAllowedAnnotationTypes.clear(); + fConfiguredHeaderAnnotationTypes.clear(); + fAllowedHeaderAnnotationTypes.clear(); + fAnnotationTypes2Colors.clear(); + fAnnotationsSortedByLayer.clear(); + fLayersSortedByLayer.clear(); + } + + /** + * Double buffer drawing. + * + * @param dest the GC to draw into + */ + private void doubleBufferPaint(GC dest) { + + Point size= fCanvas.getSize(); + + if (size.x <= 0 || size.y <= 0) + return; + + if (fBuffer != null) { + Rectangle r= fBuffer.getBounds(); + if (r.width != size.x || r.height != size.y) { + fBuffer.dispose(); + fBuffer= null; + } + } + if (fBuffer == null) + fBuffer= new Image(fCanvas.getDisplay(), size.x, size.y); + + GC gc= new GC(fBuffer); + try { + gc.setBackground(fCanvas.getBackground()); + gc.fillRectangle(0, 0, size.x, size.y); + + if (fTextViewer instanceof ITextViewerExtension5) + doPaint1(gc); + else + doPaint(gc); + + } finally { + gc.dispose(); + } + + dest.drawImage(fBuffer, 0, 0); + } + + /** + * Draws this overview ruler. + * + * @param gc the GC to draw into + */ + private void doPaint(GC gc) { + Rectangle r= new Rectangle(0, 0, 0, 0); + int yy, hh= ANNOTATION_HEIGHT; + + IDocument document= fTextViewer.getDocument(); + IRegion visible= fTextViewer.getVisibleRegion(); + + StyledText textWidget= fTextViewer.getTextWidget(); + int maxLines= textWidget.getLineCount(); + + Point size= fCanvas.getSize(); + int writable= JFaceTextUtil.computeLineHeight(textWidget, 0, maxLines, maxLines); + + if (size.y > writable) + size.y= Math.max(writable - fHeader.getSize().y, 0); + + for (Iterator iterator= fAnnotationsSortedByLayer.iterator(); iterator.hasNext();) { + Object annotationType= iterator.next(); + + if (skip(annotationType)) + continue; + + int[] style= new int[] { FilterIterator.PERSISTENT, FilterIterator.TEMPORARY }; + for (int t=0; t < style.length; t++) { + Color fill = null; + Color stroke = null; + FilterIterator e = new FilterIterator(annotationType, style[t]); + if (annotationType.toString().compareTo(getAnnotationTypeColoredLines()) != 0){ + fill= getFillColor(annotationType, style[t] == FilterIterator.TEMPORARY); + stroke= getStrokeColor(annotationType, style[t] == FilterIterator.TEMPORARY); + } + + for (int i= 0; e.hasNext(); i++) { + + Annotation a= e.next(); + Position p= fModel.getPosition(a); + + if (p == null || !p.overlapsWith(visible.getOffset(), visible.getLength())) + continue; + + + if (a.getType().compareTo(getAnnotationTypeColoredLines()) == 0){ + fill= getFPFillColor(a, true); + stroke= getFPStrokeColor(a, false); + } + + int annotationOffset= Math.max(p.getOffset(), visible.getOffset()); + int annotationEnd= Math.min(p.getOffset() + p.getLength(), visible.getOffset() + visible.getLength()); + int annotationLength= annotationEnd - annotationOffset; + + try { + if (ANNOTATION_HEIGHT_SCALABLE) { + int numbersOfLines= document.getNumberOfLines(annotationOffset, annotationLength); + // don't count empty trailing lines + IRegion lastLine= document.getLineInformationOfOffset(annotationOffset + annotationLength); + if (lastLine.getOffset() == annotationOffset + annotationLength) { + numbersOfLines -= 2; + hh= (numbersOfLines * size.y) / maxLines + ANNOTATION_HEIGHT; + if (hh < ANNOTATION_HEIGHT) + hh= ANNOTATION_HEIGHT; + } else + hh= ANNOTATION_HEIGHT; + } + fAnnotationHeight= hh; + + int startLine= textWidget.getLineAtOffset(annotationOffset - visible.getOffset()); + yy= Math.min((startLine * size.y) / maxLines, size.y - hh); + + if (fill != null) { + gc.setBackground(fill); + gc.fillRectangle(INSET, yy, size.x-(2*INSET), hh); + } + + if (stroke != null) { + gc.setForeground(stroke); + r.x= INSET; + r.y= yy; + r.width= size.x - (2 * INSET); + r.height= hh; + gc.setLineWidth(1); + gc.drawRectangle(r); + } + } catch (BadLocationException x) { + } + } + } + } + } + + /** + * Draws this overview ruler. Uses ITextViewerExtension5 for + * its implementation. Will replace doPaint(GC). + * + * @param gc the GC to draw into + */ + private void doPaint1(GC gc) { + Rectangle r= new Rectangle(0, 0, 0, 0); + int yy, hh= ANNOTATION_HEIGHT; + + ITextViewerExtension5 extension= (ITextViewerExtension5) fTextViewer; + IDocument document= fTextViewer.getDocument(); + StyledText textWidget= fTextViewer.getTextWidget(); + + int maxLines= textWidget.getLineCount(); + Point size= fCanvas.getSize(); + int writable= JFaceTextUtil.computeLineHeight(textWidget, 0, maxLines, maxLines); + if (size.y > writable) + size.y= Math.max(writable - fHeader.getSize().y, 0); + + fCachedAnnotations.clear(); + if (fModel != null) { + Iterator iter= fModel.getAnnotationIterator(); + while (iter.hasNext()) { + Annotation annotation= (Annotation) iter.next(); + + if (annotation.isMarkedDeleted()) + continue; + + if (skip(annotation.getType())) + continue; + + fCachedAnnotations.add(annotation); + } + } + + for (Iterator iterator= fAnnotationsSortedByLayer.iterator(); iterator.hasNext();) { + Object annotationType= iterator.next(); + + if (skip(annotationType)) + continue; + + int[] style= new int[] { FilterIterator.PERSISTENT, FilterIterator.TEMPORARY }; + for (int t=0; t < style.length; t++) { + + FilterIterator e= new FilterIterator(annotationType, style[t], fCachedAnnotations.iterator()); + Color fill = null; + Color stroke = null; + if (annotationType.toString().compareTo(getAnnotationTypeColoredLines()) != 0){ + fill= getFillColor(annotationType, style[t] == FilterIterator.TEMPORARY); + stroke= getStrokeColor(annotationType, style[t] == FilterIterator.TEMPORARY); + } + + for (int i= 0; e.hasNext(); i++) { + + Annotation a= e.next(); + + + Position p= fModel.getPosition(a); + + if (p == null) + continue; + + IRegion widgetRegion= extension.modelRange2WidgetRange(new Region(p.getOffset(), p.getLength())); + if (widgetRegion == null) + continue; + + if (a.getType().compareTo(getAnnotationTypeColoredLines()) == 0){ + fill= getFPFillColor(a, true); + stroke= getFPStrokeColor(a, false); + } + + try { + if (ANNOTATION_HEIGHT_SCALABLE) { + int numbersOfLines= document.getNumberOfLines(p.getOffset(), p.getLength()); + // don't count empty trailing lines + IRegion lastLine= document.getLineInformationOfOffset(p.getOffset() + p.getLength()); + if (lastLine.getOffset() == p.getOffset() + p.getLength()) { + numbersOfLines -= 2; + hh= (numbersOfLines * size.y) / maxLines + ANNOTATION_HEIGHT; + if (hh < ANNOTATION_HEIGHT) + hh= ANNOTATION_HEIGHT; + } else + hh= ANNOTATION_HEIGHT; + } + fAnnotationHeight= hh; + + int startLine= textWidget.getLineAtOffset(widgetRegion.getOffset()); + yy= Math.min((startLine * size.y) / maxLines, size.y - hh); + + if (fill != null) { + gc.setBackground(fill); + gc.fillRectangle(INSET, yy, size.x-(2*INSET), hh); + } + + if (stroke != null) { + gc.setForeground(stroke); + r.x= INSET; + r.y= yy; + r.width= size.x - (2 * INSET); + r.height= hh; + gc.setLineWidth(1); + gc.drawRectangle(r); + } + } catch (BadLocationException x) { + } + } + } + } + fCachedAnnotations.clear(); + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRuler#update() + */ + public void update() { + if (fCanvas != null && !fCanvas.isDisposed()) { + Display d= fCanvas.getDisplay(); + if (d != null) { + d.asyncExec(new Runnable() { + public void run() { + redraw(); + updateHeader(); + } + }); + } + } + } + + /** + * Redraws the overview ruler. + */ + private void redraw() { + + if (fTextViewer == null || fModel == null) + return; + + if (fCanvas != null && !fCanvas.isDisposed()) { + GC gc= new GC(fCanvas); + doubleBufferPaint(gc); + gc.dispose(); + } + } + + /** + * Translates a given y-coordinate of this ruler into the corresponding + * document lines. The number of lines depends on the concrete scaling + * given as the ration between the height of this ruler and the length + * of the document. + * + * @param y_coordinate the y-coordinate + * @return the corresponding document lines + */ + private int[] toLineNumbers(int y_coordinate) { + + StyledText textWidget= fTextViewer.getTextWidget(); + int maxLines= textWidget.getContent().getLineCount(); + + int rulerLength= fCanvas.getSize().y; + int writable= JFaceTextUtil.computeLineHeight(textWidget, 0, maxLines, maxLines); + + if (rulerLength > writable) + rulerLength= Math.max(writable - fHeader.getSize().y, 0); + + if (y_coordinate >= writable || y_coordinate >= rulerLength) + return new int[] {-1, -1}; + + int[] lines= new int[2]; + + int pixel0= Math.max(y_coordinate - 1, 0); + int pixel1= Math.min(rulerLength, y_coordinate + 1); + rulerLength= Math.max(rulerLength, 1); + + lines[0]= (pixel0 * maxLines) / rulerLength; + lines[1]= (pixel1 * maxLines) / rulerLength; + + if (fTextViewer instanceof ITextViewerExtension5) { + ITextViewerExtension5 extension= (ITextViewerExtension5) fTextViewer; + lines[0]= extension.widgetLine2ModelLine(lines[0]); + lines[1]= extension.widgetLine2ModelLine(lines[1]); + } else { + try { + IRegion visible= fTextViewer.getVisibleRegion(); + int lineNumber= fTextViewer.getDocument().getLineOfOffset(visible.getOffset()); + lines[0] += lineNumber; + lines[1] += lineNumber; + } catch (BadLocationException x) { + } + } + + return lines; + } + + /** + * Returns the position of the first annotation found in the given line range. + * + * @param lineNumbers the line range + * @param ignoreSelectedAnnotation whether to ignore the current selection + * @return the position of the first found annotation + */ + private Position getAnnotationPosition(int[] lineNumbers, boolean ignoreSelectedAnnotation) { + if (lineNumbers[0] == -1) + return null; + + Position found= null; + + try { + IDocument d= fTextViewer.getDocument(); + IRegion line= d.getLineInformation(lineNumbers[0]); + + Point currentSelection= fTextViewer.getSelectedRange(); + + int start= line.getOffset(); + + line= d.getLineInformation(lineNumbers[lineNumbers.length - 1]); + int end= line.getOffset() + line.getLength(); + + for (int i= fAnnotationsSortedByLayer.size() -1; i >= 0; i--) { + + Object annotationType= fAnnotationsSortedByLayer.get(i); + + FilterIterator e= new FilterIterator(annotationType, FilterIterator.PERSISTENT | FilterIterator.TEMPORARY); + while (e.hasNext() && found == null) { + Annotation a= e.next(); + if (a.isMarkedDeleted()) + continue; + + if (skip(a.getType())) + continue; + + Position p= fModel.getPosition(a); + if (p == null) + continue; + + int posOffset= p.getOffset(); + int posEnd= posOffset + p.getLength(); + IRegion region= d.getLineInformationOfOffset(posEnd); + // trailing empty lines don't count + if (posEnd > posOffset && region.getOffset() == posEnd) { + posEnd--; + region= d.getLineInformationOfOffset(posEnd); + } + + if (posOffset <= end && posEnd >= start) { + if (ignoreSelectedAnnotation || currentSelection.x != posOffset || currentSelection.y != p.getLength()) + found= p; + } + } + } + } catch (BadLocationException x) { + } + + return found; + } + + /** + * Returns the line which corresponds best to one of + * the underlying annotations at the given y-coordinate. + * + * @param lineNumbers the line numbers + * @return the best matching line or -1 if no such line can be found + */ + private int findBestMatchingLineNumber(int[] lineNumbers) { + if (lineNumbers == null || lineNumbers.length < 1) + return -1; + + try { + Position pos= getAnnotationPosition(lineNumbers, true); + if (pos == null) + return -1; + return fTextViewer.getDocument().getLineOfOffset(pos.getOffset()); + } catch (BadLocationException ex) { + return -1; + } + } + + /** + * Handles mouse clicks. + * + * @param event the mouse button down event + */ + private void handleMouseDown(MouseEvent event) { + if (fTextViewer != null) { + int[] lines= toLineNumbers(event.y); + Position p= getAnnotationPosition(lines, false); + if (p != null) { + fTextViewer.revealRange(p.getOffset(), p.getLength()); + fTextViewer.setSelectedRange(p.getOffset(), p.getLength()); + } + fTextViewer.getTextWidget().setFocus(); + } + fLastMouseButtonActivityLine= toDocumentLineNumber(event.y); + } + + /** + * Handles mouse moves. + * + * @param event the mouse move event + */ + private void handleMouseMove(MouseEvent event) { + if (fTextViewer != null) { + int[] lines= toLineNumbers(event.y); + Position p= getAnnotationPosition(lines, true); + Cursor cursor= (p != null ? fHitDetectionCursor : null); + if (cursor != fLastCursor) { + fCanvas.setCursor(cursor); + fLastCursor= cursor; + } + } + } + + /* + * @see org.eclipse.jface.text.source.IOverviewRuler#addAnnotationType(java.lang.Object) + */ + public void addAnnotationType(Object annotationType) { + fConfiguredAnnotationTypes.add(annotationType); + fAllowedAnnotationTypes.clear(); + } + + /* + * @see org.eclipse.jface.text.source.IOverviewRuler#removeAnnotationType(java.lang.Object) + */ + public void removeAnnotationType(Object annotationType) { + fConfiguredAnnotationTypes.remove(annotationType); + fAllowedAnnotationTypes.clear(); + } + + /* + * @see org.eclipse.jface.text.source.IOverviewRuler#setAnnotationTypeLayer(java.lang.Object, int) + */ + public void setAnnotationTypeLayer(Object annotationType, int layer) { + int j= fAnnotationsSortedByLayer.indexOf(annotationType); + if (j != -1) { + fAnnotationsSortedByLayer.remove(j); + fLayersSortedByLayer.remove(j); + } + + if (layer >= 0) { + int i= 0; + int size= fLayersSortedByLayer.size(); + while (i < size && layer >= fLayersSortedByLayer.get(i)) + i++; + fLayersSortedByLayer.add(i, layer); + fAnnotationsSortedByLayer.add(i, annotationType); + } + } + + /* + * @see org.eclipse.jface.text.source.IOverviewRuler#setAnnotationTypeColor(java.lang.Object, org.eclipse.swt.graphics.Color) + */ + + public void setAnnotationColor(Annotation annotation,Color color){ + if (color != null) + fAnnotationColors.put(annotation, color); + else + fAnnotationColors.remove(annotation); + } + + + public void setAnnotationTypeColor(Object annotationType, Color color) { + if (color != null) + fAnnotationTypes2Colors.put(annotationType, color); + else + fAnnotationTypes2Colors.remove(annotationType); + } + + /** + * Returns whether the given annotation type should be skipped by the drawing routine. + * + * @param annotationType the annotation type + * @return true if annotation of the given type should be skipped + */ + private boolean skip(Object annotationType) { + return !contains(annotationType, fAllowedAnnotationTypes, fConfiguredAnnotationTypes); + } + + /** + * Returns whether the given annotation type should be skipped by the drawing routine of the header. + * + * @param annotationType the annotation type + * @return true if annotation of the given type should be skipped + * @since 3.0 + */ + private boolean skipInHeader(Object annotationType) { + return !contains(annotationType, fAllowedHeaderAnnotationTypes, fConfiguredHeaderAnnotationTypes); + } + + /** + * Returns whether the given annotation type is mapped to true + * in the given allowed map or covered by the configured + * set. + * + * @param annotationType the annotation type + * @param allowed the map with allowed annotation types mapped to booleans + * @param configured the set with configured annotation types + * @return true if annotation is contained, false + * otherwise + * @since 3.0 + */ + private boolean contains(Object annotationType, Map allowed, Set configured) { + Boolean cached= (Boolean) allowed.get(annotationType); + if (cached != null) + return cached.booleanValue(); + + boolean covered= isCovered(annotationType, configured); + allowed.put(annotationType, covered ? Boolean.TRUE : Boolean.FALSE); + return covered; + } + + /** + * Computes whether the annotations of the given type are covered by the given configured + * set. This is the case if either the type of the annotation or any of its + * super types is contained in the configured set. + * + * @param annotationType the annotation type + * @param configured the set with configured annotation types + * @return true if annotation is covered, false + * otherwise + * @since 3.0 + */ + private boolean isCovered(Object annotationType, Set configured) { + if (fAnnotationAccess instanceof IAnnotationAccessExtension) { + IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess; + Iterator e= configured.iterator(); + while (e.hasNext()) { + if (extension.isSubtype(annotationType,e.next())) + return true; + } + return false; + } + return configured.contains(annotationType); + } + + /** + * Returns a specification of a color that lies between the given + * foreground and background color using the given scale factor. + * + * @param fg the foreground color + * @param bg the background color + * @param scale the scale factor + * @return the interpolated color + */ + private static RGB interpolate(RGB fg, RGB bg, double scale) { + return new RGB( + (int) ((1.0-scale) * fg.red + scale * bg.red), + (int) ((1.0-scale) * fg.green + scale * bg.green), + (int) ((1.0-scale) * fg.blue + scale * bg.blue) + ); + } + + /** + * Returns the grey value in which the given color would be drawn in grey-scale. + * + * @param rgb the color + * @return the grey-scale value + */ + private static double greyLevel(RGB rgb) { + if (rgb.red == rgb.green && rgb.green == rgb.blue) + return rgb.red; + return (0.299 * rgb.red + 0.587 * rgb.green + 0.114 * rgb.blue + 0.5); + } + + /** + * Returns whether the given color is dark or light depending on the colors grey-scale level. + * + * @param rgb the color + * @return true if the color is dark, false if it is light + */ + private static boolean isDark(RGB rgb) { + return greyLevel(rgb) > 128; + } + + /** + * Returns a color based on the color configured for the given annotation type and the given scale factor. + * + * @param annotationType the annotation type + * @param scale the scale factor + * @return the computed color + */ + private Color getColor(Object annotationType, double scale) { + Color base= findColor(annotationType); + return getInterpolatedColor(base,scale); + } + + + private Color getFPColor(Object annotation, double scale){ + Color base= (Color) fAnnotationColors.get(annotation); + return getInterpolatedColor(base,scale); + } + + private Color getInterpolatedColor(Color base,double scale){ + if (base == null) + return null; + + RGB baseRGB= base.getRGB(); + RGB background= fCanvas.getBackground().getRGB(); + + boolean darkBase= isDark(baseRGB); + boolean darkBackground= isDark(background); + if (darkBase && darkBackground) + background= new RGB(255, 255, 255); + else if (!darkBase && !darkBackground) + background= new RGB(0, 0, 0); + + return fSharedTextColors.getColor(interpolate(baseRGB, background, scale)); + + } + + + /** + * Returns the color for the given annotation type + * + * @param annotationType the annotation type + * @return the color + * @since 3.0 + */ + private Color findColor(Object annotationType) { + Color color= (Color) fAnnotationTypes2Colors.get(annotationType); + if (color != null) + return color; + + if (fAnnotationAccess instanceof IAnnotationAccessExtension) { + IAnnotationAccessExtension extension= (IAnnotationAccessExtension) fAnnotationAccess; + Object[] superTypes= extension.getSupertypes(annotationType); + if (superTypes != null) { + for (int i= 0; i < superTypes.length; i++) { + color= (Color) fAnnotationTypes2Colors.get(superTypes[i]); + if (color != null) + return color; + } + } + } + + return null; + } + + /** + * Returns the stroke color for the given annotation type and characteristics. + * + * @param annotationType the annotation type + * @param temporary true if for temporary annotations + * @return the stroke color + */ + private Color getStrokeColor(Object annotationType, boolean temporary) { + return getColor(annotationType, temporary ? 0.5 : 0.2); + } + + + private Color getFPStrokeColor(Object annotation, boolean temporary) { + return getFPColor(annotation, temporary ? 0.5 : 0.2); + } + + /** + * Returns the fill color for the given annotation type and characteristics. + * + * @param annotationType the annotation type + * @param temporary true if for temporary annotations + * @return the fill color + */ + private Color getFillColor(Object annotationType, boolean temporary) { + return getColor(annotationType, temporary ? 0.9 : 0.6); + } + + private Color getFPFillColor(Object annotation, boolean temporary){ + return getFPColor(annotation, temporary ? 0.9 : 0.6); + } + + /* + * @see IVerticalRulerInfo#getLineOfLastMouseButtonActivity() + */ + public int getLineOfLastMouseButtonActivity() { + return fLastMouseButtonActivityLine; + } + + /* + * @see IVerticalRulerInfo#toDocumentLineNumber(int) + */ + public int toDocumentLineNumber(int y_coordinate) { + + if (fTextViewer == null || y_coordinate == -1) + return -1; + + int[] lineNumbers= toLineNumbers(y_coordinate); + int bestLine= findBestMatchingLineNumber(lineNumbers); + if (bestLine == -1 && lineNumbers.length > 0) + return lineNumbers[0]; + return bestLine; + } + + /* + * @see org.eclipse.jface.text.source.IVerticalRuler#getModel() + */ + public IAnnotationModel getModel() { + return fModel; + } + + /* + * @see org.eclipse.jface.text.source.IOverviewRuler#getAnnotationHeight() + */ + public int getAnnotationHeight() { + return fAnnotationHeight; + } + + /* + * @see org.eclipse.jface.text.source.IOverviewRuler#hasAnnotation(int) + */ + public boolean hasAnnotation(int y) { + return findBestMatchingLineNumber(toLineNumbers(y)) != -1; + } + + /* + * @see org.eclipse.jface.text.source.IOverviewRuler#getHeaderControl() + */ + public Control getHeaderControl() { + return fHeader; + } + + /* + * @see org.eclipse.jface.text.source.IOverviewRuler#addHeaderAnnotationType(java.lang.Object) + */ + public void addHeaderAnnotationType(Object annotationType) { + fConfiguredHeaderAnnotationTypes.add(annotationType); + fAllowedHeaderAnnotationTypes.clear(); + } + + /* + * @see org.eclipse.jface.text.source.IOverviewRuler#removeHeaderAnnotationType(java.lang.Object) + */ + public void removeHeaderAnnotationType(Object annotationType) { + fConfiguredHeaderAnnotationTypes.remove(annotationType); + fAllowedHeaderAnnotationTypes.clear(); + } + + /** + * Updates the header of this ruler. + */ + private void updateHeader() { + + if (fHeader == null || fHeader.isDisposed()) + return; + + Object colorType= null; + outer: for (int i= fAnnotationsSortedByLayer.size() -1; i >= 0; i--) { + + Object annotationType= fAnnotationsSortedByLayer.get(i); + + if (skipInHeader(annotationType) || skip(annotationType)) + continue; + + for (FilterIterator e= new FilterIterator(annotationType, FilterIterator.PERSISTENT | FilterIterator.TEMPORARY | FilterIterator.IGNORE_BAGS); e.hasNext();) { + if (e.next() != null) { + colorType= annotationType; + break outer; + } + } + } + + Color color= null; + if (colorType != null) + color= findColor(colorType); + + if (color == null) { + if (fHeaderPainter != null) + fHeaderPainter.setColor(null); + } else { + if (fHeaderPainter == null) { + fHeaderPainter= new HeaderPainter(); + fHeader.addPaintListener(fHeaderPainter); + } + fHeaderPainter.setColor(color); + } + + fHeader.redraw(); + updateHeaderToolTipText(); + } + + /** + * Updates the tool tip text of the header of this ruler. + * + * @since 3.0 + */ + private void updateHeaderToolTipText() { + + if (fHeader == null || fHeader.isDisposed()) + return; + + fHeader.setToolTipText(null); + + if (!(fAnnotationAccess instanceof IAnnotationAccessExtension)) + return; + + String overview= ""; //$NON-NLS-1$ + + for (int i= fAnnotationsSortedByLayer.size() -1; i >= 0; i--) { + + Object annotationType= fAnnotationsSortedByLayer.get(i); + + if (skipInHeader(annotationType) || skip(annotationType)) + continue; + + int count= 0; + String annotationTypeLabel= null; + + for (FilterIterator e= new FilterIterator(annotationType, FilterIterator.PERSISTENT | FilterIterator.TEMPORARY | FilterIterator.IGNORE_BAGS); e.hasNext();) { + Annotation annotation= e.next(); + if (annotation != null) { + if (annotationTypeLabel == null) + annotationTypeLabel= ((IAnnotationAccessExtension)fAnnotationAccess).getTypeLabel(annotation); + count++; + } + } + + if (annotationTypeLabel != null) { + if (overview.length() > 0) + overview += "\n"; //$NON-NLS-1$ + overview += STJFaceTextMessages.getFormattedString("OverviewRulerHeader.toolTipTextEntry", new Object[] {annotationTypeLabel, new Integer(count)}); //$NON-NLS-1$ + } + } + if (overview.length() > 0) + fHeader.setToolTipText(overview); + } + + private String getAnnotationTypeColoredLines(){ + return (STAnnotatedSourceEditorActivator.getUniqueIdentifier() + STAnnotatedSourceEditorActivator.getAnnotationType()); + } +} + diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STRulerColumn.java b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STRulerColumn.java new file mode 100644 index 0000000..8af7be3 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STRulerColumn.java @@ -0,0 +1,876 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.annotatedsourceeditor; + +import java.util.Arrays; + +import org.eclipse.jface.text.BadLocationException; +import org.eclipse.jface.text.IDocument; +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextListener; +import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.ITextViewerExtension; +import org.eclipse.jface.text.IViewportListener; +import org.eclipse.jface.text.JFaceTextUtil; +import org.eclipse.jface.text.TextEvent; +import org.eclipse.jface.text.source.CompositeRuler; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.jface.text.source.ILineRange; +import org.eclipse.jface.text.source.IVerticalRulerColumn; +import org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.hyperlink.ISTAnnotationHyperlink; +import org.eclipse.swt.SWT; +import org.eclipse.swt.custom.StyledText; +import org.eclipse.swt.events.DisposeEvent; +import org.eclipse.swt.events.DisposeListener; +import org.eclipse.swt.events.MouseEvent; +import org.eclipse.swt.events.MouseListener; +import org.eclipse.swt.events.MouseMoveListener; +import org.eclipse.swt.events.MouseTrackListener; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Cursor; +import org.eclipse.swt.graphics.Font; +import org.eclipse.swt.graphics.FontMetrics; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; +import org.eclipse.swt.graphics.Rectangle; +import org.eclipse.swt.graphics.TextLayout; +import org.eclipse.swt.graphics.TextStyle; +import org.eclipse.swt.widgets.Canvas; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Display; + + +public class STRulerColumn implements IVerticalRulerColumn{ + /** + * Internal listener class. + */ + class InternalListener implements IViewportListener, ITextListener { + + /** + * @since 3.1 + */ + private boolean fCachedRedrawState= true; + + /* + * @see IViewportListener#viewportChanged(int) + */ + public void viewportChanged(int verticalPosition) { + if (fCachedRedrawState && verticalPosition != fScrollPos) + redraw(); + } + + /* + * @see ITextListener#textChanged(TextEvent) + */ + public void textChanged(TextEvent event) { + + fCachedRedrawState= event.getViewerRedrawState(); + if (!fCachedRedrawState) + return; + + if (updateNumberOfDigits()) { + computeIndentations(); + layout(event.getViewerRedrawState()); + return; + } + + boolean viewerCompletelyShown= isViewerCompletelyShown(); + if (viewerCompletelyShown || fSensitiveToTextChanges || event.getDocumentEvent() == null) + postRedraw(); + fSensitiveToTextChanges= viewerCompletelyShown; + } + } + + /** + * Handles all the mouse interaction in this line number ruler column. + */ + class MouseHandler implements MouseListener, MouseMoveListener { + + /** The cached view port size */ + private int fCachedViewportSize; + /** The area of the line at which line selection started */ + private IRegion fStartLine; + /** The number of the line at which line selection started */ + private int fStartLineNumber; + /** The auto scroll direction */ + private int fAutoScrollDirection; + /* @since 3.2 */ + private boolean fIsListeningForMove= false; + + /* + * @see org.eclipse.swt.events.MouseListener#mouseUp(org.eclipse.swt.events.MouseEvent) + */ + public void mouseUp(MouseEvent event) { + // see bug 45700 + if (event.button == 1) { + stopSelecting(); + stopAutoScroll(); + } + } + + /* + * @see org.eclipse.swt.events.MouseListener#mouseDown(org.eclipse.swt.events.MouseEvent) + */ + public void mouseDown(MouseEvent event) { + fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y); + + int newLine= fParentRuler.toDocumentLineNumber(event.y) + 1; + if (annotationColumn instanceof ISTAnnotationHyperlink){ + ISTAnnotationHyperlink ahp = (ISTAnnotationHyperlink)annotationColumn; + if (ahp.isAnnotationHyperlink(newLine) && annotationColumn.getAnnotation(newLine).trim() != ""){ + ahp.handleHyperlink(newLine); + } + + } + else{ + // see bug 45700 + if (event.button == 1) { + startSelecting(); + } + } + } + + /* + * @see org.eclipse.swt.events.MouseListener#mouseDoubleClick(org.eclipse.swt.events.MouseEvent) + */ + public void mouseDoubleClick(MouseEvent event) { + fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y); + stopSelecting(); + stopAutoScroll(); + } + + /* + * @see org.eclipse.swt.events.MouseMoveListener#mouseMove(org.eclipse.swt.events.MouseEvent) + */ + public void mouseMove(MouseEvent event) { + int newLine= fParentRuler.toDocumentLineNumber(event.y) + 1; + if (annotationColumn instanceof ISTAnnotationHyperlink){ + if (((ISTAnnotationHyperlink)annotationColumn).isAnnotationHyperlink(newLine) && annotationColumn.getAnnotation(newLine).trim() != ""){ + Cursor cursor = new Cursor(event.display,SWT.CURSOR_HAND); + fCanvas.setCursor(cursor); + } + else{ + Cursor cursor = new Cursor(event.display,SWT.CURSOR_ARROW); + fCanvas.setCursor(cursor); + } + } + if (fIsListeningForMove && !autoScroll(event)) { + expandSelection(newLine); + } + fParentRuler.setLocationOfLastMouseButtonActivity(event.x, event.y); + } + + /** + * Called when line drag selection started. Adds mouse move and track + * listeners to this column's control. + */ + private void startSelecting() { + try { + + // select line + IDocument document= fCachedTextViewer.getDocument(); + fStartLineNumber= fParentRuler.getLineOfLastMouseButtonActivity(); + fStartLine= document.getLineInformation(fStartLineNumber); + fCachedTextViewer.setSelectedRange(fStartLine.getOffset(), fStartLine.getLength()); + + // prepare for drag selection + fIsListeningForMove= true; + + } catch (BadLocationException x) { + } + } + + /** + * Called when line drag selection stopped. Removes all previously + * installed listeners from this column's control. + */ + private void stopSelecting() { + // drag selection stopped + fIsListeningForMove= false; + } + + /** + * Expands the line selection from the remembered start line to the + * given line. + * + * @param lineNumber the line to which to expand the selection + */ + private void expandSelection(int lineNumber) { + try { + + IDocument document= fCachedTextViewer.getDocument(); + IRegion lineInfo= document.getLineInformation(lineNumber); + + int start= Math.min(fStartLine.getOffset(), lineInfo.getOffset()); + int end= Math.max(fStartLine.getOffset() + fStartLine.getLength(), lineInfo.getOffset() + lineInfo.getLength()); + + if (lineNumber < fStartLineNumber) + fCachedTextViewer.setSelectedRange(end, start - end); + else + fCachedTextViewer.setSelectedRange(start, end - start); + + } catch (BadLocationException x) { + } + } + + /** + * Called when auto scrolling stopped. Clears the auto scroll direction. + */ + private void stopAutoScroll() { + fAutoScrollDirection= SWT.NULL; + } + + /** + * Called on drag selection. + * + * @param event the mouse event caught by the mouse move listener + * @return true if scrolling happened, false otherwise + */ + private boolean autoScroll(MouseEvent event) { + Rectangle area= fCanvas.getClientArea(); + + if (event.y > area.height) { + autoScroll(SWT.DOWN); + return true; + } + + if (event.y < 0) { + autoScroll(SWT.UP); + return true; + } + + stopAutoScroll(); + return false; + } + + /** + * Scrolls the viewer into the given direction. + * + * @param direction the scroll direction + */ + private void autoScroll(int direction) { + + if (fAutoScrollDirection == direction) + return; + + final int TIMER_INTERVAL= 5; + final Display display = fCanvas.getDisplay(); + Runnable timer= null; + switch (direction) { + case SWT.UP: + timer= new Runnable() { + public void run() { + if (fAutoScrollDirection == SWT.UP) { + int top= getInclusiveTopIndex(); + if (top > 0) { + fCachedTextViewer.setTopIndex(top -1); + expandSelection(top -1); + display.timerExec(TIMER_INTERVAL, this); + } + } + } + }; + break; + case SWT.DOWN: + timer = new Runnable() { + public void run() { + if (fAutoScrollDirection == SWT.DOWN) { + int top= getInclusiveTopIndex(); + fCachedTextViewer.setTopIndex(top +1); + expandSelection(top +1 + fCachedViewportSize); + display.timerExec(TIMER_INTERVAL, this); + } + } + }; + break; + } + + if (timer != null) { + fAutoScrollDirection= direction; + display.timerExec(TIMER_INTERVAL, timer); + } + } + + /** + * Returns the viewer's first visible line, even if only partially visible. + * + * @return the viewer's first visible line + */ + private int getInclusiveTopIndex() { + if (fCachedTextWidget != null && !fCachedTextWidget.isDisposed()) { + return JFaceTextUtil.getPartialTopIndex(fCachedTextViewer); + } + return -1; + } + } + + /** This column's parent ruler */ + private CompositeRuler fParentRuler; + /** Cached text viewer */ + private ITextViewer fCachedTextViewer; + /** Cached text widget */ + private StyledText fCachedTextWidget; + /** The columns canvas */ + private Canvas fCanvas; + /** Cache for the actual scroll position in pixels */ + private int fScrollPos; + /** The drawable for double buffering */ + private Image fBuffer; + /** The internal listener */ + private InternalListener fInternalListener= new InternalListener(); + /** The font of this column */ + private Font fFont; + /** The indentation cache */ + private int[] fIndentation; + /** Indicates whether this column reacts on text change events */ + private boolean fSensitiveToTextChanges= false; + /** The foreground color */ + private Color fForeground; + /** The background color */ + private Color fBackground; + /** Cached number of displayed digits */ + private int fCachedNumberOfDigits= -1; + /** Flag indicating whether a relayout is required */ + private boolean fRelayoutRequired= false; + /** + * Redraw runnable lock + * @since 3.0 + */ + private Object fRunnableLock= new Object(); + /** + * Redraw runnable state + * @since 3.0 + */ + private boolean fIsRunnablePosted= false; + /** + * Redraw runnable + * @since 3.0 + */ + private Runnable fRunnable= new Runnable() { + public void run() { + synchronized (fRunnableLock) { + fIsRunnablePosted= false; + } + redraw(); + } + }; + /* @since 3.2 */ + private MouseHandler fMouseHandler; + + private ISTAnnotationColumn annotationColumn; + + /** + * Constructs a new vertical ruler column. + */ + public STRulerColumn(ISTAnnotationColumn ac) { + annotationColumn = ac; + } + + public ISTAnnotationColumn getSTAnnotationColumn(){ + return annotationColumn; + } + + public STRulerColumn() { + } + + /** + * Sets the foreground color of this column. + * + * @param foreground the foreground color + */ + public void setForeground(Color foreground) { + fForeground= foreground; + } + + /** + * Returns the foreground color being used to print the line numbers. + * + * @return the configured foreground color + * @since 3.0 + */ + protected Color getForeground() { + return fForeground; + } + + /** + * Sets the background color of this column. + * + * @param background the background color + */ + public void setBackground(Color background) { + fBackground= background; + if (fCanvas != null && !fCanvas.isDisposed()) + fCanvas.setBackground(getBackground(fCanvas.getDisplay())); + } + + /** + * Returns the System background color for list widgets. + * + * @param display the display + * @return the System background color for list widgets + */ + protected Color getBackground(Display display) { + if (fBackground == null) + return display.getSystemColor(SWT.COLOR_LIST_BACKGROUND); + return fBackground; + } + + /* + * @see IVerticalRulerColumn#getControl() + */ + public Control getControl() { + return fCanvas; + } + + /* + * @see IVerticalRuleColumnr#getWidth + */ + public int getWidth() { + return fIndentation[0]; + } + + /** + * Computes the number of digits to be displayed. Returns + * true if the number of digits changed compared + * to the previous call of this method. If the method is called + * for the first time, the return value is also true. + * + * @return whether the number of digits has been changed + * @since 3.0 + */ + protected boolean updateNumberOfDigits() { + if (fCachedTextViewer == null) + return false; + + int digits= computeNumberOfDigits(); + + if (fCachedNumberOfDigits != digits) { + fCachedNumberOfDigits= digits; + return true; + } + + return false; + } + + /** + * Does the real computation of the number of digits. Subclasses may override this method if + * they need extra space on the line number ruler. + * + * @return the number of digits to be displayed on the line number ruler. + */ + protected int computeNumberOfDigits() { + IDocument document= fCachedTextViewer.getDocument(); + int lines= document == null ? 0 : document.getNumberOfLines(); + int digits = 0; + if (annotationColumn.getTitle() != null && annotationColumn.getTitle().length() >0){ + digits= annotationColumn.getTitle().length() + 3; + } + else + digits = 3; + + while (lines > Math.pow(10, digits) -1) { + ++digits; + } + return (digits); + } + + /** + * Layouts the enclosing viewer to adapt the layout to changes of the + * size of the individual components. + * + * @param redraw true if this column can be redrawn + */ + protected void layout(boolean redraw) { + if (!redraw) { + fRelayoutRequired= true; + return; + } + + fRelayoutRequired= false; + if (fCachedTextViewer instanceof ITextViewerExtension) { + ITextViewerExtension extension= (ITextViewerExtension) fCachedTextViewer; + Control control= extension.getControl(); + if (control instanceof Composite && !control.isDisposed()) { + Composite composite= (Composite) control; + composite.layout(true); + } + } + } + + /** + * Computes the indentations for the given font and stores them in + * fIndentation. + */ + protected void computeIndentations() { + if (fCanvas == null || fCanvas.isDisposed()) + return; + + GC gc= new GC(fCanvas); + try { + + gc.setFont(fCanvas.getFont()); + + fIndentation= new int[fCachedNumberOfDigits + 3]; + + char[] nines= new char[fCachedNumberOfDigits + 2]; + Arrays.fill(nines, '9'); + String nineString= new String(nines); + Point p= gc.stringExtent(nineString); + fIndentation[0]= p.x; + + for (int i= 1; i <= fCachedNumberOfDigits; i++) { + p= gc.stringExtent(nineString.substring(0, i)); + fIndentation[i]= fIndentation[0] - p.x; + } + + } finally { + gc.dispose(); + } + } + + /* + * @see IVerticalRulerColumn#createControl(CompositeRuler, Composite) + */ + public Control createControl(CompositeRuler parentRuler, Composite parentControl) { + + fParentRuler= parentRuler; + fCachedTextViewer= parentRuler.getTextViewer(); + fCachedTextWidget= fCachedTextViewer.getTextWidget(); + + fCanvas= new Canvas(parentControl, SWT.BORDER); + fCanvas.setBackground(getBackground(fCanvas.getDisplay())); + fCanvas.setForeground(fForeground); + + fCanvas.addPaintListener(new PaintListener() { + public void paintControl(PaintEvent event) { + if (fCachedTextViewer != null) + doubleBufferPaint(event.gc); + } + }); + + fCanvas.addDisposeListener(new DisposeListener() { + public void widgetDisposed(DisposeEvent e) { + handleDispose(); + fCachedTextViewer= null; + fCachedTextWidget= null; + } + }); + + fMouseHandler= new MouseHandler(); + fCanvas.addMouseListener(fMouseHandler); + fCanvas.addMouseMoveListener(fMouseHandler); + + if (fCachedTextViewer != null) { + + fCachedTextViewer.addViewportListener(fInternalListener); + fCachedTextViewer.addTextListener(fInternalListener); + + if (fFont == null) { + if (fCachedTextWidget != null && !fCachedTextWidget.isDisposed()) + fFont= fCachedTextWidget.getFont(); + } + } + + if (fFont != null) + fCanvas.setFont(fFont); + + updateNumberOfDigits(); + computeIndentations(); + return fCanvas; + } + + /** + * Disposes the column's resources. + */ + protected void handleDispose() { + + if (fCachedTextViewer != null) { + fCachedTextViewer.removeViewportListener(fInternalListener); + fCachedTextViewer.removeTextListener(fInternalListener); + } + + if (fBuffer != null) { + fBuffer.dispose(); + fBuffer= null; + } + } + + /** + * Double buffer drawing. + * + * @param dest the GC to draw into + */ + private void doubleBufferPaint(GC dest) { + + Point size= fCanvas.getSize(); + + if (size.x <= 0 || size.y <= 0) + return; + + if (fBuffer != null) { + Rectangle r= fBuffer.getBounds(); + if (r.width != size.x || r.height != size.y) { + fBuffer.dispose(); + fBuffer= null; + } + } + if (fBuffer == null) + fBuffer= new Image(fCanvas.getDisplay(), size.x, size.y); + + GC gc= new GC(fBuffer); + gc.setFont(fCanvas.getFont()); + if (fForeground != null) + gc.setForeground(fForeground); + + try { + gc.setBackground(getBackground(fCanvas.getDisplay())); + gc.fillRectangle(0, 0, size.x, size.y); + + ILineRange visibleLines= JFaceTextUtil.getVisibleModelLines(fCachedTextViewer); + if (visibleLines == null) + return; + fScrollPos= fCachedTextWidget.getTopPixel(); + doPaint(gc, visibleLines); + fCachedTextWidget.addMouseTrackListener(new MouseTrackListener(){ + + @Override + public void mouseEnter(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseExit(MouseEvent e) { + // TODO Auto-generated method stub + + } + + @Override + public void mouseHover(MouseEvent e) { + + + } + + }); + + } finally { + gc.dispose(); + } + + dest.drawImage(fBuffer, 0, 0); + } + + /** + * Returns true if the viewport displays the entire viewer contents, i.e. the + * viewer is not vertically scrollable. + * + * @return true if the viewport displays the entire contents, false otherwise + * @since 3.2 + */ + protected final boolean isViewerCompletelyShown() { + return JFaceTextUtil.isShowingEntireContents(fCachedTextWidget); + } + + /** + * Draws the ruler column. + * + * @param gc the GC to draw into + * @param visibleLines the visible model lines + * @since 3.2 + */ + void doPaint(GC gc, ILineRange visibleLines) { + Display display= fCachedTextWidget.getDisplay(); + + // draw diff info + int y= -JFaceTextUtil.getHiddenTopLinePixels(fCachedTextWidget); + + int lastLine= end(visibleLines); + for (int line= visibleLines.getStartLine(); line < lastLine; line++) { + int widgetLine= JFaceTextUtil.modelLineToWidgetLine(fCachedTextViewer, line); + if (widgetLine == -1) + continue; + + int lineHeight= fCachedTextWidget.getLineHeight(fCachedTextWidget.getOffsetAtLine(widgetLine)); + paintLine(line, y, lineHeight, gc, display); + y += lineHeight; + } + } + + /* @since 3.2 */ + private static int end(ILineRange range) { + return range.getStartLine() + range.getNumberOfLines(); + } + + /** + * Computes the string to be printed for line. The default implementation returns + * Integer.toString(line + 1). + * + * @param line the line number for which the line number string is generated + * @return the string to be printed on the line number bar for line + * @since 3.0 + */ + protected String createDisplayString(int line) { + return Integer.toString(line); + } + + /** + * Returns the difference between the baseline of the widget and the + * baseline as specified by the font for gc. When drawing + * line numbers, the returned bias should be added to obtain text lined up + * on the correct base line of the text widget. + * + * @param gc the GC to get the font metrics from + * @param widgetLine the widget line + * @return the baseline bias to use when drawing text that is lined up with + * fCachedTextWidget + * @since 3.2 + */ + private int getBaselineBias(GC gc, int widgetLine) { + /* + * https://bugs.eclipse.org/bugs/show_bug.cgi?id=62951 + * widget line height may be more than the font height used for the + * line numbers, since font styles (bold, italics...) can have larger + * font metrics than the simple font used for the numbers. + */ + int offset= fCachedTextWidget.getOffsetAtLine(widgetLine); + int widgetBaseline= fCachedTextWidget.getBaseline(offset); + + FontMetrics fm = gc.getFontMetrics(); + int fontBaseline = fm.getAscent() + fm.getLeading(); + int baselineBias= widgetBaseline - fontBaseline; + return Math.max(0, baselineBias); + } + + /** + * Paints the line. After this method is called the line numbers are painted on top + * of the result of this method. + * + * @param line the line of the document which the ruler is painted for + * @param y the y-coordinate of the box being painted for line, relative to gc + * @param lineheight the height of one line (and therefore of the box being painted) + * @param gc the drawing context the client may choose to draw on. + * @param display the display the drawing occurs on + * @since 3.0 + */ + protected void paintLine(int line, int y, int lineheight, GC gc, Display display) { + int widgetLine= JFaceTextUtil.modelLineToWidgetLine(fParentRuler.getTextViewer(), line); + String s = ""; + int indentation= fCachedNumberOfDigits; + + if (annotationColumn instanceof ISTAnnotationHyperlink){ + ISTAnnotationHyperlink ah = (ISTAnnotationHyperlink)annotationColumn; + if (ah.isAnnotationHyperlink(widgetLine)){ + paintHyperLink(line, y, indentation, lineheight, gc, display); + + } + } + else{ + s = annotationColumn.getAnnotation(widgetLine); + + if (widgetLine + 1 == 1){ + for(int i=0;i - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.annotatedsourceeditor; + +import org.eclipse.osgi.util.NLS; + +/** + * Helper class to get NLSed messages. + */ +final class STRulerMessages extends NLS { + + private static final String BUNDLE_NAME= STRulerMessages.class.getName(); + + private STRulerMessages() { + // Do not instantiate + } + + public static String AbstractDecoratedTextEditor_revision_quickdiff_switch_title; + public static String AbstractDecoratedTextEditor_revision_quickdiff_switch_message; + public static String AbstractDecoratedTextEditor_revision_quickdiff_switch_rememberquestion; + + static { + NLS.initializeMessages(BUNDLE_NAME, STRulerMessages.class); + } + +} diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STTextEditorMessages.java b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STTextEditorMessages.java new file mode 100644 index 0000000..0cf4097 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/STTextEditorMessages.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.annotatedsourceeditor; + +import java.util.ResourceBundle; + +import org.eclipse.osgi.util.NLS; + +public class STTextEditorMessages extends NLS { + private static final String BUNDLE_FOR_CONSTRUCTED_KEYS= "org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.STConstructedTextEditorMessages"; //$NON-NLS-1$ + private static ResourceBundle fgBundleForConstructedKeys= ResourceBundle.getBundle(BUNDLE_FOR_CONSTRUCTED_KEYS); + + /** + * Returns the message bundle which contains constructed keys. + * + * @since 3.1 + * @return the message bundle + */ + public static ResourceBundle getBundleForConstructedKeys() { + return fgBundleForConstructedKeys; + } + + private static final String BUNDLE_NAME= STTextEditorMessages.class.getName(); + + static { + NLS.initializeMessages(BUNDLE_NAME, STTextEditorMessages.class); + } + +} diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/actions/AbstractOpenSourceFileAction.java b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/actions/AbstractOpenSourceFileAction.java new file mode 100644 index 0000000..d6d923c --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/actions/AbstractOpenSourceFileAction.java @@ -0,0 +1,93 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.actions; + +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.action.Action; +import org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.AbstractSTAnnotatedSourceEditorInput; +import org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.STAnnotatedSourceEditorActivator; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.MessageBox; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; + + +public abstract class AbstractOpenSourceFileAction extends Action{ + public static final String EDITOR_ID = "org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.editor"; + private long ts; + + public AbstractOpenSourceFileAction(String filepath,long ts){ + super.setText("Open =>" + filepath); + this.ts = ts; + } + + @Override + public void run() { + + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + + IFileStore fileStore = getFileStore(); + + if (fileStore != null && !fileStore.fetchInfo().isDirectory() && fileStore.fetchInfo().exists()) { + long timeStamp = fileStore.fetchInfo().getLastModified(); + + if (timeStamp>ts) { + MessageBox msg = new MessageBox(window.getShell(),SWT.ICON_WARNING | SWT.APPLICATION_MODAL | SWT.YES| SWT.NO); + msg.setText(fileStore.toString()); + msg.setMessage("The file " + + fileStore + + " is newer than the analysis result, \n" + + " if you continue opening it the visualization could result inconsistent. \n Do you want to continue?"); + } + + try { + IWorkbenchPage page = window.getActivePage(); + if (page != null) { + IFileStore fs = EFS.getStore(fileStore.toURI()); + IEditorInput input = getInput(fs); + page.openEditor(input, EDITOR_ID, false); + } + } catch (Exception e) { + Status s = new Status( + IStatus.ERROR, + STAnnotatedSourceEditorActivator.getUniqueIdentifier(), + IStatus.ERROR, + "Error when opening annotated source view", + e); + STAnnotatedSourceEditorActivator.getDefault().getLog().log(s); + } + } + else{ + if (!fileStore.fetchInfo().exists()) { + showMessage("The selected file does not exist: " + fileStore,window.getShell()); + } + } + + } + + private void showMessage(String message,Shell shell) { + MessageBox msgBox = new MessageBox(shell,SWT.ICON_ERROR); + msgBox.setText("Error"); + msgBox.setMessage(message); + msgBox.open(); + } + + public abstract AbstractSTAnnotatedSourceEditorInput getInput(IFileStore fs); + + public abstract IFileStore getFileStore(); +} + diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/actions/OpenFileFullPathAction.java b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/actions/OpenFileFullPathAction.java new file mode 100644 index 0000000..85cb88f --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/actions/OpenFileFullPathAction.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.actions; + +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.core.runtime.Path; +import org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.AbstractSTAnnotatedSourceEditorInput; + + +public abstract class OpenFileFullPathAction extends AbstractOpenSourceFileAction { + private String filepath; + public OpenFileFullPathAction(String filepath, long ts) { + super(filepath, ts); + this.filepath = filepath; + } + + public abstract AbstractSTAnnotatedSourceEditorInput getInput(IFileStore fs); + + public IFileStore getFileStore(){ + return EFS.getLocalFileSystem().getStore(new Path(filepath)); + } + +} diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/actions/OpenWksRelFilePathAction.java b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/actions/OpenWksRelFilePathAction.java new file mode 100644 index 0000000..a6dce5c --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/actions/OpenWksRelFilePathAction.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.actions; + +import java.io.File; + +import org.eclipse.core.filesystem.EFS; +import org.eclipse.core.filesystem.IFileStore; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IWorkspace; +import org.eclipse.core.resources.IWorkspaceRoot; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.Path; +import org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.AbstractSTAnnotatedSourceEditorInput; +import org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.STAnnotatedSourceEditorActivator; + + + +public abstract class OpenWksRelFilePathAction extends AbstractOpenSourceFileAction { + private String filepath; + + public OpenWksRelFilePathAction(String filepath, long ts) { + super(filepath, ts); + + this.filepath = filepath; + } + + @Override + public abstract AbstractSTAnnotatedSourceEditorInput getInput(IFileStore fs); + + public IFileStore getFileStore(){ + File file = new File(filepath); + IFile f = null; + if (!file.isAbsolute()) + { + IWorkspace workspace = ResourcesPlugin.getWorkspace(); + if (workspace != null) { + IWorkspaceRoot wrkRoot = workspace.getRoot(); + f = wrkRoot.getFile(new Path(filepath)); + IPath p = f.getLocation(); + if (p != null) file = p.toFile(); + } + try { + IFileStore fs = EFS.getStore(file.toURI()); + return fs; + } catch (CoreException e) { + STAnnotatedSourceEditorActivator.getDefault().getLog().log(e.getStatus()); + } + } + return null; + } + +} diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/hyperlink/ISTAnnotationHyperlink.java b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/hyperlink/ISTAnnotationHyperlink.java new file mode 100644 index 0000000..95dad66 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/hyperlink/ISTAnnotationHyperlink.java @@ -0,0 +1,17 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.hyperlink; + +public interface ISTAnnotationHyperlink { + boolean isAnnotationHyperlink(int line); + void handleHyperlink(int line); +} diff --git a/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/preferencespages/STAnnotatedSourceEditorPreferencePage.java b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/preferencespages/STAnnotatedSourceEditorPreferencePage.java new file mode 100644 index 0000000..23fd2d9 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.annotatedsourceeditor/src/org/eclipse/linuxtools/dataviewers/annotatedsourceeditor/preferencespages/STAnnotatedSourceEditorPreferencePage.java @@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.dataviewers.annotatedsourceeditor.preferencespages; + +import org.eclipse.jface.preference.PreferencePage; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.ui.IWorkbench; +import org.eclipse.ui.IWorkbenchPreferencePage; + +public class STAnnotatedSourceEditorPreferencePage extends PreferencePage + implements IWorkbenchPreferencePage { + + /** + * A named preference that controls if the line number ruler is shown in the UI + * (value "lineNumberRuler"). + *

+ * The preference value is of type Boolean. + *

+ */ + public final static String EDITOR_ST_RULER= "STRuler"; //$NON-NLS-1$ + + public STAnnotatedSourceEditorPreferencePage() { + // TODO Auto-generated constructor stub + } + + public STAnnotatedSourceEditorPreferencePage(String title) { + super(title); + // TODO Auto-generated constructor stub + } + + public STAnnotatedSourceEditorPreferencePage(String title, + ImageDescriptor image) { + super(title, image); + // TODO Auto-generated constructor stub + } + + @Override + protected Control createContents(Composite parent) { + // TODO Auto-generated method stub + return null; + } + + public void init(IWorkbench workbench) { + // TODO Auto-generated method stub + + } + +} diff --git a/org.eclipse.linuxtools.dataviewers.charts/.classpath b/org.eclipse.linuxtools.dataviewers.charts/.classpath new file mode 100755 index 0000000..8a8f166 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.charts/.classpath @@ -0,0 +1,7 @@ + + + + + + + diff --git a/org.eclipse.linuxtools.dataviewers.charts/.project b/org.eclipse.linuxtools.dataviewers.charts/.project new file mode 100755 index 0000000..70e988c --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.charts/.project @@ -0,0 +1,28 @@ + + + org.eclipse.linuxtools.dataviewers.charts + + + + + + org.eclipse.jdt.core.javabuilder + + + + + org.eclipse.pde.ManifestBuilder + + + + + org.eclipse.pde.SchemaBuilder + + + + + + org.eclipse.pde.PluginNature + org.eclipse.jdt.core.javanature + + diff --git a/org.eclipse.linuxtools.dataviewers.charts/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.dataviewers.charts/META-INF/MANIFEST.MF new file mode 100755 index 0000000..ea57dcd --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.charts/META-INF/MANIFEST.MF @@ -0,0 +1,26 @@ +Manifest-Version: 1.0 +Bundle-ManifestVersion: 2 +Bundle-Name: %bundleName +Bundle-SymbolicName: org.eclipse.linuxtools.dataviewers.charts;singleton:=true +Bundle-Version: 4.1.0.qualifier +Bundle-Activator: org.eclipse.linuxtools.dataviewers.charts.Activator +Bundle-Vendor: %bundleProvider +Require-Bundle: org.eclipse.ui, + org.eclipse.core.runtime, + org.eclipse.linuxtools.dataviewers;bundle-version="4.0.0", + org.eclipse.birt.core;bundle-version="2.5.1", + org.eclipse.birt.chart.ui;bundle-version="2.5.1", + org.eclipse.birt.data;bundle-version="2.5.1", + org.eclipse.birt.data.aggregation;bundle-version="2.5.1", + org.eclipse.core.resources;bundle-version="3.4.2" +Bundle-RequiredExecutionEnvironment: JavaSE-1.6 +Bundle-ActivationPolicy: lazy +Export-Package: org.eclipse.linuxtools.dataviewers.charts, + org.eclipse.linuxtools.dataviewers.charts.actions, + org.eclipse.linuxtools.dataviewers.charts.dataengine, + org.eclipse.linuxtools.dataviewers.charts.dialogs, + org.eclipse.linuxtools.dataviewers.charts.provider, + org.eclipse.linuxtools.dataviewers.charts.view, + org.eclipse.linuxtools.dataviewers.charts.viewer +Import-Package: com.ibm.icu.util;version="4.0.1" +Bundle-Localization: plugin diff --git a/org.eclipse.linuxtools.dataviewers.charts/about.html b/org.eclipse.linuxtools.dataviewers.charts/about.html new file mode 100644 index 0000000..23506a4 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.charts/about.html @@ -0,0 +1,26 @@ + + + + + +About + +

About This Content

+ +

June 5, 2006

+

License

+ +

The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise +indicated below, the Content is provided to you under the terms and conditions of the +Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available +at http://www.eclipse.org/legal/epl-v10.html. +For purposes of the EPL, "Program" will mean the Content.

+ +

If you did not receive this Content directly from the Eclipse Foundation, the Content is +being redistributed by another party ("Redistributor") and different terms and conditions may +apply to your use of any object code in the Content. Check the Redistributor's license that was +provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise +indicated below, the terms and conditions of the EPL still apply to any source code in the Content +and such source code may be obtained at http://www.eclipse.org.

+ + \ No newline at end of file diff --git a/org.eclipse.linuxtools.dataviewers.charts/build.properties b/org.eclipse.linuxtools.dataviewers.charts/build.properties new file mode 100755 index 0000000..8ef30b8 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.charts/build.properties @@ -0,0 +1,8 @@ +source.. = src/ +output.. = bin/ +bin.includes = .,\ + META-INF/,\ + icons/,\ + plugin.xml,\ + about.html,\ + plugin.properties diff --git a/org.eclipse.linuxtools.dataviewers.charts/icons/Thumbs.db b/org.eclipse.linuxtools.dataviewers.charts/icons/Thumbs.db new file mode 100755 index 0000000..1f91a7a Binary files /dev/null and b/org.eclipse.linuxtools.dataviewers.charts/icons/Thumbs.db differ diff --git a/org.eclipse.linuxtools.dataviewers.charts/icons/chart_icon.png b/org.eclipse.linuxtools.dataviewers.charts/icons/chart_icon.png new file mode 100755 index 0000000..67d1a81 Binary files /dev/null and b/org.eclipse.linuxtools.dataviewers.charts/icons/chart_icon.png differ diff --git a/org.eclipse.linuxtools.dataviewers.charts/icons/dexport.gif b/org.eclipse.linuxtools.dataviewers.charts/icons/dexport.gif new file mode 100644 index 0000000..3f89cd9 Binary files /dev/null and b/org.eclipse.linuxtools.dataviewers.charts/icons/dexport.gif differ diff --git a/org.eclipse.linuxtools.dataviewers.charts/icons/dimport.gif b/org.eclipse.linuxtools.dataviewers.charts/icons/dimport.gif new file mode 100644 index 0000000..cd44741 Binary files /dev/null and b/org.eclipse.linuxtools.dataviewers.charts/icons/dimport.gif differ diff --git a/org.eclipse.linuxtools.dataviewers.charts/icons/eexport.gif b/org.eclipse.linuxtools.dataviewers.charts/icons/eexport.gif new file mode 100644 index 0000000..5a0837d Binary files /dev/null and b/org.eclipse.linuxtools.dataviewers.charts/icons/eexport.gif differ diff --git a/org.eclipse.linuxtools.dataviewers.charts/icons/eimport.gif b/org.eclipse.linuxtools.dataviewers.charts/icons/eimport.gif new file mode 100644 index 0000000..d38085a Binary files /dev/null and b/org.eclipse.linuxtools.dataviewers.charts/icons/eimport.gif differ diff --git a/org.eclipse.linuxtools.dataviewers.charts/icons/save_chart.gif b/org.eclipse.linuxtools.dataviewers.charts/icons/save_chart.gif new file mode 100755 index 0000000..466bfb1 Binary files /dev/null and b/org.eclipse.linuxtools.dataviewers.charts/icons/save_chart.gif differ diff --git a/org.eclipse.linuxtools.dataviewers.charts/plugin.properties b/org.eclipse.linuxtools.dataviewers.charts/plugin.properties new file mode 100644 index 0000000..c1c5fab --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.charts/plugin.properties @@ -0,0 +1,14 @@ +#****************************************************************************** +# Copyright (c) 2009 STMicroelectronics. +# 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: +# STMicroelectronics - initial API and implementation +#******************************************************************************* +bundleProvider = Eclipse Linux Tools +bundleName = Data Viewers Birt Charts Plug-in (Incubation) +chartview.name = Chart View +chartcategory.name = Charts \ No newline at end of file diff --git a/org.eclipse.linuxtools.dataviewers.charts/plugin.xml b/org.eclipse.linuxtools.dataviewers.charts/plugin.xml new file mode 100755 index 0000000..fd38dfb --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.charts/plugin.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + diff --git a/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/Activator.java b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/Activator.java new file mode 100755 index 0000000..0162326 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/Activator.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.charts; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.osgi.framework.BundleContext; + +/** + * The activator class controls the plug-in life cycle + */ +public class Activator extends AbstractUIPlugin { + + // The plug-in ID + public static final String PLUGIN_ID = "org.eclipse.linuxtools.dataviewers.charts"; + + // The shared instance + private static Activator plugin; + + /** + * The constructor + */ + public Activator() { + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext) + */ + public void start(BundleContext context) throws Exception { + super.start(context); + plugin = this; + } + + /* + * (non-Javadoc) + * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext) + */ + public void stop(BundleContext context) throws Exception { + plugin = null; + super.stop(context); + } + + /** + * Returns the shared instance + * + * @return the shared instance + */ + public static Activator getDefault() { + return plugin; + } + + /** + * Returns an image descriptor for the image file at the given + * plug-in relative path + * + * @param path the path + * @return the image descriptor + */ + public static ImageDescriptor getImageDescriptor(String path) { + return imageDescriptorFromPlugin(PLUGIN_ID, path); + } + + /** + * Returns an image from the path + * + * @param path the path + * @return the image + */ + public static Image getImage(String path) { + Image image = plugin.getImageRegistry().get(path); + if (image == null) { + image = getImageDescriptor(path).createImage(); + plugin.getImageRegistry().put(path, image); + } + return image; + } + +} diff --git a/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/ChartConstants.java b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/ChartConstants.java new file mode 100755 index 0000000..431ecf0 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/ChartConstants.java @@ -0,0 +1,85 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.charts; + + +/** + * A class that handles the constants used by the charts. + * + *
+ *
+ * It contains: + *
    + *
  • labels used by the chart dialog.
  • + *
  • keys and default values used by the dialog settings.
  • + *
  • predefined colors used by the charts.
  • + *
+ * + */ +public class ChartConstants { + + /** The section name of the viewer's dialog settings where the chart dialog save its state */ + public static final String TAG_SECTION_BIRTCHARTS_STATE = "birtcharts_section"; + /** The key used by the column buttons to save their state. For example the button i will use the key TAG_COLUMN_BUTTON_+i */ + public static final String TAG_COLUMN_BUTTON_ = "COLUMN_BUTTON_"; + /** The key used by the bar graph button to save its state */ + public static final String TAG_BAR_GRAPH_BUTTON = "BAR_GRAPH_BUTTON"; + /** The key used by the vertical bars button to save its state */ + public static final String TAG_VERTICAL_BARS_BUTTON = "VERTICAL_BARS_BUTTON"; + + /** The default value of the column buttons */ + public static final boolean DEFAULT_COLUMN_BUTTON = true; + /** The default value of the bar graph button */ + public static final boolean DEFAULT_BAR_GRAPH_BUTTON = true; + /** The default value of the vertical bars button */ + public static final boolean DEFAULT_VERTICAL_BARS_BUTTON = false; + + /** The section name of the "save chart as image" action dialog settings */ + public static final String TAG_SECTION_BIRTCHARTS_SAVEACTION_STATE = "birtcharts_saveasimg_section"; + /** The key used by the file dialog to save its file name */ + public static final String TAG_IMG_FILE_NAME = "IMG_FILE_NAME"; + /** The key used by the file dialog to save its filter path */ + public static final String TAG_IMG_FILTER_PATH = "IMG_FILTER_PATH"; + + /** The default value of the file dialog file name */ + public static final String DEFAULT_IMG_FILE_NAME = "."; + /** The default value of the file dialog filter path */ + public static final String DEFAULT_IMG_FILTER_PATH = "."; + + /** Image extension for jpg format */ + public static final String EXT_JPG = ".jpg"; + /** Image extension for jpeg format */ + public static final String EXT_JPEG = ".jpeg"; + /** Image extension for png format */ + public static final String EXT_PNG = ".png"; + /** Image extension for gif format */ + public static final String EXT_GIF = ".gif"; + /** Image extension for svg format */ + public static final String EXT_SVG = ".svg"; + /** The file extensions provided by the "save chart as image" file dialog */ + public static final String[] saveAsImageExt = + { + "*"+EXT_JPG, + "*"+EXT_JPEG, + "*"+EXT_PNG, + "*"+EXT_GIF, + "*.*" + }; + /** The names associated to the files extensions provided by the "save chart as image" file dialog */ + public static String[] saveAsImageExtNames = + { + "JPEG (*.jpg)", + "JPEG (*.jpeg)", + "PNG (*.png)", + "GIF (*.gif)", + "All Files (*.*)" + }; +} diff --git a/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/UIHelper.java b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/UIHelper.java new file mode 100644 index 0000000..1cfc2e3 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/UIHelper.java @@ -0,0 +1,143 @@ +/******************************************************************************* + * Copyright (c) 2005 Actuate Corporation. + * 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: + * Actuate Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.dataviewers.charts; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.net.MalformedURLException; +import java.net.URL; + +import org.eclipse.core.runtime.Platform; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; +import org.eclipse.jface.resource.JFaceResources; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; + +/** + * This class has been created to hold methods that provide specific + * functionality or services. + */ +public final class UIHelper +{ + + /** + * This method returns an URL for a resource given its plugin relative path. + * It is intended to be used to abstract out the usage of the UI as a plugin + * or standalone component when it comes to accessing resources. + * + * @param sPluginRelativePath + * The path to the resource relative to the plugin location. + * @return URL representing the location of the resource. + */ + public static URL getURL( String sPluginRelativePath ) + { + URL url = null; + if ( Platform.getExtensionRegistry( ) != null ) + { + try + { + url = new URL( Activator.getDefault( ) + .getBundle( ) + .getEntry( "/" ), sPluginRelativePath ); //$NON-NLS-1$ + } + catch ( MalformedURLException e ) + { + e.printStackTrace( ); + } + } + else + { + try + { + url = new URL( "file:///" + new File( sPluginRelativePath ).getAbsolutePath( ) ); //$NON-NLS-1$ + } + catch ( MalformedURLException e ) + { + e.printStackTrace( ); + } + } + + return url; + } + + private static Image createImage( String sPluginRelativePath ) + { + Image img = null; + try + { + try + { + img = new Image( Display.getCurrent( ), + getURL( sPluginRelativePath ).openStream( ) ); + } + catch ( MalformedURLException e1 ) + { + img = new Image( Display.getCurrent( ), + new FileInputStream( getURL( sPluginRelativePath ).toString( ) ) ); + } + } + catch ( IOException e ) + { + e.printStackTrace( ); + } + + // If still can't load, return a dummy image. + if ( img == null ) + { + img = new Image( Display.getCurrent( ), 1, 1 ); + } + return img; + } + + /** + * This is a convenience method to get an imgIcon from a URL. + * + * @param sPluginRelativePath + * The URL for the imgIcon. + * @return The imgIcon represented by the given URL. + * @see #setImageCached( boolean ) + */ + public static Image getImage( String sPluginRelativePath ) + { + ImageRegistry registry = JFaceResources.getImageRegistry( ); + Image image = registry.get( sPluginRelativePath ); + if ( image == null ) + { + image = createImage( sPluginRelativePath ); + registry.put( sPluginRelativePath, image ); + } + return image; + } + + /** + * This is a convenience method to get an imgIcon from a URL. + * + * @param sPluginRelativePath + * The URL for the imgIcon. + * @return The imgIcon represented by the given URL. + * @see #setImageCached( boolean ) + */ + public static ImageDescriptor getImageDescriptor( String sPluginRelativePath ) + { + ImageRegistry registry = JFaceResources.getImageRegistry( ); + ImageDescriptor image = registry.getDescriptor( sPluginRelativePath ); + if ( image == null ) + { + registry.put( sPluginRelativePath, + createImage( sPluginRelativePath ) ); + image = registry.getDescriptor( sPluginRelativePath ); + } + return image; + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/ChartAction.java b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/ChartAction.java new file mode 100755 index 0000000..43cf431 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/ChartAction.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.charts.actions; + +import org.eclipse.birt.chart.model.Chart; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.viewers.ISelectionChangedListener; +import org.eclipse.jface.viewers.SelectionChangedEvent; +import org.eclipse.linuxtools.dataviewers.abstractviewers.AbstractSTViewer; +import org.eclipse.linuxtools.dataviewers.charts.Activator; +import org.eclipse.linuxtools.dataviewers.charts.dialogs.ChartDialog; +import org.eclipse.linuxtools.dataviewers.charts.view.ChartView; +import org.eclipse.swt.widgets.Shell; + +/** + * An action that open a chart dialog from an AbstractSTViewer. + * + * @see AbstractSTViewer + */ +public class ChartAction extends Action { + + /** The dialog */ + private ChartDialog dialog; + + /** + * The constructor. + * + * @param shell the shell used by the dialog + * @param viewer the viewer inputed to the disalog + */ + public ChartAction(Shell shell, AbstractSTViewer viewer) { + super("Create chart...", Activator.getImageDescriptor("icons/chart_icon.png")); + dialog = createDialog(shell, viewer); + setEnabled(!viewer.getViewer().getSelection().isEmpty()); + viewer.getViewer().addSelectionChangedListener(new ISelectionChangedListener() { + public void selectionChanged(SelectionChangedEvent event) { + setEnabled(!event.getSelection().isEmpty()); + } + }); + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.action.Action#run() + */ + @Override + public void run() { + dialog.open(); + Chart chart = dialog.getValue(); + if (chart != null) { + ChartView.createChartView(chart); + + } + } + + protected ChartDialog createDialog(Shell shell,AbstractSTViewer viewer){ + return new ChartDialog(shell,viewer); + } +} diff --git a/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/ChartActionRenderer.java b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/ChartActionRenderer.java new file mode 100644 index 0000000..cd47aab --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/ChartActionRenderer.java @@ -0,0 +1,46 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.charts.actions; + +import org.eclipse.birt.chart.render.ActionRendererAdapter; +import org.eclipse.birt.chart.computation.DataPointHints; +import org.eclipse.birt.chart.event.StructureSource; +import org.eclipse.birt.chart.event.StructureType; +import org.eclipse.birt.chart.model.attribute.ActionType; +import org.eclipse.birt.chart.model.attribute.TooltipValue; +import org.eclipse.birt.chart.model.attribute.impl.JavaNumberFormatSpecifierImpl; +import org.eclipse.birt.chart.model.data.Action; + +import com.ibm.icu.util.ULocale; + + +/** + * Simple implementation for IActionRenderer + */ +public class ChartActionRenderer extends ActionRendererAdapter { + + + public void processAction( Action action, StructureSource source ) + { + if ( ActionType.SHOW_TOOLTIP_LITERAL.equals( action.getType( ) ) ) + { + TooltipValue tv = (TooltipValue) action.getValue( ); + if ( StructureType.SERIES_DATA_POINT.equals( source.getType( ) ) ) + { + final DataPointHints dph = (DataPointHints) source.getSource( ); + String MyToolTip = "Value is " + + JavaNumberFormatSpecifierImpl.create("0.00").format( + ((Double)dph.getOrthogonalValue()).doubleValue(),ULocale.getDefault()); + tv.setText( MyToolTip ); + } + } + } +} diff --git a/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/OpenChartAction.java b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/OpenChartAction.java new file mode 100644 index 0000000..539ef4c --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/OpenChartAction.java @@ -0,0 +1,77 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.charts.actions; + +import java.io.File; +import java.io.FileInputStream; + +import org.eclipse.birt.chart.model.Chart; +import org.eclipse.birt.chart.model.Serializer; +import org.eclipse.birt.chart.model.impl.SerializerImpl; +import org.eclipse.birt.core.ui.frameworks.taskwizard.WizardBase; +import org.eclipse.jface.action.Action; +import org.eclipse.linuxtools.dataviewers.charts.UIHelper; +import org.eclipse.linuxtools.dataviewers.charts.view.ChartView; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; + + + +public class OpenChartAction extends Action { + private Chart chart = null; + private FileDialog dialog; + private ChartView chartView; + + public OpenChartAction(Shell shell,ChartView cView){ + setImageDescriptor( UIHelper.getImageDescriptor( "icons/eimport.gif" ) ); + setDisabledImageDescriptor( UIHelper.getImageDescriptor( "icons/dimport.gif" ) ); + setToolTipText( "Open XML Source" ); + setEnabled(true); + this.chartView = cView; + this.dialog = new FileDialog(shell, SWT.OPEN); + dialog.setText("Select a chart file "); + dialog.setFilterExtensions(new String[]{"*.chart"}); + } + + public void run() { + String path = dialog.open(); + + if (path == null) { + // cancel pressed + return; + } + + Serializer serializer = null; + final File chartFile = new File( path ); + + // Reads the chart model + try + { + serializer = SerializerImpl.instance( ); + if ( chartFile.exists( ) ) + { + chart = serializer.read( new FileInputStream( chartFile ) ); + chartView.getChartViewer().setBuffer(null); + chartView.setChart(chart); + } + } + catch ( Exception e ) + { + WizardBase.displayException( e ); + } + } + + public Chart getChart(){ + return chart; + } + +} diff --git a/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/SaveChartAction.java b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/SaveChartAction.java new file mode 100755 index 0000000..74de88b --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/SaveChartAction.java @@ -0,0 +1,286 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.charts.actions; + +import java.io.File; +import java.io.IOException; + +import org.eclipse.birt.chart.device.IDeviceRenderer; +import org.eclipse.birt.chart.exception.ChartException; +import org.eclipse.birt.chart.factory.GeneratedChartState; +import org.eclipse.birt.chart.factory.Generator; +import org.eclipse.birt.chart.factory.RunTimeContext; +import org.eclipse.birt.chart.model.Chart; +import org.eclipse.birt.chart.model.attribute.Bounds; +import org.eclipse.birt.chart.model.attribute.impl.BoundsImpl; +import org.eclipse.birt.chart.util.PluginSettings; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; +import org.eclipse.jface.action.Action; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.linuxtools.dataviewers.charts.Activator; +import org.eclipse.linuxtools.dataviewers.charts.ChartConstants; +import org.eclipse.linuxtools.dataviewers.charts.view.ChartView; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Shell; + +import com.ibm.icu.util.ULocale; + +/** + * An action to save a chart as an image (jpeg, gif, png) + * @author Marzia Maugeri + */ +public class SaveChartAction extends Action { + + private FileDialog dialog; + private Shell shell; + private Chart cm; + private IDeviceRenderer idr; + private Bounds bo; + private ChartView chartView; + + /** + * Constructor + * + * @param shell the shell used by the dialogs + */ + public SaveChartAction(Shell shell,ChartView cview) { + super("Save chart as...", Activator.getImageDescriptor("icons/save_chart.gif")); + this.chartView = cview; + this.setEnabled(false); + this.shell = shell; + this.dialog = new FileDialog(shell, SWT.SAVE); + dialog.setFileName(ChartConstants.DEFAULT_IMG_FILE_NAME); + dialog.setFilterPath(ChartConstants.DEFAULT_IMG_FILTER_PATH); + dialog.setFilterExtensions(ChartConstants.saveAsImageExt); + dialog.setFilterNames(ChartConstants.saveAsImageExtNames); + dialog.setText("Select an image file (extension will be set to \".jpeg\" if not recognized)."); + + // restore state if there is one saved + restoreState(); + } + + /** + * Sets the image plugins on the chart and enables the action if chart is not null. + * + * @param chart + */ + public void setChart(Chart chart) { + try { + if (chart != null) { + setEnabled(true); + } else { + setEnabled(false); + } + cm = chart; + } catch (Throwable _) + { + Status s = new Status( + Status.ERROR, + Activator.PLUGIN_ID, + Status.ERROR, + "Error when creating \"save as image\" action...", + _); + Activator.getDefault().getLog().log(s); + } + } + + public void setBounds(Bounds bo){ + this.bo = bo; + } + + /* + * (non-Javadoc) + * @see org.eclipse.jface.action.Action#run() + */ + public void run() { + String path = dialog.open(); + if (path == null) { + // cancel pressed + return; + } + + String ext = ""; + + + int dotIdx = path.lastIndexOf("."); + if (dotIdx > 0) ext = path.substring(dotIdx); + + try { + if (ext.equals(ChartConstants.EXT_GIF)) { + idr = PluginSettings.instance().getDevice("dv.GIF"); + } + else if (ext.equals(ChartConstants.EXT_JPEG)) { + idr = PluginSettings.instance().getDevice("dv.JPEG"); + } + else if (ext.equals(ChartConstants.EXT_JPG)) { + idr = PluginSettings.instance().getDevice("dv.JPG"); + } + else if (ext.equals(ChartConstants.EXT_PNG)) { + idr = PluginSettings.instance().getDevice("dv.PNG"); + } + else { + path += ChartConstants.EXT_JPEG; + idr = PluginSettings.instance().getDevice("dv.JPG"); + } + + } catch (ChartException e) { + Status s = new Status( + Status.ERROR, + Activator.PLUGIN_ID, + Status.ERROR, + e.getMessage(), + e); + Activator.getDefault().getLog().log(s); + } + + final File file = new File(path); + if (file.exists()) { + boolean overwrite = + MessageDialog.openQuestion(shell, "Confirm overwrite", "File already exists. Overwrite?"); + if (overwrite) { + file.delete(); + } else { + return; + } + } + + Job saveAsImage = new Job("Save chart as "+file.getName()) { + @Override + protected IStatus run(IProgressMonitor monitor) { + try { + monitor.beginTask("Saving chart as "+file.getName()+"...", IProgressMonitor.UNKNOWN); + file.createNewFile(); + generateImageFile(file); + return Status.OK_STATUS; + } catch (IOException e) { + return new Status( + IStatus.ERROR, + Activator.PLUGIN_ID, + "Error saving chart to \"" + + file.getAbsolutePath() + + "\":" + + e.getMessage(), + e); + } + } + }; + saveAsImage.setUser(true); + saveAsImage.schedule(); + + // save the state of the dialog + saveState(); + } + + /** + * Restores the state of this action (file dialog) + */ + public void restoreState() { + try { + IDialogSettings settings = + Activator.getDefault().getDialogSettings().getSection(ChartConstants.TAG_SECTION_BIRTCHARTS_SAVEACTION_STATE); + if (settings == null) { + settings = Activator.getDefault().getDialogSettings().addNewSection(ChartConstants.TAG_SECTION_BIRTCHARTS_SAVEACTION_STATE); + return; + } + + dialog.setFileName(settings.get(ChartConstants.TAG_IMG_FILE_NAME)); + dialog.setFilterPath(settings.get(ChartConstants.TAG_IMG_FILTER_PATH)); + } + catch (Exception e) { + Status s = new Status( + Status.ERROR, + Activator.PLUGIN_ID, + Status.ERROR, + e.getMessage(), + e); + Activator.getDefault().getLog().log(s); + } + } + + /** + * Saves the state of this action (file dialog) + */ + public void saveState() { + try { + IDialogSettings settings = + Activator.getDefault().getDialogSettings().getSection(ChartConstants.TAG_SECTION_BIRTCHARTS_SAVEACTION_STATE); + if (settings == null) { + settings = Activator.getDefault().getDialogSettings().addNewSection(ChartConstants.TAG_SECTION_BIRTCHARTS_SAVEACTION_STATE); + } + + settings.put(ChartConstants.TAG_IMG_FILE_NAME, dialog.getFileName()); + settings.put(ChartConstants.TAG_IMG_FILTER_PATH, dialog.getFilterPath()); + } + catch (Exception e) { + Status s = new Status( + Status.ERROR, + Activator.PLUGIN_ID, + Status.ERROR, + e.getMessage(), + e); + Activator.getDefault().getLog().log(s); + } + } + + protected void generateImageFile(File file){ + RunTimeContext rtc = new RunTimeContext( ); + rtc.setULocale( ULocale.getDefault( ) ); + + final Generator gr = Generator.instance( ); + GeneratedChartState gcs = null; + + Bounds boFile = null; + bo = chartView.getChartViewer().getBounds(); + //Set the chart size + if (bo != null){ + boFile = BoundsImpl.create(bo.getLeft(), bo.getTop(), bo.getWidth(), bo.getHeight()); + } + else{ + boFile = BoundsImpl.create(0, 0, 800, 600); + } + + + try { + gcs = gr.build( idr.getDisplayServer( ), cm, boFile, null, rtc, null ); + } catch (ChartException e) { + Status s = new Status( + Status.ERROR, + Activator.PLUGIN_ID, + Status.ERROR, + e.getMessage(), + e); + Activator.getDefault().getLog().log(s); + } + + //Specify the file to write to. + idr.setProperty( IDeviceRenderer.FILE_IDENTIFIER, file.getAbsolutePath() ); + + //generate the chart + try { + gr.render( idr, gcs ); + } catch (ChartException e) { + Status s = new Status( + Status.ERROR, + Activator.PLUGIN_ID, + Status.ERROR, + e.getMessage(), + e); + Activator.getDefault().getLog().log(s); + } + } + + +} diff --git a/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/SaveXMLAction.java b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/SaveXMLAction.java new file mode 100644 index 0000000..aa36687 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/actions/SaveXMLAction.java @@ -0,0 +1,133 @@ +/*********************************************************************** + * Copyright (c) 2004, 2005 Actuate Corporation. + * 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: + * Actuate Corporation - initial API and implementation + ***********************************************************************/ + +package org.eclipse.linuxtools.dataviewers.charts.actions; + +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; + +import org.eclipse.birt.chart.model.Chart; +import org.eclipse.birt.chart.model.Serializer; +import org.eclipse.birt.chart.model.impl.SerializerImpl; +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.action.Action; +import org.eclipse.linuxtools.dataviewers.charts.Activator; +import org.eclipse.linuxtools.dataviewers.charts.UIHelper; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.MessageBox; + +public class SaveXMLAction extends Action +{ + + private Composite cmp; + private Chart cm; + + public SaveXMLAction( Composite parent ) + { + super( ); + cmp = parent; + setImageDescriptor( UIHelper.getImageDescriptor( "icons/eexport.gif" ) ); + setDisabledImageDescriptor( UIHelper.getImageDescriptor( "icons/dexport.gif" ) ); + setToolTipText( "Save XML Source" ); + setDescription( "Save XML Source to the designated directory" ); + } + + /** + * When the action is invoked, pop up a File Dialog to designate the + * directory. + */ + public void run( ) + { + if ( cm != null ) + { + final FileDialog saveDialog = new FileDialog( cmp.getShell( ), + SWT.SAVE ); + saveDialog.setFilterExtensions( new String[]{ + "*.chart"} ); //$NON-NLS-1$ + try + { + saveDialog.open( ); + String name = saveDialog.getFileName( ); + if ( name != null && name != "" ) //$NON-NLS-1$ + { + Serializer serializer = null; + final File file = new File( saveDialog.getFilterPath( ), + name ); + if ( file.exists( ) ) + { + MessageBox box = new MessageBox( cmp.getShell( ), + SWT.ICON_WARNING | SWT.YES | SWT.NO ); + box.setText( "Save XML Source"); //$NON-NLS-1$ + box.setMessage( "The XML source already exists in the directory. \nDo you want to replace it?" ); + if ( box.open( ) != SWT.YES ) + { + return; + } + } + + serializer = SerializerImpl.instance( ); + try + { + // FIXED: Cloned instance of cm object must be passed. Otherwise, the chart(cm object) does not be scaled by resize event. + serializer.write( cm.copyInstance(), new FileOutputStream( file ) ); + IFile c = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(new Path(file.getAbsolutePath())); + if (c != null){ + try { + c.refreshLocal(1, new NullProgressMonitor()); + } catch (CoreException e) { + IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, e.getMessage(), e); + Activator.getDefault().getLog().log(status); + } + } + + } + catch ( IOException ioe ) + { + ioe.printStackTrace( ); + } + } + } + catch ( Throwable e ) + { + e.printStackTrace( ); + } + } + } + + public void setChart(Chart chart) { + try { + if (chart != null) { + setEnabled(true); + } else { + setEnabled(false); + } + cm = chart; + } catch (Throwable _) + { + Status s = new Status( + Status.ERROR, + Activator.PLUGIN_ID, + Status.ERROR, + "Error when creating \"save as image\" action...", + _); + Activator.getDefault().getLog().log(s); + } + } +} diff --git a/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/dataengine/BindDataEngine.java b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/dataengine/BindDataEngine.java new file mode 100644 index 0000000..a6d2d3a --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/dataengine/BindDataEngine.java @@ -0,0 +1,364 @@ +/******************************************************************************* + * Copyright (c) 2008 Actuate Corporation. + * 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: + * Actuate Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.charts.dataengine; + +import org.eclipse.birt.chart.exception.ChartException; +import org.eclipse.birt.chart.factory.Generator; +import org.eclipse.birt.chart.factory.IDataRowExpressionEvaluator; +import org.eclipse.birt.chart.factory.RunTimeContext; +import org.eclipse.birt.chart.model.Chart; +import org.eclipse.birt.chart.model.ChartWithAxes; +import org.eclipse.birt.chart.model.attribute.AxisType; +import org.eclipse.birt.chart.model.attribute.IntersectionType; +import org.eclipse.birt.chart.model.attribute.LegendItemType; +import org.eclipse.birt.chart.model.attribute.Position; +import org.eclipse.birt.chart.model.attribute.TickStyle; +import org.eclipse.birt.chart.model.attribute.impl.ColorDefinitionImpl; +import org.eclipse.birt.chart.model.component.Axis; +import org.eclipse.birt.chart.model.component.Series; +import org.eclipse.birt.chart.model.component.impl.SeriesImpl; +import org.eclipse.birt.chart.model.data.SeriesDefinition; +import org.eclipse.birt.chart.model.data.impl.QueryImpl; +import org.eclipse.birt.chart.model.data.impl.SeriesDefinitionImpl; +import org.eclipse.birt.chart.model.impl.ChartWithAxesImpl; +import org.eclipse.birt.chart.model.layout.Legend; +import org.eclipse.birt.chart.model.layout.Plot; +import org.eclipse.birt.chart.model.type.BarSeries; +import org.eclipse.birt.chart.model.type.impl.BarSeriesImpl; +import org.eclipse.birt.core.archive.IDocArchiveReader; +import org.eclipse.birt.core.archive.IDocArchiveWriter; +import org.eclipse.birt.core.data.Constants; +import org.eclipse.birt.core.data.ExpressionUtil; +import org.eclipse.birt.core.exception.BirtException; +import org.eclipse.birt.data.aggregation.api.IBuildInAggregation; +import org.eclipse.birt.data.engine.api.DataEngine; +import org.eclipse.birt.data.engine.api.DataEngineContext; +import org.eclipse.birt.data.engine.api.IGroupDefinition; +import org.eclipse.birt.data.engine.api.IPreparedQuery; +import org.eclipse.birt.data.engine.api.IQueryResults; +import org.eclipse.birt.data.engine.api.querydefn.Binding; +import org.eclipse.birt.data.engine.api.querydefn.GroupDefinition; +import org.eclipse.birt.data.engine.api.querydefn.OdaDataSetDesign; +import org.eclipse.birt.data.engine.api.querydefn.OdaDataSourceDesign; +import org.eclipse.birt.data.engine.api.querydefn.QueryDefinition; +import org.eclipse.birt.data.engine.api.querydefn.ScriptExpression; +import org.eclipse.birt.data.engine.core.DataException; +import org.eclipse.linuxtools.dataviewers.charts.Activator; + +import com.ibm.icu.util.ULocale; + +/** + * The example demonstrates how chart works with ODA/DtE(BIRT data engine) to + * get grouped/aggregated data set, the ODA/DtE is responsible to execute data + * query and grouping/aggregation, it returns a grouped data set to chart and + * chart retrieve data without grouping/aggregation by chart-self. + *

+ * In the example, it only uses flat file as data source, actually it supports + * any JDBC data source, referring to {@link org.eclipse.birt.data.engine} to + * get detail information. + * + * @since 2.3 + */ +public class BindDataEngine +{ + private String[] columnsName = null; + private FlatFileDataSource ffds = null; + + /** + * Create runtime chart model and bind data. + * + * @return + * @throws ChartException + */ + public final Chart createWorkingWithBIRTDataEngine(FlatFileDataSource ffds) + throws ChartException + { + this.ffds = ffds; + columnsName = ffds.getCOLUMNNAME(); + String[] expressions = new String[columnsName.length]; + expressions[0] = ExpressionUtil.createRowExpression( columnsName[0] ); + expressions[1] = ExpressionUtil.createRowExpression( columnsName[1] ); + + ChartWithAxes cwaBar = createChartModel( expressions ); + + cwaBar = bindData( cwaBar, expressions ); + + return cwaBar; + } + + /** + * Create chart model. + * + * @param expressions + * expressions are used to set category series and value series. + * @return + */ + private static ChartWithAxes createChartModel( String[] expressions ) + { + ChartWithAxes cwaBar = ChartWithAxesImpl.create( ); + cwaBar.setType( "Bar Chart" ); + cwaBar.setSubType( "Side-by-side" ); + // Plot + cwaBar.getBlock( ).setBackground( ColorDefinitionImpl.WHITE( ) ); + cwaBar.getBlock( ).getOutline( ).setVisible( true ); + Plot p = cwaBar.getPlot( ); + p.getClientArea( ).setBackground( ColorDefinitionImpl.create( 255, + 255, + 225 ) ); + + // Title + cwaBar.getTitle( ) + .getLabel( ) + .getCaption( ) + .setValue( "Working with BIRT Data Engine" ); + + // Legend + Legend lg = cwaBar.getLegend( ); + lg.setItemType( LegendItemType.CATEGORIES_LITERAL ); + + // X-Axis + Axis xAxisPrimary = cwaBar.getPrimaryBaseAxes( )[0]; + + xAxisPrimary.setType( AxisType.TEXT_LITERAL ); + xAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.BELOW_LITERAL ); + xAxisPrimary.getOrigin( ).setType( IntersectionType.MIN_LITERAL ); + + // Y-Axis + Axis yAxisPrimary = cwaBar.getPrimaryOrthogonalAxis( xAxisPrimary ); + yAxisPrimary.getMajorGrid( ).setTickStyle( TickStyle.LEFT_LITERAL ); + yAxisPrimary.setType( AxisType.LINEAR_LITERAL ); + yAxisPrimary.getLabel( ).getCaption( ).getFont( ).setRotation( 90 ); + yAxisPrimary.getTitle( ).setVisible( true ); + yAxisPrimary.getTitle( ).getCaption( ).setValue( "Customer Amount" ); //$NON-NLS-1$ + yAxisPrimary.getTitle( ) + .getCaption( ) + .setColor( ColorDefinitionImpl.GREEN( ) ); + + // X-Series + Series seCategory = SeriesImpl.create( ); + // seCategory.setDataSet( categoryValues ); + + // Set category expression. + seCategory.getDataDefinition( ) + .add( QueryImpl.create( expressions[0] ) ); + + SeriesDefinition sdX = SeriesDefinitionImpl.create( ); + sdX.getSeriesPalette( ).shift( 0 ); + + xAxisPrimary.getSeriesDefinitions( ).add( sdX ); + sdX.getSeries( ).add( seCategory ); + + // Y-Series + BarSeries bs1 = (BarSeries) BarSeriesImpl.create( ); + bs1.getDataDefinition( ).add( QueryImpl.create( expressions[1] ) ); + bs1.getLabel( ).setVisible( true ); + bs1.setLabelPosition( Position.INSIDE_LITERAL ); + + SeriesDefinition sdY = SeriesDefinitionImpl.create( ); + yAxisPrimary.getSeriesDefinitions( ).add( sdY ); + sdY.getSeries( ).add( bs1 ); + return cwaBar; + } + + /** + * Binds data into chart model. + * + * @param cwaBar + * @return + * @throws ChartException + */ + private ChartWithAxes bindData( ChartWithAxes cwaBar, + String[] expressions ) throws ChartException + { + + RunTimeContext context = new RunTimeContext( ); + context.setULocale( ULocale.getDefault( ) ); + + IDataRowExpressionEvaluator evaluator; + try + { + // Create row expression evaluator for chart doing data binding. + evaluator = prepareRowExpressionEvaluator( cwaBar, expressions ); + + // Binding data. + Generator.instance( ).bindData( evaluator, cwaBar, context ); + } + catch ( BirtException e ) + { + throw new ChartException( Activator.PLUGIN_ID, + ChartException.DATA_BINDING, + e ); + } + return cwaBar; + } + + /** + * Uses BIRT data engine to do query and wraps data with + * IDataRowExpressionEvaluator for chart doing data binding. + * + * @return + * @throws BirtException + */ + private IDataRowExpressionEvaluator prepareRowExpressionEvaluator( + ChartWithAxes chart, String[] expressions ) throws BirtException + { + + // Initialize data source and data set. + OdaDataSourceDesign odaDataSource = newDataSource( ); + OdaDataSetDesign odaDataSet = newDataSet( odaDataSource ); + + // Create query definition. + QueryDefinition query = createQueryDefinition( odaDataSet, expressions ); + + // Create data engine and execute query. + DataEngine dataEngine = newDataEngine( ); + dataEngine.defineDataSource( odaDataSource ); + dataEngine.defineDataSet( odaDataSet ); + IPreparedQuery preparedQuery = dataEngine.prepare( query ); + + IQueryResults queryResults = preparedQuery.execute( null ); + + // Create row expression evaluator. + return new GroupedRowExpressionsEvaluator( queryResults.getResultIterator( ), + true ); + } + + /** + * Create query definition. + * + * @param odaDataSet + * @param expressions + * @return + * @throws ChartException + */ + private QueryDefinition createQueryDefinition( + OdaDataSetDesign odaDataSet, String[] expressions ) + throws ChartException + { + + QueryDefinition queryDefn = new QueryDefinition( ); + queryDefn.setDataSetName( odaDataSet.getName( ) ); + + try + { + initDefaultBindings( queryDefn ); + + // Add group definitions and aggregation binding. + String groupName = "Group_Country"; //$NON-NLS-1$ + GroupDefinition gd = new GroupDefinition( groupName ); + gd.setKeyExpression( expressions[0] ); + gd.setInterval( IGroupDefinition.NO_INTERVAL ); + gd.setIntervalRange( 0 ); + + // Add expression bindings. + for ( int i = 0; i < expressions.length; i++ ) + { + String expr = (String) expressions[i]; + Binding colBinding = new Binding( expr ); + colBinding.setExpression( new ScriptExpression( expr ) ); + if ( i == 1 ) + { + colBinding.setExpression( null ); + colBinding.setAggrFunction( IBuildInAggregation.TOTAL_COUNT_FUNC ); + colBinding.addAggregateOn( groupName ); + colBinding.addArgument( new ScriptExpression( expressions[i] ) ); + } + + queryDefn.addBinding( colBinding ); + } + + queryDefn.addGroup( gd ); + } + catch ( DataException e ) + { + throw new ChartException( Activator.PLUGIN_ID, + ChartException.DATA_BINDING, + e ); + } + + return queryDefn; + } + + /** + * Initialize default column bindings for original columns. + * + * @param queryDefn + * @throws DataException + */ + private void initDefaultBindings( QueryDefinition queryDefn ) + throws DataException + { + + for(int i=0;i - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.charts.dataengine; + +/** + * Resource of flat file data. + */ +public class FlatFileDataSource { + static final String DATA_SOURCE_TYPE = "org.eclipse.datatools.connectivity.oda.flatfile"; + static final String DATA_SET_TYPE = "org.eclipse.datatools.connectivity.oda.flatfile.dataSet"; + static final String CHARSET = "UTF-8"; + static final String DELIMTYPE = "TAB"; + static final String INCLTYPELINE = "NO"; + protected String HOME = null; + + protected String dataFile = ""; + protected String query = ""; + protected String[] columnsName = null; + + public FlatFileDataSource(){ + } + + public FlatFileDataSource(String HOME,String dataFile,String query,String[] columns){ + this.HOME = HOME; + this.dataFile = dataFile; + this.query = query; + this.columnsName = columns; + } + + protected void setHOME_VARIABLE(String home){ + HOME = home; + } + + protected String getHOME(){ + return HOME; + } + + protected void setDataFile(String fileName){ + dataFile = fileName; + } + + protected String getDataFile(){ + return dataFile; + } + + protected void setQuery(String query){ + this.query = query; + } + + protected String getQuery(){ + return query; + } + + protected String[] getCOLUMNNAME(){ + return columnsName; + } + + protected void setCOLUMNName(String[] cn){ + columnsName = cn; + } + +} diff --git a/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/dataengine/FlatFileDataSourceFactory.java b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/dataengine/FlatFileDataSourceFactory.java new file mode 100644 index 0000000..5f5d4a8 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/dataengine/FlatFileDataSourceFactory.java @@ -0,0 +1,40 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.charts.dataengine; + +public class FlatFileDataSourceFactory { + public FlatFileDataSourceFactory(){ + } + + public String createHomeVariable(){ + return null; + } + + public String createFileName(){ + return null; + + } + + public String createQuery(){ + return null; + + } + + public String[] createColumns(){ + return null; + } + + public FlatFileDataSource createFlatFileDataSource(){ + return new FlatFileDataSource(createHomeVariable(),createFileName(),createQuery(),createColumns()); + } + + +} diff --git a/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/dataengine/GroupedRowExpressionsEvaluator.java b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/dataengine/GroupedRowExpressionsEvaluator.java new file mode 100644 index 0000000..b56d135 --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/dataengine/GroupedRowExpressionsEvaluator.java @@ -0,0 +1,280 @@ +/******************************************************************************* + * Copyright (c) 2008 Actuate Corporation. + * 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: + * Actuate Corporation - initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.dataviewers.charts.dataengine; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.birt.chart.exception.ChartException; +import org.eclipse.birt.chart.factory.AbstractGroupedDataRowExpressionEvaluator; +import org.eclipse.birt.chart.log.ILogger; +import org.eclipse.birt.chart.log.Logger; +import org.eclipse.birt.core.exception.BirtException; +import org.eclipse.birt.data.engine.api.IGroupDefinition; +import org.eclipse.birt.data.engine.api.IResultIterator; + +/** + * The class implements an evaluator to retrieve grouped row data. + * @since 2.3 + */ +public class GroupedRowExpressionsEvaluator extends + AbstractGroupedDataRowExpressionEvaluator +{ + + private static ILogger sLogger = Logger.getLogger( "org.eclipse.birt.chart.examples/trace" ); //$NON-NLS-1$ + + private IResultIterator fResultIterator; + + private boolean fIsGrouped = false; + + private int fGroupCount; + + private List[] faGroupBreaks; + + private int fCountOfAvaiableRows = 0; + + private boolean fHasAggregation = false; + + /** + * Constructor. + * + * @param resultSet + * @param hasAggregation + * @param cm + * @throws ChartException + */ + public GroupedRowExpressionsEvaluator( IResultIterator resultIterator, + boolean hasAggregation ) throws ChartException + { + fHasAggregation = hasAggregation; + + fResultIterator = resultIterator; + List groupDefinitions = fResultIterator.getQueryResults( ) + .getPreparedQuery( ) + .getReportQueryDefn( ) + .getGroups( ); + if ( groupDefinitions != null && groupDefinitions.size( ) > 0 ) + { + fIsGrouped = true; + fGroupCount = groupDefinitions.size( ); + + faGroupBreaks = new List[groupDefinitions.size( )]; + for ( int i = 0; i < faGroupBreaks.length; i++ ) + { + faGroupBreaks[i] = new ArrayList( ); + } + } + } + + /** + * Get list of group breaks, the group level is base on 0th index, 0 index + * means outermost group. + * + * @param groupLevel + * @return + */ + private List getGroupBreaksList( int groupLevel ) + { + if ( faGroupBreaks == null + || groupLevel < 0 + || groupLevel > ( faGroupBreaks.length - 1 ) ) + { + return new ArrayList( ); + } + + return faGroupBreaks[groupLevel]; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.birt.chart.factory.IGroupedDataResultSet#getGroupBreaks(int) + */ + public int[] getGroupBreaks( int groupLevel ) + { + Object[] breaksArray = getGroupBreaksList( groupLevel ).toArray( ); + int[] breaks = new int[breaksArray.length]; + for ( int i = 0; i < breaksArray.length; i++ ) + { + breaks[i] = ( (Integer) breaksArray[i] ).intValue( ); + } + return breaks; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.birt.chart.factory.IDataRowExpressionEvaluator#close() + */ + public void close( ) + { + try + { + fResultIterator.close( ); + } + catch ( BirtException e ) + { + sLogger.log( e ); + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.birt.chart.factory.IDataRowExpressionEvaluator#evaluate(java.lang.String) + */ + public Object evaluate( String expression ) + { + try + { + // Here, the expression should be binding name. + return fResultIterator.getValue( expression ); + } + catch ( BirtException e ) + { + sLogger.log( e ); + } + return null; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.birt.chart.factory.IDataRowExpressionEvaluator#evaluateGlobal(java.lang.String) + */ + public Object evaluateGlobal( String expression ) + { + return evaluate( expression ); + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.birt.chart.factory.IDataRowExpressionEvaluator#first() + */ + public boolean first( ) + { + try + { + fCountOfAvaiableRows = 0; + + if ( !fIsGrouped ) + { + if ( fResultIterator.next( ) ) + { + return true; + } + } + else + { + if ( findFirst( ) ) + { + return true; + } + } + } + catch ( BirtException e ) + { + sLogger.log( e ); + } + return false; + } + + /** + * Find the first row position. + * + * @return + * @throws BirtException + */ + private boolean findFirst( ) throws BirtException + { + if ( !fResultIterator.next( ) ) + { + return false; + } + + int groupLevel = fResultIterator.getStartingGroupLevel( ); + if ( groupLevel == 0 ) // It means the start of current row data. + { + return true; + } + else + { + return findFirst( ); + } + } + + /** + * Find next available row position. If it has grouped-enabled, should + * ignore non-grouped/non-aggregation row. + * + * @return + * @throws BirtException + */ + private boolean findNext( ) throws BirtException + { + while ( fResultIterator.next( ) ) + { + int startIndex = fResultIterator.getStartingGroupLevel( ); + if ( startIndex > 0 && startIndex <= fGroupCount ) + { + fCountOfAvaiableRows++; + // Add break point to current grouping. + getGroupBreaksList( startIndex - 1 ).add( new Integer( fCountOfAvaiableRows ) ); + // Also the sub-groupings of current grouping should be + // added the break point. + for ( int i = startIndex; i < fGroupCount; i++ ) + { + getGroupBreaksList( i ).add( new Integer( fCountOfAvaiableRows ) ); + } + + return true; + } + + if ( !fHasAggregation ) + { + fCountOfAvaiableRows++; + return true; + } + } + return false; + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.birt.chart.factory.IDataRowExpressionEvaluator#next() + */ + public boolean next( ) + { + try + { + if ( !fIsGrouped ) + { + if ( fResultIterator.next( ) ) + { + fCountOfAvaiableRows++; + return true; + } + } + else + { + return findNext( ); + } + } + catch ( BirtException e ) + { + sLogger.log( e ); + } + return false; + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/dialogs/ChartDialog.java b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/dialogs/ChartDialog.java new file mode 100755 index 0000000..76be33e --- /dev/null +++ b/org.eclipse.linuxtools.dataviewers.charts/src/org/eclipse/linuxtools/dataviewers/charts/dialogs/ChartDialog.java @@ -0,0 +1,427 @@ +/******************************************************************************* + * Copyright (c) 2009 STMicroelectronics. + * 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: + * Marzia Maugeri - initial API and implementation + *******************************************************************************/ +package org.eclipse.linuxtools.dataviewers.charts.dialogs; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; + +import org.eclipse.birt.chart.model.Chart; +import org.eclipse.jface.dialogs.Dialog; +import org.eclipse.jface.dialogs.IDialogConstants; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.linuxtools.dataviewers.abstractviewers.AbstractSTViewer; +import org.eclipse.linuxtools.dataviewers.abstractviewers.ISTDataViewersField; +import org.eclipse.linuxtools.dataviewers.charts.Activator; +import org.eclipse.linuxtools.dataviewers.charts.ChartConstants; +import org.eclipse.linuxtools.dataviewers.charts.provider.ChartFactory; +import org.eclipse.linuxtools.dataviewers.charts.provider.IChartField; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.SelectionListener; +import org.eclipse.swt.layout.FillLayout; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Text; + +/** + * The dialog used to customize the chart before cerating it. + */ +public class ChartDialog extends Dialog { + + private final AbstractSTViewer stViewer; + private Chart chart; + + private Text errorMessageText; + private Button verticalBarsButton; + private Button pieChartButton; + private Button barGraphButton; + private Button okButton; + private List