From 6e651d8b5b6dd888b53ab0871736329a151dcfa6 Mon Sep 17 00:00:00 2001 From: Marc-Andre Laperle Date: Wed, 18 Sep 2013 18:19:26 -0400 Subject: [PATCH] tmf: Import and Export trace package Import and export files, bookmarks, supplementary files for a single trace as an archive (tar, tar.gz or zip) Change-Id: I71f5f104b2c552a5dbb2721fbdde9b069dd1a306 Signed-off-by: Marc-Andre Laperle Reviewed-on: https://git.eclipse.org/r/17666 Reviewed-by: Bernd Hufmann IP-Clean: Bernd Hufmann Tested-by: Bernd Hufmann Tested-by: Hudson CI --- .../.settings/org.eclipse.jdt.core.prefs | 2 +- .../META-INF/MANIFEST.MF | 2 + .../icons/etool16/export.gif | Bin 0 -> 329 bytes .../icons/wizban/export_wiz.png | Bin 0 -> 6675 bytes .../plugin.properties | 9 + org.eclipse.linuxtools.tmf.ui/plugin.xml | 117 +++- .../schema/export-manifest.xsd | 60 ++ .../project/handlers/DeleteTraceHandler.java | 37 +- .../AbstractTracePackageOperation.java | 332 +++++++++++ .../AbstractTracePackageWizardPage.java | 542 ++++++++++++++++++ .../tracepkg/ITracePackageConstants.java | 76 +++ .../ui/project/wizards/tracepkg/Messages.java | 84 +++ .../tracepkg/TracePackageBookmarkElement.java | 66 +++ .../tracepkg/TracePackageContentProvider.java | 57 ++ .../wizards/tracepkg/TracePackageElement.java | 139 +++++ .../tracepkg/TracePackageFilesElement.java | 107 ++++ .../tracepkg/TracePackageLabelProvider.java | 69 +++ .../TracePackageSupplFileElement.java | 89 +++ .../TracePackageSupplFilesElement.java | 47 ++ .../tracepkg/TracePackageTraceElement.java | 87 +++ .../ExportTracePackageHandler.java | 54 ++ ...portTracePackageSelectTraceWizardPage.java | 155 +++++ .../ExportTracePackageWizard.java | 67 +++ .../ExportTracePackageWizardPage.java | 450 +++++++++++++++ .../ImportTracePackageHandler.java | 53 ++ .../ImportTracePackageWizard.java | 63 ++ .../ImportTracePackageWizardPage.java | 354 ++++++++++++ .../tracepkg/importexport/Messages.java | 234 ++++++++ .../TracePackageExportOperation.java | 279 +++++++++ .../TracePackageExtractManifestOperation.java | 243 ++++++++ .../TracePackageImportOperation.java | 432 ++++++++++++++ .../tracepkg/importexport/messages.properties | 52 ++ .../wizards/tracepkg/messages.properties | 22 + .../tmf/ui/project/model/TmfTraceElement.java | 44 ++ 34 files changed, 4386 insertions(+), 38 deletions(-) create mode 100644 org.eclipse.linuxtools.tmf.ui/icons/etool16/export.gif create mode 100644 org.eclipse.linuxtools.tmf.ui/icons/wizban/export_wiz.png create mode 100644 org.eclipse.linuxtools.tmf.ui/schema/export-manifest.xsd create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/AbstractTracePackageOperation.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/AbstractTracePackageWizardPage.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/ITracePackageConstants.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/Messages.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageBookmarkElement.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageContentProvider.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageElement.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageFilesElement.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageLabelProvider.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageSupplFileElement.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageSupplFilesElement.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageTraceElement.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ExportTracePackageHandler.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ExportTracePackageSelectTraceWizardPage.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ExportTracePackageWizard.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ExportTracePackageWizardPage.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ImportTracePackageHandler.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ImportTracePackageWizard.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ImportTracePackageWizardPage.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/Messages.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageExportOperation.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageExtractManifestOperation.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageImportOperation.java create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/messages.properties create mode 100644 org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/messages.properties diff --git a/org.eclipse.linuxtools.tmf.ui/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.linuxtools.tmf.ui/.settings/org.eclipse.jdt.core.prefs index d13ab1415a..7aeec7f8d4 100644 --- a/org.eclipse.linuxtools.tmf.ui/.settings/org.eclipse.jdt.core.prefs +++ b/org.eclipse.linuxtools.tmf.ui/.settings/org.eclipse.jdt.core.prefs @@ -21,7 +21,7 @@ org.eclipse.jdt.core.compiler.problem.deadCode=error org.eclipse.jdt.core.compiler.problem.deprecation=warning org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=enabled org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled -org.eclipse.jdt.core.compiler.problem.discouragedReference=error +org.eclipse.jdt.core.compiler.problem.discouragedReference=warning org.eclipse.jdt.core.compiler.problem.emptyStatement=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=error diff --git a/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF b/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF index 57845bed6d..9bda17fc6f 100644 --- a/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF +++ b/org.eclipse.linuxtools.tmf.ui/META-INF/MANIFEST.MF @@ -26,6 +26,8 @@ Export-Package: org.eclipse.linuxtools.internal.tmf.ui;x-friends:="org.eclipse.l org.eclipse.linuxtools.internal.tmf.ui.project.dialogs;x-internal:=true, org.eclipse.linuxtools.internal.tmf.ui.project.handlers;x-internal:=true, org.eclipse.linuxtools.internal.tmf.ui.project.model;x-friends:="org.eclipse.linuxtools.lttng2.ui,org.eclipse.linuxtools.tmf.ui.tests", + org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg;x-internal:=true, + org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.importexport;x-internal:=true, org.eclipse.linuxtools.tmf.ui.editors, org.eclipse.linuxtools.tmf.ui.project.model, org.eclipse.linuxtools.tmf.ui.project.wizards, diff --git a/org.eclipse.linuxtools.tmf.ui/icons/etool16/export.gif b/org.eclipse.linuxtools.tmf.ui/icons/etool16/export.gif new file mode 100644 index 0000000000000000000000000000000000000000..5a0837d1e475ec48731c88f6d554a37750df4693 GIT binary patch literal 329 zcmZ?wbhEHb6krfwxXQp_Z$IBYe!fro^uXMCfjM(S@)ri=&J8YD7??XZC~s~=$&!eY z#Sx{8BTE;@R4k9LS)EY3I=*^Ea{bzr`n73I>suF|ZCiMD?&fRpK=ImD$qj2;7oBYb zp)(U!U0S~T*77~K)*rlUT(HErV6j8_a^9F(|NsAIpdL{C$->CMpvIsBG7{t`2DUVZ z$ps!dQvDvvnIT%LohlPQYwEbJT&CH{W#Fcfkd(lo*X}eWaeB?N3@5410-q@!PLq$b ze>&4(z$eb<-^j-+$H~RR-P7AE$IUJyBP}B~Ra#nBMsx}*6B`>d2iuZ`94lB>M7TII GSOWlifno0e literal 0 HcmV?d00001 diff --git a/org.eclipse.linuxtools.tmf.ui/icons/wizban/export_wiz.png b/org.eclipse.linuxtools.tmf.ui/icons/wizban/export_wiz.png new file mode 100644 index 0000000000000000000000000000000000000000..aa787ef5614dd941b2853cb7c4e2f74d9a6678da GIT binary patch literal 6675 zcmV+u8tmnXP)002S=1^@s6A3-Z300009a7bBm000XU z000XU0RWnu7ytkYO=&|zP*7-ZbZ>KLZ*U+5Lu!Sk^o_Z5E4Meg@_7P6crJiNL9pw)e1;Xm069{HJUZAPk55R%$-RIA z6-eL&AQ0xu!e<4=008gy@A0LT~suv4>S3ILP<0Bm`DLLvaF4FK%)Nj?Pt*r}7;7Xa9z9H|HZjR63e zC`Tj$K)V27Re@400>HumpsYY5E(E}?0f1SyGDiY{y#)Yvj#!WnKwtoXnL;eg03bL5 z07D)V%>y7z1E4U{zu>7~aD})?0RX_umCct+(lZpemCzb@^6=o|A>zVpu|i=NDG+7} zl4`aK{0#b-!z=TL9Wt0BGO&T{GJWpjryhdijfaIQ&2!o}p04JRKYg3k&Tf zVxhe-O!X z{f;To;xw^bEES6JSc$k$B2CA6xl)ltA<32E66t?3@gJ7`36pmX0IY^jz)rRYwaaY4 ze(nJRiw;=Qb^t(r^DT@T3y}a2XEZW-_W%Hszxj_qD**t_m!#tW0KDiJT&R>6OvVTR z07RgHDzHHZ48atvzz&?j9lXF70$~P3Knx_nJP<+#`N z#-MZ2bTkiLfR>_b(HgWKJ%F~Nr_oF3b#wrIijHG|(J>BYjM-sajE6;FiC7vY#};Gd zST$CUHDeuEH+B^pz@B062qXfFfD`NpUW5?BY=V%GM_5c)L#QR}BeW8_2v-S%gfYS= zB9o|3v?Y2H`NVi)In3rTB8+ej^> zQ=~r95NVuDChL%G$=>7$vVg20myx%S50Foi`^m%Pw-h?Xh~i8Mq9jtJloCocWk2Nv zrJpiFnV_ms&8eQ$2&#xWpIS+6pmtC%Q-`S&GF4Q#^mhymh7E(qNMa}%YZ-ePrx>>xFPTiH1=E+A$W$=bG8>s^ zm=Bn5Rah$aDtr}@$`X}2l~$F0mFKEdRdZE8)p@E5RI61Ft6o-prbbn>P~)iy)E2AN zsU20jsWz_8Qg>31P|s0cqrPALg8E|(vWA65poU1JRAaZs8I2(p#xiB`SVGovRs-uS zYnV-9TeA7=Om+qP8+I>yOjAR1s%ETak!GFdam@h^# z)@rS0t$wXH+Irf)+G6c;?H29p+V6F6oj{!|o%K3xI`?%6x;DB|x`n#ibhIR?(H}Q3Gzd138Ei2)WAMz7W9Vy`X}HnwgyEn!VS)>mv$8&{hQn>w4zwy3R}t;BYlZQm5)6pty=DfLrs+A-|>>;~;Q z_F?uV_HFjh9n2gO9o9Q^JA86v({H5aB!kjoO6 zc9$1ZZKsN-Zl8L~mE{`ly3)1N^`o1+o7}D0ZPeY&J;i;i`%NyJ8_8Y6J?}yE@b_5a zam?eLr<8@mESk|3$_SkmS{wQ>%qC18))9_|&j{ZT zes8AvOzF(F2#DZEY>2oYX&IRp`F#{ADl)1r>QS^)ba8a|EY_^#S^HO&t^Rgqwv=MZThqqEWH8 zxJo>d=ABlR_Bh=;eM9Tw|Ih34~oTE|= zX_mAr*D$vzw@+p(E0Yc6dFE}(8oqt`+R{gE3x4zjX+Sb3_cYE^= zgB=w+-tUy`ytONMS8KgRef4hA?t0j zufM;t32jm~jUGrkaOInTZ`zyfns>EuS}G30LFK_G-==(f<51|K&cocp&EJ`SxAh3? zNO>#LI=^+SEu(FqJ)ynt=!~PC9bO$rzPJB=?=j6w@a-(u02P7 zaQ)#(uUl{HW%tYNS3ItC^iAtK(eKlL`f9+{bJzISE?u8_z3;~C8@FyI-5j_jy7l;W z_U#vU3hqqYU3!mrul&B+{ptt$59)uk{;_4iZQ%G|z+lhASr6|H35TBkl>gI*;nGLU zN7W-nBaM%pA0HbH8olyl&XeJ%vZoWz%6?Y=dFykl=imL}`%BMQ{Mhgd`HRoLu6e2R za__6DuR6yg#~-}Tc|Gx_{H@O0eebyMy5GmWADJlpK>kqk(fVV@r_fLLKIeS?{4e)} z^ZO;zpECde00d`2O+f$vv5tKEQIh}w03c&XQcVB=dL;k=fP(-4`Tqa_faw4Lbua(` z>RI+y?e7jKeZ#YO-C4=_nYK~#9!>|A?{9o2dNedo-5?%lh0cWp12HLO`bz{X&R zX(1s6BBUl2Qh_KfRig;Ce^d%pRS7jx)2h&_QY%7AqgF|pl!6eIViA>x2qhvB;Z;aN zTA+cX7zaCRd%a%o`*H6)&iCsdGxy%P*LUs3k2S0_((KIKnKN_dcYfdR`_6aHtl(Em z$K~E{9ke9!Bzs7711NaEf~5tZ41fZOvMRes6w>F__&)9>s}-b&zI!A~qD(TQ3Mc`R zAkj^-s0yeO%6RLNEg4^XPJs2uv*T9DGKqX0pad)dSRs*BO@2FO&3If4n$hRMAT?D+JoX5Q!P3gpjA_nIB599)D>fuSAbXBW7v?N<0ztQ6a~| z_#p)A@#pspkr;}ct2pIO7b%?bdgm08)1A&~#W{Wa&fnd2Yr5PMFHe>UbP3rJ1_3-V zr$?h!9IVHm-!lZ@4ggmGr~nuOFhl}Q6{^J4%p$6Oh}pR+X6CCnIx&OpyoaruFRIk< z^PN{GjS{^ivRvA=d&Wqgo+gc2ajqGvXXahZN|@X&*Kd9Z zz?A@|%S8`YT`9O=!y2p~s9@t@0sWPJc%FeVg6X3Zh{6bmM#m939eUaG!H9%B67y9WW~S&fZJ}|GX0sGF1gYZ`R2r=MLA0pi#^yld=YkCy9?Dt zAI4Z1V=*>9jmRnH7pfbM3zU(vtdOHxQLyUE%^x5B;@~>mJ9czt{^*ej^mol6pU>jz z>#l*#WMHfZV+^85;RjK9sry(XMPpi1zpD-`0JGaKe(71#`<;CUXR+u1CSh~}L&Jj@ zzH}Ryq*5lPW>KyB+dEd=AZrb}&u~43L`IbbRTj@uoRtIcTQB|S?Mv^=d&KC`1r(-y zND0`o;}RSkIe@9L!>HAKL>+pyBCuAZ!qe&X2+o30k;!uB2?!os)#u3q*-Z(gL*T=5j{ttzG?hm4cx!Do|Y`$y< z=I0j?Ic*23EOK&!PQp4xK5{Ha5&NBEnM5IB(Faqrdb@LvEiNop4vf!Z!})9OzV`Cr zw*lazAKCUyZ>9Wc4g9y(R|@E^^uZ6JkER4Y_kIPPgg8Y$ir5o5_NubPC5E~_aA5uI zgRk6Q%wXr6dq#2oz?$8k{McoWrqBP{&aH24-+a-htufE^l!}NV7gtnZJu5xSeU4LP zBggK@X}>B<1Tv>uce|26{na;Kx@BE&{vY3b=OA+V;!m&HG5q;Tx#-u0y6y#g%O!v7 z@P;S$ymx4}>W4RuPtHEGW#jq?fURFcCM%j-B_whzhRSYL-Sw5{?iZ1rP8I4DP8H7S>rQp1eyrNus`8<4{oQBwE%lIl zzWMTlJw?0ol{ZE(u(p5q&A)N^ZY~2U5r}7{OaM=O|J7ZiM<#bACyX^FBVsH`_(3?} z2jM`v?6%FDzIN&6&3n%{SOj*0xB;!yyx}<(Dl}@ z@7Q?vax0hhqy)f{!03^wT@%xDf3)1PRlinR5oW0>0KuPq?iz>)L}IroA}|7o0M0pl z?}vNw)C=z{dGjy)^Yc5`_T=v$pP0tXqMN;P+l7C+X~Wvt<(QvmC2Ncnli?}rc{T?C zkKXsWI9ilue#RvGLE!N0f4z$bo_uxX%+Mu)pa2Mh2w@n-fYpH$!NDUlSgeLiisF|Z z`Eg$mMh_Z9m3Q_}V0dWo?i)U`X<0fYB9if>tO|)DmLf&Yh%}s0Er{R;F4cH(I6r!1 z9@T2JvYMqSH4VZD^9!|R#f-p+V1Ch$8)b*WgXi^+{N8U~@fFX?vI1ZMiji{ADU0ls`IJU-G*z$Wh3*W3 z)!7VF%o3?r4G5isbA*ZKH6fng)XJ>c1^+4=u^)(!u z3J&`r-4ag4st~8P+u`X)#Iu%+33lnybPl zv`HdD{9;g_#sdJ@bD)|%IN?4!(381q z%Y|$Hq`ND(Kwu-37@G`tcj`eTX_2f5tTj?N(YyZJV?Ty-#8sE9$Hu`5W@i1ERq=S^ z%7fJqcu7Tv4Q&v-`R-UU<3yoJUt#Z|YKHN+9u80ImsR=YO$C158u@)c! zV>Z>F;#uhePCShD>i@>!+{GJuVT?4Kj4Ba1wn)edGAqTX6swE~R23xt`q6uDzXt%` z8?6}m1U&TB*sX_h-CFR_V?M}zUg6AeOL+H|KPWu zZM3BTPGez@oWi*kXI9*;OoNp6Kw9sGHa%1?fJ`S=j2vkKMY5pr1bk@=K)X-YiN*7& z>dexWXI3-Lk`}L6U#U$|-#=C>lgRRf`EB-)$aRR+ix8NT8buZX8JnI{o=we?W8$lr zWwDDUiIF3ILCLNYw7jQe1w1w#lnl8SPUih2i8oxrDm{B(rOYrDIzSM|SgH^s20;1v zK(R=&!*CS^RPn5oK-ktKRgw#C=w)-?Kus%Q$cb zLXm6kM`{NkVvwly z`>;8i8GuuXLMK7sOt2W4np4peYL+xSjx^0N(TSQL-oAHa{B|a9TL&oyF8K{?0ihnm zo~|V=?hVaK?qAAEU%`e0&AK$fNV5k`ut-89l^|5{jfho>o;aVCvioMgD+a8P%i^|A zY)?J3&eJ6TVM=7kCRN+|Ix)0ux!u&W+n4Rb14&9b2CCf~<}=ch6}Og>0;`d-t~YRl zp{hg_sZ^C9C^bJawb{VV*I9K!Gi>w=6QR##JX}23kIT2NPqh+TTDq|#sn<+}9!Phg zQmu?st0Q$jU8a6aG^b?OSC{k)H8I1Shd$4^u%%vY<{tAxA|Dg*beG*K~Bd`Ca8UtvORE{M5$VM(K*@sA6E{VG9rbJ~U z4b+~3F(MEMBBuzQB8(J4fT)|HPs<8LH@soR7DZm#J&lq47CXYd(ya7$mK?YBGV=)sN$sAmdof zSd*l346HS=DOrIvCduI^f*i%!f+&j9EFuQh#MfCPuwr0sycGz7$e|WE)WQgU5Wx@Q zV?T^qf>LYHYvLL35g}D2797o3sItEr+4pAr%)W`m?AT&td|jr8J}$GKdf{iN`C+qn z4>Vd+U94>`Wd?Qgt!s=VFC8BPCfScW>oF4|R~Ke&lx>!YL8@;_B8VLPP!WU?g2*8V zHQ73Zk;6i@*5XJBS#*?NhHCZ&&irC7%$R8P$o=IbuVtJP z4?p=6;FyuxW>nbz`$`OSE_YGFca%{_^NT?3yNi+c?v$V1Hxp#0BX@FD_1b_k0CJnw z_uP}udV_uC!WwHN=UK^TGhUZxP0!`aBJ!SR(Dsv(-o+&_9$9Ij#fVEI_U4Z114*w|uC4g8f1+0?Aw9XH3 z7C;H$DKo0hDv{OmwQM`HDu^dyoH9_!4475Jsur+nfhz#W#in=apLVP^RyDv1LNx-Z zoDN2>(E0X-`@S%v=w!9-5;0M0*MKmkC;N)fAYF#tB6&abL6MzSJe dRwG#dKL8bTMuhiDt9JkZ002ovPDHLkV1jb#zi$8l literal 0 HcmV?d00001 diff --git a/org.eclipse.linuxtools.tmf.ui/plugin.properties b/org.eclipse.linuxtools.tmf.ui/plugin.properties index ab241fca3b..8bafb2bd3f 100644 --- a/org.eclipse.linuxtools.tmf.ui/plugin.properties +++ b/org.eclipse.linuxtools.tmf.ui/plugin.properties @@ -38,6 +38,8 @@ project.new.wizard.custom.xml.parser = Custom XML Parser project.import.wizard.name = Trace Import project.import.wizard.name.batch = Batch Trace Import +project.import.wizard.name.tracepkg = Trace Package Import +project.export.wizard.name.tracepkg = Trace Package Export # Preference page preference.page.trace.name = Tracing @@ -125,6 +127,13 @@ command.new_experiment = New... command.new_experiment.mnemonic = N command.new_experiment.description = Create Tracing Experiment +command.export_trace_package = Export Trace Package... +command.export_trace_package.mnemonic = E +command.export_trace_package.description = Export a Trace Package +command.import_trace_package = Import Trace Package... +command.import_trace_package.mnemonic = P +command.import_trace_package.description = Import a Trace Package + # Custom parsers commands.parser.category.name = Parser Commands commands.parser.category.description = Parser Commands diff --git a/org.eclipse.linuxtools.tmf.ui/plugin.xml b/org.eclipse.linuxtools.tmf.ui/plugin.xml index 229929ce81..9876d7291e 100644 --- a/org.eclipse.linuxtools.tmf.ui/plugin.xml +++ b/org.eclipse.linuxtools.tmf.ui/plugin.xml @@ -164,6 +164,13 @@ id="org.eclipse.linuxtools.tmf.ui.batch_import" name="%project.import.wizard.name.batch"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -753,6 +811,16 @@ id="org.eclipse.linuxtools.tmf.ui.command.delete_suppl_files" name="%command.delete_suppl_files"> + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -1279,5 +1381,18 @@ - + + + + + + diff --git a/org.eclipse.linuxtools.tmf.ui/schema/export-manifest.xsd b/org.eclipse.linuxtools.tmf.ui/schema/export-manifest.xsd new file mode 100644 index 0000000000..4f19998ae7 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/schema/export-manifest.xsd @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceHandler.java index 5173ce4da6..6a95391dc7 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceHandler.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/handlers/DeleteTraceHandler.java @@ -15,25 +15,16 @@ package org.eclipse.linuxtools.internal.tmf.ui.project.handlers; import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; -import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.viewers.ISelection; import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.TreeSelection; import org.eclipse.linuxtools.internal.tmf.ui.Activator; -import org.eclipse.linuxtools.tmf.ui.project.model.ITmfProjectModelElement; -import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentElement; -import org.eclipse.linuxtools.tmf.ui.project.model.TmfExperimentFolder; import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; -import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder; import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.MessageBox; @@ -120,34 +111,8 @@ public class DeleteTraceHandler extends AbstractHandler { Object element = iterator.next(); if (element instanceof TmfTraceElement) { final TmfTraceElement trace = (TmfTraceElement) element; - IResource resource = trace.getResource(); try { - // Close the trace if open - trace.closeEditors(); - - IPath path = resource.getLocation(); - if (path != null && (trace.getParent() instanceof TmfTraceFolder)) { - TmfExperimentFolder experimentFolder = trace.getProject().getExperimentsFolder(); - - // Propagate the removal to traces - for (ITmfProjectModelElement experiment : experimentFolder.getChildren()) { - List toRemove = new LinkedList(); - for (ITmfProjectModelElement child : experiment.getChildren()) { - if (child.getName().equals(trace.getName())) { - toRemove.add(child); - } - } - for (ITmfProjectModelElement child : toRemove) { - ((TmfExperimentElement) experiment).removeTrace((TmfTraceElement) child); - } - } - - // Delete supplementary files - trace.deleteSupplementaryFolder(); - } - - // Finally, delete the trace - resource.delete(true, new NullProgressMonitor()); + trace.delete(null); // Refresh the project trace.getProject().refresh(); diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/AbstractTracePackageOperation.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/AbstractTracePackageOperation.java new file mode 100644 index 0000000000..03376610de --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/AbstractTracePackageOperation.java @@ -0,0 +1,332 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Enumeration; +import java.util.Vector; +import java.util.zip.ZipEntry; +import java.util.zip.ZipException; +import java.util.zip.ZipFile; + +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.ui.internal.wizards.datatransfer.TarEntry; +import org.eclipse.ui.internal.wizards.datatransfer.TarException; +import org.eclipse.ui.internal.wizards.datatransfer.TarFile; + +/** + * An abstract operation containing common code useful for other trace package + * operations + * + * @author Marc-Andre Laperle + */ +@SuppressWarnings("restriction") +abstract public class AbstractTracePackageOperation { + private IStatus fStatus; + private final String fFileName; + + /** + * Constructs a new trace package operation + * + * @param fileName + * the output file name + */ + public AbstractTracePackageOperation(String fileName) { + fFileName = fileName; + } + + /** + * Run the operation. The status (result) of the operation can be obtained + * with {@link #getStatus} + * + * @param progressMonitor + * the progress monitor to use to display progress and receive + * requests for cancellation + */ + public abstract void run(IProgressMonitor progressMonitor); + + /** + * Returns the status of the operation (result) + * + * @return the status of the operation + */ + public IStatus getStatus() { + return fStatus; + } + + /** + * Set the status for this operation + * + * @param status + * the status + */ + protected void setStatus(IStatus status) { + fStatus = status; + } + + /** + * Get the file name of the package + * + * @return the file name + */ + protected String getFileName() { + return fFileName; + } + + /** + * Answer a handle to the archive file currently specified as being the + * source. Return null if this file does not exist or is not of valid + * format. + * + * @return the archive file + */ + public ArchiveFile getSpecifiedArchiveFile() { + if (fFileName.length() == 0) { + return null; + } + + try { + ZipFile zipFile = new ZipFile(fFileName); + return new ZipArchiveFile(zipFile); + } catch (ZipException e) { + // ignore + } catch (IOException e) { + // ignore + } + + try { + TarFile tarFile = new TarFile(fFileName); + return new TarArchiveFile(tarFile); + } catch (TarException e) { + // ignore + } catch (IOException e) { + // ignore + } + + return null; + } + + /** + * Get the number of checked elements in the array and the children + * + * @param elements + * the elements to check for checked + * @return the number of checked elements + */ + protected int getNbCheckedElements(TracePackageElement[] elements) { + int totalWork = 0; + for (TracePackageElement tracePackageElement : elements) { + if (tracePackageElement.getChildren() != null) { + totalWork += getNbCheckedElements(tracePackageElement.getChildren()); + } else if (tracePackageElement.isChecked()) { + ++totalWork; + } + } + + return totalWork; + } + + /** + * Common interface between ZipEntry and TarEntry + */ + protected interface ArchiveEntry { + /** + * The name of the entry + * + * @return The name of the entry + */ + String getName(); + } + + /** + * Common interface between ZipFile and TarFile + */ + protected interface ArchiveFile { + /** + * Returns an enumeration cataloging the archive. + * + * @return enumeration of all files in the archive + */ + Enumeration entries(); + + /** + * Close the file input stream. + * + * @throws IOException + */ + void close() throws IOException; + + /** + * Returns a new InputStream for the given file in the archive. + * + * @param entry + * the given file + * @return an input stream for the given file + * @throws TarException + * @throws IOException + */ + InputStream getInputStream(ArchiveEntry entry) throws TarException, IOException; + } + + /** + * Adapter for TarFile to ArchiveFile + */ + protected class TarArchiveFile implements ArchiveFile { + + private TarFile fTarFile; + + /** + * Constructs a TarAchiveFile for a TarFile + * + * @param tarFile + * the TarFile + */ + public TarArchiveFile(TarFile tarFile) { + this.fTarFile = tarFile; + } + + @Override + public Enumeration entries() { + Vector v = new Vector(); + for (Enumeration e = fTarFile.entries(); e.hasMoreElements();) { + v.add(new TarArchiveEntry((TarEntry) e.nextElement())); + } + + return v.elements(); + } + + @Override + public void close() throws IOException { + fTarFile.close(); + } + + @Override + public InputStream getInputStream(ArchiveEntry entry) throws TarException, IOException { + return fTarFile.getInputStream(((TarArchiveEntry) entry).getTarEntry()); + } + } + + /** + * Adapter for TarEntry to ArchiveEntry + */ + protected class TarArchiveEntry implements ArchiveEntry { + private TarEntry fTarEntry; + + /** + * Constructs a TarArchiveEntry for a TarEntry + * + * @param tarEntry + * the TarEntry + */ + public TarArchiveEntry(TarEntry tarEntry) { + this.fTarEntry = tarEntry; + } + + @Override + public String getName() { + return fTarEntry.getName(); + } + + /** + * Get the corresponding TarEntry + * + * @return the corresponding TarEntry + */ + public TarEntry getTarEntry() { + return fTarEntry; + } + + @Override + public String toString() { + return getName(); + } + } + + /** + * Adapter for ArchiveEntry to ArchiveEntry + */ + protected class ZipAchiveEntry implements ArchiveEntry { + + private ZipEntry fZipEntry; + + /** + * Constructs a ZipAchiveEntry for a ZipEntry + * + * @param zipEntry + * the ZipEntry + */ + public ZipAchiveEntry(ZipEntry zipEntry) { + this.fZipEntry = zipEntry; + } + + @Override + public String getName() { + return fZipEntry.getName(); + } + + /** + * Get the corresponding ZipEntry + * + * @return the corresponding ZipEntry + */ + public ZipEntry getZipEntry() { + return fZipEntry; + } + + @Override + public String toString() { + return getName(); + } + } + + /** + * Adapter for ZipFile to ArchiveFile + */ + protected class ZipArchiveFile implements ArchiveFile { + + private ZipFile fZipFile; + + /** + * Constructs a ZipArchiveFile for a ZipFile + * + * @param zipFile + * the ZipFile + */ + public ZipArchiveFile(ZipFile zipFile) { + this.fZipFile = zipFile; + } + + @Override + public Enumeration entries() { + Vector v = new Vector(); + for (Enumeration e = fZipFile.entries(); e.hasMoreElements();) { + v.add(new ZipAchiveEntry((ZipEntry) e.nextElement())); + } + + return v.elements(); + } + + @Override + public void close() throws IOException { + fZipFile.close(); + } + + @Override + public InputStream getInputStream(ArchiveEntry entry) throws TarException, IOException { + return fZipFile.getInputStream(((ZipAchiveEntry) entry).getZipEntry()); + } + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/AbstractTracePackageWizardPage.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/AbstractTracePackageWizardPage.java new file mode 100644 index 0000000000..655a06b6ad --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/AbstractTracePackageWizardPage.java @@ -0,0 +1,542 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.dialogs.ErrorDialog; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.CheckboxTreeViewer; +import org.eclipse.jface.viewers.ICheckStateListener; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.linuxtools.internal.tmf.ui.Activator; +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.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.TreeItem; + +/** + * An abstract wizard page containing common code useful for both import and + * export trace package wizard pages + * + * @author Marc-Andre Laperle + */ +abstract public class AbstractTracePackageWizardPage extends WizardPage { + + private static final int COMBO_HISTORY_LENGTH = 5; + private static final String STORE_FILE_PATHS_ID = ".STORE_FILEPATHS_ID"; //$NON-NLS-1$ + + private final String fStoreFilePathId; + private final IStructuredSelection fSelection; + + private CheckboxTreeViewer fElementViewer; + private Button fSelectAllButton; + private Button fDeselectAllButton; + private Combo fFilePathCombo; + private Button fBrowseButton; + + /** + * Create the trace package wizard page + * + * @param pageName + * the name of the page + * @param title + * the title for this wizard page, or null if none + * @param titleImage + * the image descriptor for the title of this wizard page, or + * null if none + * @param selection + * the current object selection + */ + protected AbstractTracePackageWizardPage(String pageName, String title, ImageDescriptor titleImage, IStructuredSelection selection) { + super(pageName, title, titleImage); + fStoreFilePathId = getName() + STORE_FILE_PATHS_ID; + fSelection = selection; + } + + /** + * Create the element viewer + * + * @param parent + * the parent composite + */ + protected void createElementViewer(Composite parent) { + fElementViewer = new CheckboxTreeViewer(parent, SWT.SINGLE | SWT.H_SCROLL | SWT.V_SCROLL | SWT.BORDER | SWT.CHECK); + + fElementViewer.addCheckStateListener(new ICheckStateListener() { + @Override + public void checkStateChanged(CheckStateChangedEvent event) { + TracePackageElement element = (TracePackageElement) event.getElement(); + if (!element.isEnabled()) { + fElementViewer.setChecked(element, element.isChecked()); + } else { + setSubtreeChecked(fElementViewer, element, true, event.getChecked()); + } + maintainCheckIntegrity(element); + updateApproximateSelectedSize(); + updatePageCompletion(); + } + + private void maintainCheckIntegrity(final TracePackageElement element) { + TracePackageElement parentElement = element.getParent(); + boolean allChecked = true; + boolean oneChecked = false; + if (parentElement != null) { + if (parentElement.getChildren() != null) { + for (TracePackageElement child : parentElement.getChildren()) { + boolean checked = fElementViewer.getChecked(child) && !fElementViewer.getGrayed(child); + oneChecked |= checked; + allChecked &= checked; + } + } + if (oneChecked && !allChecked) { + fElementViewer.setGrayChecked(parentElement, true); + } else { + fElementViewer.setGrayed(parentElement, false); + fElementViewer.setChecked(parentElement, allChecked); + } + maintainCheckIntegrity(parentElement); + } + } + }); + GridData layoutData = new GridData(GridData.FILL_BOTH); + fElementViewer.getTree().setLayoutData(layoutData); + fElementViewer.setContentProvider(new TracePackageContentProvider()); + fElementViewer.setLabelProvider(new TracePackageLabelProvider()); + } + + /** + * Create the input for the element viewer + * + * @return the input for the element viewer + */ + protected abstract Object createElementViewerInput(); + + /** + * Create the file path group that allows the user to type or browse for a + * file path + * + * @param parent + * the parent composite + * @param label + * the label to describe the file path (i.e. import/export) + * @param fileDialogStyle + * SWT.OPEN or SWT.SAVE + */ + protected void createFilePathGroup(Composite parent, String label, final int fileDialogStyle) { + + Composite filePathSelectionGroup = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 3; + filePathSelectionGroup.setLayout(layout); + filePathSelectionGroup.setLayoutData(new GridData( + GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); + + Label destinationLabel = new Label(filePathSelectionGroup, SWT.NONE); + destinationLabel.setText(label); + + fFilePathCombo = new Combo(filePathSelectionGroup, SWT.SINGLE + | SWT.BORDER); + GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL + | GridData.GRAB_HORIZONTAL); + data.grabExcessHorizontalSpace = true; + fFilePathCombo.setLayoutData(data); + + fBrowseButton = new Button(filePathSelectionGroup, + SWT.PUSH); + fBrowseButton.setText(org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_Browse); + fBrowseButton.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event event) { + handleFilePathBrowseButtonPressed(fileDialogStyle); + } + }); + setButtonLayoutData(fBrowseButton); + } + + /** + * Update the page with the file path the current file path selection + */ + abstract protected void updateWithFilePathSelection(); + + /** + * Creates the buttons for selecting all or none of the elements. + * + * @param parent + * the parent control + * @return the button group + */ + protected Composite createButtonsGroup(Composite parent) { + + // top level group + Composite buttonComposite = new Composite(parent, SWT.NONE); + + GridLayout layout = new GridLayout(); + layout.numColumns = 3; + buttonComposite.setLayout(layout); + buttonComposite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL + | GridData.HORIZONTAL_ALIGN_FILL)); + + fSelectAllButton = new Button(buttonComposite, SWT.PUSH); + fSelectAllButton.setText(org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_SelectAll); + + SelectionListener listener = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + setAllChecked(fElementViewer, true, true); + updateApproximateSelectedSize(); + updatePageCompletion(); + } + }; + fSelectAllButton.addSelectionListener(listener); + + fDeselectAllButton = new Button(buttonComposite, SWT.PUSH); + fDeselectAllButton.setText(org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_DeselectAll); + + listener = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + setAllChecked(fElementViewer, true, false); + updateApproximateSelectedSize(); + updatePageCompletion(); + } + }; + fDeselectAllButton.addSelectionListener(listener); + + return buttonComposite; + } + + /** + * Restore widget values to the values that they held last time this wizard + * was used to completion. + */ + protected void restoreWidgetValues() { + IDialogSettings settings = getDialogSettings(); + if (settings != null) { + String[] directoryNames = settings.getArray(fStoreFilePathId); + if (directoryNames == null || directoryNames.length == 0) { + return; + } + + for (int i = 0; i < directoryNames.length; i++) { + fFilePathCombo.add(directoryNames[i]); + } + } + } + + /** + * Save widget values to Dialog settings + */ + protected void saveWidgetValues() { + IDialogSettings settings = getDialogSettings(); + if (settings != null) { + // update directory names history + String[] directoryNames = settings.getArray(fStoreFilePathId); + if (directoryNames == null) { + directoryNames = new String[0]; + } + + directoryNames = addToHistory(directoryNames, getFilePathValue()); + settings.put(fStoreFilePathId, directoryNames); + } + } + + /** + * Determine if the page is complete and update the page appropriately. + */ + protected void updatePageCompletion() { + boolean pageComplete = determinePageCompletion(); + setPageComplete(pageComplete); + if (pageComplete) { + setErrorMessage(null); + } + } + + /** + * Determine if the page is completed or not + * + * @return true if the page is completed, false otherwise + */ + protected boolean determinePageCompletion() { + return fElementViewer.getCheckedElements().length > 0 && !getFilePathValue().isEmpty(); + } + + /** + * Handle error status + * + * @param status + * the error status + */ + protected void handleErrorStatus(IStatus status) { + + Throwable exception = status.getException(); + String message = status.getMessage().length() > 0 ? status.getMessage() : org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorOperation; + + if (!status.isMultiStatus()) { + handleError(message, exception); + return; + } + + // Build a string with all the children status messages, exception + // messages and stack traces + StringBuilder sb = new StringBuilder(); + for (IStatus childStatus : status.getChildren()) { + StringBuilder childSb = new StringBuilder(); + if (!childStatus.getMessage().isEmpty()) { + childSb.append(childStatus.getMessage() + '\n'); + } + + Throwable childException = childStatus.getException(); + if (childException != null) { + String reason = childException.getMessage(); + // Some system exceptions have no message + if (reason == null) { + reason = childException.toString(); + } + + String stackMessage = getExceptionStackMessage(childException); + if (stackMessage == null) { + stackMessage = reason; + } + + childSb.append(stackMessage); + } + + if (childSb.length() > 0) { + childSb.insert(0, '\n'); + sb.append(childSb.toString()); + } + } + + // ErrorDialog only prints the call stack for a CoreException + exception = new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, sb.toString(), null)); + final Status statusWithException = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorMultipleProblems, exception); + + Activator.getDefault().logError(message, exception); + ErrorDialog.openError(getContainer().getShell(), org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_InternalErrorTitle, message, statusWithException); + } + + /** + * Handle errors occurring in the wizard operations + * + * @param message + * the error message + * @param exception + * the exception attached to the message + */ + protected void handleError(String message, Throwable exception) { + Activator.getDefault().logError(message, exception); + displayErrorDialog(message, exception); + } + + private static String getExceptionStackMessage(Throwable exception) { + String stackMessage = null; + ByteArrayOutputStream baos = new ByteArrayOutputStream(); + PrintStream ps = new PrintStream(baos); + exception.printStackTrace(ps); + ps.flush(); + try { + baos.flush(); + stackMessage = baos.toString(); + } catch (IOException e) { + } + + return stackMessage; + } + + private void displayErrorDialog(String message, Throwable exception) { + if (exception == null) { + final Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID, message); + ErrorDialog.openError(getContainer().getShell(), org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_InternalErrorTitle, null, s); + return; + } + + String reason = exception.getMessage(); + // Some system exceptions have no message + if (reason == null) { + reason = exception.toString(); + } + + String stackMessage = getExceptionStackMessage(exception); + if (stackMessage == null || stackMessage.isEmpty()) { + stackMessage = reason; + } + + // ErrorDialog only prints the call stack for a CoreException + CoreException coreException = new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, stackMessage, exception)); + final Status s = new Status(IStatus.ERROR, Activator.PLUGIN_ID, IStatus.ERROR, reason, coreException); + ErrorDialog.openError(getContainer().getShell(), org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_InternalErrorTitle, message, s); + } + + /** + * A version of setSubtreeChecked that is aware of isEnabled + * + * @param viewer + * the viewer + * @param element + * the element + * @param enabledOnly + * if only enabled elements should be considered + * @param checked + * true if the item should be checked, and false if it should be + * unchecked + */ + protected static void setSubtreeChecked(CheckboxTreeViewer viewer, TracePackageElement element, boolean enabledOnly, boolean checked) { + if (!enabledOnly || element.isEnabled()) { + viewer.setChecked(element, checked); + if (checked) { + viewer.setGrayed(element, false); + } + element.setChecked(checked); + if (element.getChildren() != null) { + for (TracePackageElement child : element.getChildren()) { + setSubtreeChecked(viewer, child, enabledOnly, checked); + } + } + } + } + + /** + * Sets all items in the element viewer to be checked or unchecked + * + * @param viewer + * the viewer + * @param enabledOnly + * if only enabled elements should be considered + * @param checked + * whether or not items should be checked + */ + protected static void setAllChecked(CheckboxTreeViewer viewer, boolean enabledOnly, boolean checked) { + TreeItem[] items = viewer.getTree().getItems(); + for (int i = 0; i < items.length; i++) { + Object element = items[i].getData(); + setSubtreeChecked(viewer, (TracePackageElement) element, enabledOnly, checked); + } + } + + private static void addToHistory(List history, String newEntry) { + history.remove(newEntry); + history.add(0, newEntry); + + // since only one new item was added, we can be over the limit + // by at most one item + if (history.size() > COMBO_HISTORY_LENGTH) { + history.remove(COMBO_HISTORY_LENGTH); + } + } + + private static String[] addToHistory(String[] history, String newEntry) { + ArrayList l = new ArrayList(Arrays.asList(history)); + addToHistory(l, newEntry); + String[] r = new String[l.size()]; + l.toArray(r); + return r; + } + + /** + * Open an appropriate file dialog so that the user can specify a file to + * import/export + * @param fileDialogStyle + */ + private void handleFilePathBrowseButtonPressed(int fileDialogStyle) { + FileDialog dialog = new FileDialog(getContainer().getShell(), fileDialogStyle | SWT.SHEET); + dialog.setFilterExtensions(new String[] { "*.zip;*.tar.gz;*.tar;*.tgz", "*.*" }); //$NON-NLS-1$ //$NON-NLS-2$ + dialog.setText(Messages.TracePackage_FileDialogTitle); + String currentSourceString = getFilePathValue(); + int lastSeparatorIndex = currentSourceString.lastIndexOf(File.separator); + if (lastSeparatorIndex != -1) { + dialog.setFilterPath(currentSourceString.substring(0, lastSeparatorIndex)); + } + String selectedFileName = dialog.open(); + + if (selectedFileName != null) { + setFilePathValue(selectedFileName); + updateWithFilePathSelection(); + } + } + + /** + * Get the current file path value + * + * @return the current file path value + */ + protected String getFilePathValue() { + return fFilePathCombo.getText().trim(); + } + + /** + * Set the file path value + * + * @param value + * file path value + */ + protected void setFilePathValue(String value) { + fFilePathCombo.setText(value); + updatePageCompletion(); + } + + /** + * Update the approximate size of the selected elements + */ + protected void updateApproximateSelectedSize() { + } + + /** + * Get the element tree viewer + * + * @return the element tree viewer + */ + protected CheckboxTreeViewer getElementViewer() { + return fElementViewer; + } + + /** + * Get the file path combo box + * + * @return the file path combo box + */ + protected Combo getFilePathCombo() { + return fFilePathCombo; + } + + /** + * Get the object selection when the wizard was created + * + * @return the object selection + */ + protected IStructuredSelection getSelection() { + return fSelection; + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/ITracePackageConstants.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/ITracePackageConstants.java new file mode 100644 index 0000000000..640a6c6ec2 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/ITracePackageConstants.java @@ -0,0 +1,76 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg; + +/** + * Constants used in the trace package (XML attribute and element names, etc). + * + * @author Marc-Andre Laperle + */ +public interface ITracePackageConstants { + + /** + * The file name for the package manifest file + */ + public static final String MANIFEST_FILENAME = "export-manifest.xml"; //$NON-NLS-1$ + + /** + * The root element of an export + */ + public static final String TMF_EXPORT_ELEMENT = "tmf-export"; //$NON-NLS-1$ + + /** + * Element representing a single trace + */ + public static final String TRACE_ELEMENT = "trace"; //$NON-NLS-1$ + + /** + * Attribute for the name of a trace + */ + public static final String TRACE_NAME_ATTRIB = "name"; //$NON-NLS-1$ + + /** + * Attribute for the type of a trace + */ + public static final String TRACE_TYPE_ATTRIB = "type"; //$NON-NLS-1$ + + /** + * Element representing a single supplementary file + */ + public static final String SUPPLEMENTARY_FILE_ELEMENT = "supplementary-file"; //$NON-NLS-1$ + + /** + * Attribute for the name of a supplementary file + */ + public static final String SUPPLEMENTARY_FILE_NAME_ATTRIB = "name"; //$NON-NLS-1$ + + /** + * Element representing a trace file or folder + */ + public static final String TRACE_FILE_ELEMENT = "file"; //$NON-NLS-1$ + + /** + * Attribute for the name of the file + */ + public static final String TRACE_FILE_NAME_ATTRIB = "name"; //$NON-NLS-1$ + + /** + * Element representing the bookmarks of a trace + */ + public static final String BOOKMARKS_ELEMENT = "bookmarks"; //$NON-NLS-1$ + + /** + * Element representing a single bookmark of a trace + */ + public static final String BOOKMARK_ELEMENT = "bookmark"; //$NON-NLS-1$ +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/Messages.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/Messages.java new file mode 100644 index 0000000000..452b32cd28 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/Messages.java @@ -0,0 +1,84 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg; + +import org.eclipse.osgi.util.NLS; + +/** + * Messages common to trace package operations + * + * @author Marc-Andre Laperle + */ +public class Messages extends NLS { + + private static final String BUNDLE_NAME = "org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.messages"; //$NON-NLS-1$ + + /** + * Text for supplementary files in the element viewer + */ + public static String TracePackage_SupplementaryFiles; + + /** + * Text for trace in the element viewer + */ + public static String TracePackage_TraceElement; + + /** + * Text for bookmarks in the element viewer + */ + public static String TracePackage_Bookmarks; + + /** + * Text for browse button in the wizard pages + */ + public static String TracePackage_Browse; + + /** + * Title for the file dialog + */ + public static String TracePackage_FileDialogTitle; + + /** + * Text for browse select all button in the wizard pages + */ + public static String TracePackage_SelectAll; + + /** + * Text for browse deselect all button in the wizard pages + */ + public static String TracePackage_DeselectAll; + + /** + * Generic error message for wizard operations + */ + public static String TracePackage_ErrorOperation; + + /** + * Generic error when multiple problems occur (MultiStatus) + */ + public static String TracePackage_ErrorMultipleProblems; + + /** + * Generic dialog message for error in wizard operations + */ + public static String TracePackage_InternalErrorTitle; + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageBookmarkElement.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageBookmarkElement.java new file mode 100644 index 0000000000..65c374524d --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageBookmarkElement.java @@ -0,0 +1,66 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg; + +import java.util.List; +import java.util.Map; + +import org.eclipse.linuxtools.internal.tmf.ui.Activator; +import org.eclipse.swt.graphics.Image; + +/** + * A trace package element representing the bookmarks of a trace + * + * @author Marc-Andre Laperle + */ +public class TracePackageBookmarkElement extends TracePackageElement { + private static final String BOOKMARK_IMAGE_PATH = "icons/elcl16/bookmark_obj.gif"; //$NON-NLS-1$ + private final List> bookmarkAttribs; + + /** + * Construct a bookmark element containing all the bookmarks + * + * @param parent + * the parent node + * @param bookmarkAttribs + * the bookmarks for the trace + */ + public TracePackageBookmarkElement(TracePackageElement parent, List> bookmarkAttribs) { + super(parent); + this.bookmarkAttribs = bookmarkAttribs; + } + + @Override + public long getSize(boolean checkedOnly) { + return 0; + } + + @Override + public String getText() { + return Messages.TracePackage_Bookmarks; + } + + @Override + public Image getImage() { + return Activator.getDefault().getImageFromImageRegistry(BOOKMARK_IMAGE_PATH); + } + + /** + * Get all the bookmarks + * + * @return the bookmarks + */ + public List> getBookmarks() { + return bookmarkAttribs; + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageContentProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageContentProvider.java new file mode 100644 index 0000000000..0012745358 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageContentProvider.java @@ -0,0 +1,57 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg; + +import org.eclipse.jface.viewers.ITreeContentProvider; +import org.eclipse.jface.viewers.Viewer; + +/** + * A content provider to display the content of a trace package in a tree + * + * @author Marc-Andre Laperle + */ +public class TracePackageContentProvider implements ITreeContentProvider { + + @Override + public void dispose() { + } + + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + @Override + public Object[] getElements(Object inputElement) { + if (inputElement instanceof TracePackageElement[]) { + return (TracePackageElement[]) inputElement; + } + return null; + } + + @Override + public Object[] getChildren(Object parentElement) { + return ((TracePackageElement) parentElement).getChildren(); + } + + @Override + public Object getParent(Object element) { + return ((TracePackageElement) element).getParent(); + } + + @Override + public boolean hasChildren(Object element) { + TracePackageElement traceTransferElement = (TracePackageElement) element; + return traceTransferElement.getChildren() != null && traceTransferElement.getChildren().length > 0; + } + +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageElement.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageElement.java new file mode 100644 index 0000000000..da0386a933 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageElement.java @@ -0,0 +1,139 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg; + +import org.eclipse.swt.graphics.Image; +import org.eclipse.ui.model.WorkbenchAdapter; + +/** + * An ExportTraceElement represents an item in the ExportTraceWizard tree. + * + * @author Marc-Andre Laperle + */ +public abstract class TracePackageElement extends WorkbenchAdapter { + private TracePackageElement[] fChildren; + private final TracePackageElement fParent; + private boolean fEnabled; + private boolean fChecked; + + /** + * + * @param parent + * the parent of this element, can be set to null + */ + public TracePackageElement(TracePackageElement parent) { + fParent = parent; + fEnabled = true; + } + + /** + * @return the parent of this element or null if there is no parent + */ + public TracePackageElement getParent() { + return fParent; + } + + /** + * Get the text representation of this element to be displayed in the tree. + * + * @return the text representation + */ + abstract public String getText(); + + /** + * Get the children of this element + * + * @return the children of this element + */ + public TracePackageElement[] getChildren() { + return fChildren; + } + + /** + * Set the children of this element + * + * @param children + * the children of this element + */ + public void setChildren(TracePackageElement[] children) { + this.fChildren = children; + } + + /** + * Get the total size of the element including its children + * + * @param checkedOnly + * only count checked elements + * + * @return the total size of the element + */ + public long getSize(boolean checkedOnly) { + long size = 0; + if (fChildren != null) { + for (TracePackageElement child : fChildren) { + size += child.getSize(checkedOnly); + } + } + + return size; + } + + /** + * Get the image representation of this element to be displayed in the tree. + * + * @return the image representation + */ + public Image getImage() { + return null; + } + + /** + * Returns whether or not the element is enabled (grayed and not + * modifiable). + * + * @return whether or not the element is enabled + */ + public boolean isEnabled() { + return fEnabled; + } + + /** + * Returns whether or not the element is checked. + * + * @return whether or not the element is checked + */ + public boolean isChecked() { + return fChecked; + } + + /** + * Sets whether or not the element should be enabled (grayed and not + * modifiable). + * + * @param enabled + * if the element should be enabled + */ + public void setEnabled(boolean enabled) { + fEnabled = enabled; + } + + /** + * Sets whether or not the element should be checked. + * + * @param checked + * if the element should be checked + */ + public void setChecked(boolean checked) { + fChecked = checked; + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageFilesElement.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageFilesElement.java new file mode 100644 index 0000000000..881a9cfa6a --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageFilesElement.java @@ -0,0 +1,107 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg; + +import java.io.File; + +import org.eclipse.core.resources.IResource; +import org.eclipse.linuxtools.internal.tmf.ui.Activator; +import org.eclipse.swt.graphics.Image; + +/** + * An ExportTraceElement representing the trace files of a trace. + * + * @author Marc-Andre Laperle + */ +public class TracePackageFilesElement extends TracePackageElement { + + private static final String TRACE_ICON_PATH = "icons/elcl16/trace.gif"; //$NON-NLS-1$ + private final String fFileName; + private final IResource fResource; + private long fSize = -1; + + /** + * Constructs an instance of ExportTraceFilesElement when exporting + * + * @param parent + * the parent of this element, can be set to null + * @param resource + * the resource representing the trace file or folder in the + * workspace + */ + public TracePackageFilesElement(TracePackageElement parent, IResource resource) { + super(parent); + fFileName = null; + fResource = resource; + } + + /** + * Constructs an instance of ExportTraceFilesElement when importing + * + * @param parent + * the parent of this element, can be set to null + * @param fileName + * the name of the file to be imported + */ + public TracePackageFilesElement(TracePackageElement parent, String fileName) { + super(parent); + fFileName = fileName; + fResource = null; + } + + private long getSize(File file) { + if (file.isDirectory()) { + long size = 0; + for (File f : file.listFiles()) { + size += getSize(f); + } + return size; + } + + return file.length(); + } + + @Override + public long getSize(boolean checkedOnly) { + if (checkedOnly && !isChecked()) { + return 0; + } + + if (fSize == -1 && fResource.exists()) { + File file = fResource.getLocation().toFile(); + fSize = getSize(file); + } + + return fSize; + } + + @Override + public String getText() { + return Messages.TracePackage_TraceElement; + } + + @Override + public Image getImage() { + return Activator.getDefault().getImageFromImageRegistry(TRACE_ICON_PATH); + } + + /** + * Get the file name for this trace file or folder + * + * @return the file name for this trace file or folder + */ + public String getFileName() { + return fFileName; + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageLabelProvider.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageLabelProvider.java new file mode 100644 index 0000000000..e9b0f9886c --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageLabelProvider.java @@ -0,0 +1,69 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg; + +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.ILabelProviderListener; +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Color; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; + +/** + * A label provider for the export trace tree. + * + * @author Marc-Andre Laperle + */ +public class TracePackageLabelProvider extends ColumnLabelProvider { + + @Override + public void addListener(ILabelProviderListener listener) { + } + + @Override + public void dispose() { + } + + @Override + public boolean isLabelProperty(Object element, String property) { + return false; + } + + @Override + public void removeListener(ILabelProviderListener listener) { + } + + @Override + public Image getImage(Object element) { + return ((TracePackageElement) element).getImage(); + } + + @Override + public String getText(Object element) { + return ((TracePackageElement) element).getText(); + } + + @Override + public Color getForeground(Object element) { + if (!((TracePackageElement) element).isEnabled()) { + return Display.getDefault().getSystemColor(SWT.COLOR_GRAY); + } + return null; + } + + @Override + public Color getBackground(Object element) { + return null; + } + +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageSupplFileElement.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageSupplFileElement.java new file mode 100644 index 0000000000..a9091f7fc3 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageSupplFileElement.java @@ -0,0 +1,89 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg; + +import org.eclipse.core.resources.IResource; +import org.eclipse.linuxtools.internal.tmf.ui.Activator; +import org.eclipse.swt.graphics.Image; + +/** + * A trace package element representing a single supplementary file + * + * @author Marc-Andre Laperle + */ +public class TracePackageSupplFileElement extends TracePackageElement { + + private static final String SUPPL_FILE_ICON_PATH = "icons/obj16/thread_obj.gif"; //$NON-NLS-1$ + + private final IResource fResource; + private final String fSuppFileName; + + /** + * Constructor used when exporting + * + * @param resource + * the resource representing this supplementary file in the + * workspace + * @param parent + * the parent element + */ + public TracePackageSupplFileElement(IResource resource, TracePackageElement parent) { + super(parent); + fResource = resource; + fSuppFileName = null; + } + + /** + * Constructor used when importing + * + * @param suppFileName + * the name to be used for the supplementary file in the + * workspace + * @param parent + * the parent element + */ + public TracePackageSupplFileElement(String suppFileName, TracePackageElement parent) { + super(parent); + this.fSuppFileName = suppFileName; + fResource = null; + } + + /** + * Get the resource corresponding to this supplementary file + * + * @return the resource corresponding to this supplementary file + */ + public IResource getResource() { + return fResource; + } + + @Override + public String getText() { + return fResource != null ? fResource.getName() : fSuppFileName; + } + + @Override + public long getSize(boolean checkedOnly) { + if (checkedOnly && !isChecked()) { + return 0; + } + + return fResource.getLocation().toFile().length(); + } + + @Override + public Image getImage() { + return Activator.getDefault().getImageFromImageRegistry(SUPPL_FILE_ICON_PATH); + } + +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageSupplFilesElement.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageSupplFilesElement.java new file mode 100644 index 0000000000..70cb7c74da --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageSupplFilesElement.java @@ -0,0 +1,47 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg; + +import org.eclipse.linuxtools.internal.tmf.ui.Activator; +import org.eclipse.swt.graphics.Image; + +/** + * A trace package element used for grouping supplementary file under a single + * subtree + * + * @author Marc-Andre Laperle + */ +public class TracePackageSupplFilesElement extends TracePackageElement { + + private static final String SUPPL_FILE_ICON_PATH = "icons/obj16/thread_obj.gif"; //$NON-NLS-1$ + + /** + * Construct a new TracePackageSupplFilesElement instance + * + * @param parent + * the parent of this element, can be set to null + */ + public TracePackageSupplFilesElement(TracePackageElement parent) { + super(parent); + } + + @Override + public String getText() { + return Messages.TracePackage_SupplementaryFiles; + } + + @Override + public Image getImage() { + return Activator.getDefault().getImageFromImageRegistry(SUPPL_FILE_ICON_PATH); + } +} \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageTraceElement.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageTraceElement.java new file mode 100644 index 0000000000..7296239610 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/TracePackageTraceElement.java @@ -0,0 +1,87 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg; + +import org.eclipse.linuxtools.tmf.ui.project.model.TmfNavigatorLabelProvider; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; +import org.eclipse.swt.graphics.Image; + +/** + * An ExportTraceElement associated to a TmfTraceElement. This will be the + * parent of other elements (events, supplementary files, bookmarks, etc). + * + * @author Marc-Andre Laperle + */ +public class TracePackageTraceElement extends TracePackageElement { + + private final TmfTraceElement fTraceElement; + private final String fImportName; + private final String fTraceType; + + /** + * Construct an instance associated to a TmfTraceElement. For exporting. + * + * @param parent + * the parent of this element, can be set to null + * @param traceElement + * the associated TmfTraceElement + */ + public TracePackageTraceElement(TracePackageElement parent, TmfTraceElement traceElement) { + super(parent); + fTraceElement = traceElement; + fImportName = null; + fTraceType = null; + } + + /** + * Construct an instance associated to a TmfTraceElement. For importing. + * + * @param parent + * the parent of this element, can be set to null + * @param importName + * the name to use to identify this trace + * @param traceType + * the trace type to set for this trace + */ + public TracePackageTraceElement(TracePackageElement parent, String importName, String traceType) { + super(parent); + fImportName = importName; + fTraceElement = null; + fTraceType = traceType; + } + + @Override + public String getText() { + return fTraceElement != null ? fTraceElement.getName() : fImportName; + } + + /** + * @return the associated TmfTraceElement + */ + public TmfTraceElement getTraceElement() { + return fTraceElement; + } + + /** + * @return the trace type of this trace + */ + public String getTraceType() { + return fTraceType; + } + + @Override + public Image getImage() { + TmfNavigatorLabelProvider tmfNavigatorLabelProvider = new TmfNavigatorLabelProvider(); + return tmfNavigatorLabelProvider.getImage(fTraceElement); + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ExportTracePackageHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ExportTracePackageHandler.java new file mode 100644 index 0000000000..525af468d2 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ExportTracePackageHandler.java @@ -0,0 +1,54 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.importexport; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * Handler for exporting a trace package + * + * @author Marc-Andre Laperle + */ +public class ExportTracePackageHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ExportTracePackageWizard w = new ExportTracePackageWizard(); + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + + if (window == null) { + return false; + } + + ISelection currentSelection = HandlerUtil.getCurrentSelection(event); + IStructuredSelection sec = StructuredSelection.EMPTY; + if (currentSelection instanceof IStructuredSelection) { + sec = (IStructuredSelection) currentSelection; + } + + w.init(PlatformUI.getWorkbench(), sec); + WizardDialog dialog = new WizardDialog(window.getShell(), w); + dialog.open(); + return null; + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ExportTracePackageSelectTraceWizardPage.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ExportTracePackageSelectTraceWizardPage.java new file mode 100644 index 0000000000..eaf11bc6e4 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ExportTracePackageSelectTraceWizardPage.java @@ -0,0 +1,155 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.importexport; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.IProject; +import org.eclipse.jface.viewers.IStructuredContentProvider; +import org.eclipse.jface.viewers.TableViewer; +import org.eclipse.jface.viewers.Viewer; +import org.eclipse.jface.wizard.WizardPage; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfNavigatorContentProvider; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfNavigatorLabelProvider; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder; +import org.eclipse.linuxtools.tmf.ui.project.model.TraceUtils; +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.layout.GridLayout; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Table; +import org.eclipse.swt.widgets.TableItem; +import org.eclipse.ui.model.WorkbenchLabelProvider; + +/** + * A wizard page for selecting the trace to export when no trace was previously + * selected. + * + * @author Marc-Andre Laperle + */ +public class ExportTracePackageSelectTraceWizardPage extends WizardPage { + + private static final String PAGE_NAME = "ExportTracePackageSelectTraceWizardPage"; //$NON-NLS-1$ + + /** + * Construct the select trace page + */ + public ExportTracePackageSelectTraceWizardPage() { + super(PAGE_NAME); + } + + private IProject fSelectedProject; + private Table fTraceTable; + + @Override + public void createControl(Composite parent) { + Composite projectSelectionGroup = new Composite(parent, SWT.NONE); + projectSelectionGroup.setLayout(new GridLayout(2, true)); + projectSelectionGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); + projectSelectionGroup.setFont(parent.getFont()); + + Label projectLabel = new Label(projectSelectionGroup, SWT.NONE); + projectLabel.setText(Messages.ExportTracePackageSelectTraceWizardPage_ProjectSelection); + projectLabel.setLayoutData(new GridData()); + + Label configLabel = new Label(projectSelectionGroup, SWT.NONE); + configLabel.setText(Messages.ExportTracePackageSelectTraceWizardPage_TraceSelection); + configLabel.setLayoutData(new GridData()); + + final Table projectTable = new Table(projectSelectionGroup, SWT.SINGLE | SWT.BORDER); + projectTable.setLayoutData(new GridData(GridData.FILL_BOTH)); + + TableViewer projectViewer = new TableViewer(projectTable); + projectViewer.setContentProvider(new TmfNavigatorContentProvider() { + + @Override + public Object[] getElements(Object inputElement) { + return (IProject[]) inputElement; + } + }); + projectViewer.setLabelProvider(new WorkbenchLabelProvider()); + projectViewer.setInput(TraceUtils.getOpenedTmfProjects().toArray(new IProject[] {})); + + fTraceTable = new Table(projectSelectionGroup, SWT.SINGLE | SWT.BORDER); + fTraceTable.setLayoutData(new GridData(GridData.FILL_BOTH)); + + final TableViewer traceViewer = new TableViewer(fTraceTable); + traceViewer.setContentProvider(new IStructuredContentProvider() { + @Override + public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { + } + + @Override + public void dispose() { + } + + @Override + public Object[] getElements(Object inputElement) { + if (inputElement instanceof TmfTraceElement[]) { + return (TmfTraceElement[]) inputElement; + } + return null; + } + }); + traceViewer.setLabelProvider(new TmfNavigatorLabelProvider()); + fTraceTable.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + TableItem[] items = fTraceTable.getSelection(); + TmfTraceElement trace = (TmfTraceElement) items[0].getData(); + ExportTracePackageWizardPage page = (ExportTracePackageWizardPage) getWizard().getPage(ExportTracePackageWizardPage.PAGE_NAME); + ArrayList traces = new ArrayList(); + traces.add(trace); + page.setSelectedTraces(traces); + } + }); + + projectTable.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + TableItem[] items = projectTable.getSelection(); + fSelectedProject = (IProject) items[0].getData(); + + // Make sure all the elements are created + new TmfNavigatorContentProvider().getChildren(fSelectedProject); + TmfProjectElement project = TmfProjectRegistry.getProject(fSelectedProject); + + TmfTraceFolder tracesFolder = project.getTracesFolder(); + List traces = tracesFolder.getTraces(); + TmfTraceElement[] array = traces.toArray(new TmfTraceElement[] {}); + traceViewer.setInput(array); + traceViewer.refresh(); + fTraceTable.select(0); + fTraceTable.notifyListeners(SWT.Selection, new Event()); + getWizard().getContainer().updateButtons(); + } + }); + + setControl(projectSelectionGroup); + setTitle(Messages.ExportTracePackageWizardPage_Title); + setMessage(Messages.ExportTracePackageSelectTraceWizardPage_ChooseTrace); + } + + @Override + public boolean canFlipToNextPage() { + return fTraceTable.getSelectionCount() > 0; + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ExportTracePackageWizard.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ExportTracePackageWizard.java new file mode 100644 index 0000000000..2eb2c2ad0d --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ExportTracePackageWizard.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.importexport; + +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.linuxtools.internal.tmf.ui.Activator; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; +import org.eclipse.ui.IExportWizard; +import org.eclipse.ui.IWorkbench; + +/** + * Wizard for exporting a trace package + * + * @author Marc-Andre Laperle + */ +public class ExportTracePackageWizard extends Wizard implements IExportWizard { + + private static final String STORE_EXPORT_TRACE_WIZARD = "ExportTraceWizard"; //$NON-NLS-1$ + private IStructuredSelection fSelection; + private ExportTracePackageWizardPage fPage; + + /** + * Constructor for the export trace wizard + */ + public ExportTracePackageWizard() { + IDialogSettings workbenchSettings = Activator.getDefault().getDialogSettings(); + IDialogSettings section = workbenchSettings + .getSection(STORE_EXPORT_TRACE_WIZARD); + if (section == null) { + section = workbenchSettings.addNewSection(STORE_EXPORT_TRACE_WIZARD); + } + setDialogSettings(section); + } + + @Override + public void init(IWorkbench workbench, IStructuredSelection selection) { + fSelection = selection; + setNeedsProgressMonitor(true); + } + + @Override + public boolean performFinish() { + return fPage.finish(); + } + + @Override + public void addPages() { + super.addPages(); + fPage = new ExportTracePackageWizardPage(fSelection); + if (!(fSelection.getFirstElement() instanceof TmfTraceElement)) { + addPage(new ExportTracePackageSelectTraceWizardPage()); + } + addPage(fPage); + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ExportTracePackageWizardPage.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ExportTracePackageWizardPage.java new file mode 100644 index 0000000000..575ddd4251 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ExportTracePackageWizardPage.java @@ -0,0 +1,450 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.importexport; + +import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.CheckboxTreeViewer; +import org.eclipse.jface.viewers.ColumnLabelProvider; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.TreeViewerColumn; +import org.eclipse.linuxtools.internal.tmf.ui.Activator; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.AbstractTracePackageWizardPage; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageLabelProvider; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +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.Group; +import org.eclipse.swt.widgets.Label; + +/** + * Wizard page for the export trace package wizard + * + * @author Marc-Andre Laperle + */ +public class ExportTracePackageWizardPage extends AbstractTracePackageWizardPage { + + private static final int CONTENT_COL_WIDTH = 300; + private static final int SIZE_COL_WIDTH = 100; + + private static final String ZIP_EXTENSION = ".zip"; //$NON-NLS-1$ + private static final String TAR_EXTENSION = ".tar"; //$NON-NLS-1$ + private static final String TAR_GZ_EXTENSION = ".tar.gz"; //$NON-NLS-1$ + private static final String TGZ_EXTENSION = ".tgz"; //$NON-NLS-1$ + + private static final String ICON_PATH = "icons/wizban/export_wiz.png"; //$NON-NLS-1$ + + /** + * The page name, can be referenced from other pages + */ + public static final String PAGE_NAME = "ExportTracePackageWizardPage"; //$NON-NLS-1$ + // dialog store id constants + private static final String STORE_COMPRESS_CONTENTS_ID = PAGE_NAME + ".STORE_COMPRESS_CONTENTS_ID"; //$NON-NLS-1$ + private static final String STORE_FORMAT_ID = PAGE_NAME + ".STORE_FORMAT_ID"; //$NON-NLS-1$ + + private Button fCompressContentsCheckbox; + private Button fZipFormatButton; + private Button fTargzFormatButton; + private Label fApproximateSizeLabel; + private List fSelectedTraces; + + /** + * Constructor for the export trace package wizard page + * + * @param selection + * the current object selection + */ + public ExportTracePackageWizardPage(IStructuredSelection selection) { + super(PAGE_NAME, Messages.ExportTracePackageWizardPage_Title, Activator.getDefault().getImageDescripterFromPath(ICON_PATH), selection); + + Object[] selectedElements = getSelection().toArray(); + fSelectedTraces = new ArrayList(); + for (Object selectedElement : selectedElements) { + if (selectedElement instanceof TmfTraceElement) { + fSelectedTraces.add(((TmfTraceElement) selectedElement).getElementUnderTraceFolder()); + } + } + } + + /** + * Set the selected trace from the previous page to be displayed in the + * element viewer + * + * @param selectedTraces + * the selected trace + */ + public void setSelectedTraces(List selectedTraces) { + if (!fSelectedTraces.containsAll(selectedTraces) || !selectedTraces.containsAll(fSelectedTraces)) { + fSelectedTraces = selectedTraces; + CheckboxTreeViewer elementViewer = getElementViewer(); + elementViewer.setInput(createElementViewerInput()); + elementViewer.expandToLevel(2); + setAllChecked(elementViewer, false, true); + updateApproximateSelectedSize(); + } + } + + @Override + public void createControl(Composite parent) { + + initializeDialogUnits(parent); + + Composite composite = new Composite(parent, SWT.NULL); + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL)); + + createElementViewer(composite); + createButtonsGroup(composite); + createFilePathGroup(composite, Messages.ExportTracePackageWizardPage_ToArchive, SWT.SAVE); + createOptionsGroup(composite); + + restoreWidgetValues(); + setMessage(Messages.ExportTracePackageWizardPage_ChooseContent); + + updateApproximateSelectedSize(); + updatePageCompletion(); + + setControl(composite); + } + + /** + * Restore widget values to the values that they held last time this wizard + * was used to completion. + */ + @Override + protected void restoreWidgetValues() { + super.restoreWidgetValues(); + + IDialogSettings settings = getDialogSettings(); + if (settings != null) { + if (getFilePathCombo().getItemCount() > 0) { + String item = getFilePathCombo().getItem(0); + setFilePathValue(item); + } + fCompressContentsCheckbox.setSelection(settings.getBoolean(STORE_COMPRESS_CONTENTS_ID)); + fZipFormatButton.setSelection(settings.getBoolean(STORE_FORMAT_ID)); + fTargzFormatButton.setSelection(!settings.getBoolean(STORE_FORMAT_ID)); + updateWithFilePathSelection(); + } + } + + @Override + protected void createFilePathGroup(Composite parent, String label, int fileDialogStyle) { + super.createFilePathGroup(parent, label, fileDialogStyle); + + getFilePathCombo().addModifyListener(new ModifyListener() { + @Override + public void modifyText(ModifyEvent e) { + updatePageCompletion(); + } + }); + } + + private void createOptionsGroup(Composite parent) { + Group optionsGroup = new Group(parent, SWT.NONE); + optionsGroup.setLayout(new RowLayout(SWT.VERTICAL)); + optionsGroup.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_FILL + | GridData.GRAB_HORIZONTAL)); + optionsGroup.setText(Messages.ExportTracePackageWizardPage_Options); + + SelectionAdapter listener = new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + updateWithFilePathSelection(); + } + }; + + fZipFormatButton = new Button(optionsGroup, SWT.RADIO | SWT.LEFT); + fZipFormatButton.setText(Messages.ExportTracePackageWizardPage_SaveInZipFormat); + fZipFormatButton.setSelection(true); + fZipFormatButton.addSelectionListener(listener); + + fTargzFormatButton = new Button(optionsGroup, SWT.RADIO | SWT.LEFT); + fTargzFormatButton.setText(Messages.ExportTracePackageWizardPage_SaveInTarFormat); + fTargzFormatButton.setSelection(false); + fTargzFormatButton.addSelectionListener(listener); + + fCompressContentsCheckbox = new Button(optionsGroup, SWT.CHECK | SWT.LEFT); + fCompressContentsCheckbox.setText(Messages.ExportTracePackageWizardPage_CompressContents); + fCompressContentsCheckbox.setSelection(true); + fCompressContentsCheckbox.addSelectionListener(listener); + } + + @Override + protected void createElementViewer(Composite parent) { + super.createElementViewer(parent); + + CheckboxTreeViewer elementViewer = getElementViewer(); + elementViewer.getTree().setHeaderVisible(true); + // Content column + TreeViewerColumn column = new TreeViewerColumn(elementViewer, SWT.NONE); + column.getColumn().setWidth(CONTENT_COL_WIDTH); + column.getColumn().setText(Messages.ExportTracePackageWizardPage_ContentColumnName); + column.setLabelProvider(new TracePackageLabelProvider()); + + // Size column + column = new TreeViewerColumn(elementViewer, SWT.NONE); + column.getColumn().setWidth(SIZE_COL_WIDTH); + column.getColumn().setText(Messages.ExportTracePackageWizardPage_SizeColumnName); + column.setLabelProvider(new ColumnLabelProvider() { + @Override + public String getText(Object element) { + TracePackageElement tracePackageElement = (TracePackageElement) element; + long size = tracePackageElement.getSize(false); + if (size == 0) { + return null; + } + int level = 0; + TracePackageElement curElement = tracePackageElement.getParent(); + while (curElement != null) { + curElement = curElement.getParent(); + ++level; + } + + return indent(getHumanReadable(size), level); + } + + private String indent(String humanReadable, int level) { + StringBuilder s = new StringBuilder(humanReadable); + for (int i = 0; i < level; ++i) { + final String indentStr = " "; //$NON-NLS-1$ + s.insert(0, indentStr); + } + return s.toString(); + } + }); + + elementViewer.setInput(createElementViewerInput()); + elementViewer.expandToLevel(2); + setAllChecked(elementViewer, false, true); + } + + @Override + protected void updateApproximateSelectedSize() { + long checkedSize = 0; + TracePackageElement[] tracePackageElements = (TracePackageElement[]) getElementViewer().getInput(); + for (TracePackageElement element : tracePackageElements) { + checkedSize += element.getSize(true); + } + checkedSize = Math.max(0, checkedSize); + fApproximateSizeLabel.setText(MessageFormat.format(Messages.ExportTracePackageWizardPage_ApproximateSizeLbl, getHumanReadable(checkedSize))); + } + + /** + * Get the human readable string for a size in bytes. (KB, MB, etc). + * + * @param size + * the size to print in human readable, + * @return the human readable string + */ + private static String getHumanReadable(long size) { + String humanSuffix[] = { Messages.ExportTracePackageWizardPage_SizeByte, Messages.ExportTracePackageWizardPage_SizeKilobyte, + Messages.ExportTracePackageWizardPage_SizeMegabyte, Messages.ExportTracePackageWizardPage_SizeGigabyte, + Messages.ExportTracePackageWizardPage_SizeTerabyte }; + long curSize = size; + + int suffixIndex = 0; + while (curSize >= 1024) { + curSize /= 1024; + ++suffixIndex; + } + + return Long.toString(curSize) + " " + humanSuffix[suffixIndex]; //$NON-NLS-1$ + } + + @Override + protected Object createElementViewerInput() { + List traceElements = new ArrayList(); + for (TmfTraceElement tmfTraceElement : fSelectedTraces) { + TracePackageTraceElement traceElement = new TracePackageTraceElement(null, tmfTraceElement); + + // Trace files + List children = new ArrayList(); + TracePackageFilesElement filesElement = new TracePackageFilesElement(traceElement, tmfTraceElement.getResource()); + filesElement.setChecked(true); + // Always export the files + filesElement.setEnabled(false); + children.add(filesElement); + + // Supplementary files + IResource[] supplementaryResources = tmfTraceElement.getSupplementaryResources(); + List suppFilesChildren = new ArrayList(); + TracePackageSupplFilesElement suppFilesElement = new TracePackageSupplFilesElement(traceElement); + children.add(suppFilesElement); + for (IResource res : supplementaryResources) { + suppFilesChildren.add(new TracePackageSupplFileElement(res, suppFilesElement)); + } + suppFilesElement.setChildren(suppFilesChildren.toArray(new TracePackageElement[] {})); + + // Bookmarks + IFile bookmarksFile = tmfTraceElement.getBookmarksFile(); + if (bookmarksFile != null && bookmarksFile.exists()) { + IMarker[] findMarkers; + try { + findMarkers = bookmarksFile.findMarkers(IMarker.BOOKMARK, false, IResource.DEPTH_ZERO); + if (findMarkers.length > 0) { + children.add(new TracePackageBookmarkElement(traceElement, null)); + } + } catch (CoreException e) { + // Should not happen since we just checked bookmarksFile.exists() but log it just in case + Activator.getDefault().logError("Error finding bookmarks", e); //$NON-NLS-1$ + } + } + + traceElement.setChildren(children.toArray(new TracePackageElement[] {})); + + traceElements.add(traceElement); + + } + + return traceElements.toArray(new TracePackageTraceElement[] {}); + } + + @Override + protected final Composite createButtonsGroup(Composite parent) { + Composite buttonGroup = super.createButtonsGroup(parent); + + // Add the label on the same row of the select/deselect all buttons + fApproximateSizeLabel = new Label(buttonGroup, SWT.RIGHT); + GridData layoutData = new GridData(GridData.FILL_HORIZONTAL); + layoutData.grabExcessHorizontalSpace = true; + fApproximateSizeLabel.setLayoutData(layoutData); + + return buttonGroup; + } + + /** + * Save widget values to Dialog settings + */ + @Override + protected void saveWidgetValues() { + super.saveWidgetValues(); + + IDialogSettings settings = getDialogSettings(); + if (settings != null) { + settings.put(STORE_COMPRESS_CONTENTS_ID, fCompressContentsCheckbox.getSelection()); + settings.put(STORE_FORMAT_ID, fZipFormatButton.getSelection()); + } + } + + private String getOutputExtension() { + if (fZipFormatButton.getSelection()) { + return ZIP_EXTENSION; + } else if (fCompressContentsCheckbox.getSelection()) { + return TAR_GZ_EXTENSION; + } else { + return TAR_EXTENSION; + } + } + + @Override + protected void updateWithFilePathSelection() { + String filePathValue = getFilePathValue(); + if (filePathValue.isEmpty()) { + return; + } + + filePathValue = stripKnownExtension(filePathValue); + filePathValue = filePathValue.concat(getOutputExtension()); + + setFilePathValue(filePathValue); + } + + private static String stripKnownExtension(String str) { + String ret = str; + if (str.endsWith(TAR_GZ_EXTENSION)) { + ret = ret.substring(0, ret.lastIndexOf(".")); //$NON-NLS-1$ + } + + if (ret.endsWith(ZIP_EXTENSION) | ret.endsWith(TAR_EXTENSION) | ret.endsWith(TGZ_EXTENSION)) { + ret = ret.substring(0, ret.lastIndexOf(".")); //$NON-NLS-1$ + } + + return ret; + } + + /** + * Finish the wizard page + * + * @return true on success + */ + public boolean finish() { + if (!checkForOverwrite()) { + return false; + } + + saveWidgetValues(); + + TracePackageTraceElement[] traceExportElements = (TracePackageTraceElement[]) getElementViewer().getInput(); + boolean useCompression = fCompressContentsCheckbox.getSelection(); + boolean useTar = fTargzFormatButton.getSelection(); + String fileName = getFilePathValue(); + final TracePackageExportOperation exporter = new TracePackageExportOperation(traceExportElements, useCompression, useTar, fileName); + + try { + getContainer().run(true, true, new IRunnableWithProgress() { + + @Override + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + exporter.run(monitor); + } + }); + + IStatus status = exporter.getStatus(); + if (status.getSeverity() == IStatus.ERROR) { + handleErrorStatus(status); + } + + } catch (InvocationTargetException e) { + handleError(org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorOperation, e); + } catch (InterruptedException e) { + } + + return exporter.getStatus().getSeverity() == IStatus.OK; + } + + private boolean checkForOverwrite() { + File file = new File(getFilePathValue()); + if (file.exists()) { + return MessageDialog.openQuestion(getContainer().getShell(), null, Messages.ExportTracePackageWizardPage_AlreadyExitst); + } + return true; + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ImportTracePackageHandler.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ImportTracePackageHandler.java new file mode 100644 index 0000000000..840bfe33a0 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ImportTracePackageHandler.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.importexport; + +import org.eclipse.core.commands.AbstractHandler; +import org.eclipse.core.commands.ExecutionEvent; +import org.eclipse.core.commands.ExecutionException; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.StructuredSelection; +import org.eclipse.jface.wizard.WizardDialog; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.handlers.HandlerUtil; + +/** + * Handler for importing a trace package + * + * @author Marc-Andre Laperle + */ +public class ImportTracePackageHandler extends AbstractHandler { + + @Override + public Object execute(ExecutionEvent event) throws ExecutionException { + ImportTracePackageWizard w = new ImportTracePackageWizard(); + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + + if (window == null) { + return false; + } + + ISelection currentSelection = HandlerUtil.getCurrentSelection(event); + IStructuredSelection sec = StructuredSelection.EMPTY; + if (currentSelection instanceof IStructuredSelection) { + sec = (IStructuredSelection) currentSelection; + } + + w.init(PlatformUI.getWorkbench(), sec); + WizardDialog dialog = new WizardDialog(window.getShell(), w); + dialog.open(); + return null; + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ImportTracePackageWizard.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ImportTracePackageWizard.java new file mode 100644 index 0000000000..8acf158f8d --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ImportTracePackageWizard.java @@ -0,0 +1,63 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.importexport; + +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.wizard.Wizard; +import org.eclipse.linuxtools.internal.tmf.ui.Activator; +import org.eclipse.ui.IImportWizard; +import org.eclipse.ui.IWorkbench; + +/** + * Wizard for importing a trace package + * + * @author Marc-Andre Laperle + */ +public class ImportTracePackageWizard extends Wizard implements IImportWizard { + + private static final String STORE_IMPORT_TRACE_PKG_WIZARD = "ImportTracePackageWizard"; //$NON-NLS-1$ + private IStructuredSelection fSelection; + private ImportTracePackageWizardPage fPage; + + /** + * Constructs the import trace package wizard + */ + public ImportTracePackageWizard() { + IDialogSettings workbenchSettings = Activator.getDefault().getDialogSettings(); + IDialogSettings section = workbenchSettings + .getSection(STORE_IMPORT_TRACE_PKG_WIZARD); + if (section == null) { + section = workbenchSettings.addNewSection(STORE_IMPORT_TRACE_PKG_WIZARD); + } + setDialogSettings(section); + } + + @Override + public void init(IWorkbench workbench, IStructuredSelection selection) { + fSelection = selection; + setNeedsProgressMonitor(true); + } + + @Override + public boolean performFinish() { + return fPage.finish(); + } + + @Override + public void addPages() { + super.addPages(); + fPage = new ImportTracePackageWizardPage(fSelection); + addPage(fPage); + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ImportTracePackageWizardPage.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ImportTracePackageWizardPage.java new file mode 100644 index 0000000000..e57e5e4fcb --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/ImportTracePackageWizardPage.java @@ -0,0 +1,354 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.importexport; + +import java.io.File; +import java.lang.reflect.InvocationTargetException; +import java.util.List; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.jface.dialogs.IDialogSettings; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.operation.IRunnableWithProgress; +import org.eclipse.jface.viewers.CheckboxTreeViewer; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.linuxtools.internal.tmf.ui.Activator; +import org.eclipse.linuxtools.internal.tmf.ui.project.model.TmfImportHelper; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.AbstractTracePackageWizardPage; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfNavigatorContentProvider; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder; +import org.eclipse.linuxtools.tmf.ui.project.model.TraceUtils; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.events.TraverseEvent; +import org.eclipse.swt.events.TraverseListener; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.layout.GridLayout; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Event; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Listener; +import org.eclipse.swt.widgets.Text; +import org.eclipse.ui.dialogs.ElementListSelectionDialog; +import org.eclipse.ui.model.WorkbenchLabelProvider; + +/** + * Wizard page for the import trace package wizard + * + * @author Marc-Andre Laperle + */ +public class ImportTracePackageWizardPage extends AbstractTracePackageWizardPage { + + private static final String ICON_PATH = "icons/wizban/trace_import_wiz.png"; //$NON-NLS-1$ + private static final String PAGE_NAME = "ImportTracePackagePage"; //$NON-NLS-1$ + private static final String STORE_PROJECT_NAME_ID = PAGE_NAME + ".STORE_PROJECT_NAME_ID"; //$NON-NLS-1$ + + private String fValidatedFilePath; + private TmfTraceFolder fTmfTraceFolder; + private Text fProjectText; + private List fOpenedTmfProjects; + + /** + * Constructor for the import trace package wizard page + * + * @param selection + * the current object selection + */ + public ImportTracePackageWizardPage(IStructuredSelection selection) { + super(PAGE_NAME, Messages.ImportTracePackageWizardPage_Title, Activator.getDefault().getImageDescripterFromPath(ICON_PATH), selection); + + if (getSelection().getFirstElement() instanceof TmfTraceFolder) { + fTmfTraceFolder = (TmfTraceFolder) getSelection().getFirstElement(); + } + } + + @Override + public void createControl(Composite parent) { + initializeDialogUnits(parent); + + Composite composite = new Composite(parent, SWT.NULL); + composite.setLayout(new GridLayout()); + composite.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_FILL + | GridData.HORIZONTAL_ALIGN_FILL)); + composite.setFont(parent.getFont()); + + createFilePathGroup(composite, Messages.ImportTracePackageWizardPage_FromArchive, SWT.OPEN); + createElementViewer(composite); + createButtonsGroup(composite); + if (fTmfTraceFolder == null) { + createProjectSelectionGroup(composite); + } + + restoreWidgetValues(); + setMessage(Messages.ImportTracePackageWizardPage_Message); + updatePageCompletion(); + + setControl(composite); + } + + private void createProjectSelectionGroup(Composite parent) { + + Composite projectSelectionGroup = new Composite(parent, SWT.NONE); + GridLayout layout = new GridLayout(); + layout.numColumns = 3; + projectSelectionGroup.setLayout(layout); + projectSelectionGroup.setLayoutData(new GridData( + GridData.HORIZONTAL_ALIGN_FILL | GridData.VERTICAL_ALIGN_FILL)); + + Label projectLabel = new Label(projectSelectionGroup, SWT.NONE); + projectLabel.setText(Messages.ImportTracePackageWizardPage_Project); + + fProjectText = new Text(projectSelectionGroup, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY); + GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL + | GridData.GRAB_HORIZONTAL); + data.grabExcessHorizontalSpace = true; + fProjectText.setLayoutData(data); + + fOpenedTmfProjects = TraceUtils.getOpenedTmfProjects(); + + // No project to import to, create a default project if it doesn't exist + if (fOpenedTmfProjects.isEmpty()) { + IProject defaultProject = ResourcesPlugin.getWorkspace().getRoot().getProject(TmfCommonConstants.DEFAULT_TRACE_PROJECT_NAME); + if (!defaultProject.exists()) { + IProject project = TmfProjectRegistry.createProject(TmfCommonConstants.DEFAULT_TRACE_PROJECT_NAME, null, null); + TmfImportHelper.forceFolderRefresh(project.getFolder(TmfTraceFolder.TRACE_FOLDER_NAME)); + fOpenedTmfProjects.add(project); + } + } + + if (!fOpenedTmfProjects.isEmpty()) { + selectProject(fOpenedTmfProjects.get(0)); + } + + Button button = new Button(projectSelectionGroup, + SWT.PUSH); + button.setText(Messages.ImportTracePackageWizardPage_SelectProjectButton); + button.addListener(SWT.Selection, new Listener() { + @Override + public void handleEvent(Event event) { + ElementListSelectionDialog d = new ElementListSelectionDialog(getContainer().getShell(), new WorkbenchLabelProvider()); + + d.setBlockOnOpen(true); + d.setTitle(Messages.ImportTracePackageWizardPage_SelectProjectDialogTitle); + + d.setElements(fOpenedTmfProjects.toArray(new IProject[] {})); + + d.open(); + if (d.getFirstResult() != null) { + IProject project = (IProject) d.getFirstResult(); + selectProject(project); + } + } + }); + setButtonLayoutData(button); + } + + @Override + protected void restoreWidgetValues() { + super.restoreWidgetValues(); + IDialogSettings settings = getDialogSettings(); + if (settings != null && fProjectText != null) { + + // Restore last selected project + String projectName = settings.get(STORE_PROJECT_NAME_ID); + if (projectName != null && !projectName.isEmpty()) { + for (IProject project : fOpenedTmfProjects) { + if (project.getName().equals(projectName)) { + selectProject(project); + break; + } + } + } + } + } + + @Override + protected void saveWidgetValues() { + super.saveWidgetValues(); + + IDialogSettings settings = getDialogSettings(); + if (settings != null) { + settings.put(STORE_PROJECT_NAME_ID, fTmfTraceFolder.getProject().getResource().getName()); + } + } + + private void selectProject(IProject project) { + fProjectText.setText(project.getName()); + new TmfNavigatorContentProvider().getChildren(project); + fTmfTraceFolder = TmfProjectRegistry.getProject(project).getTracesFolder(); + updatePageCompletion(); + } + + @Override + protected boolean determinePageCompletion() { + return super.determinePageCompletion() && fTmfTraceFolder != null; + } + + @Override + protected Object createElementViewerInput() { + + final TracePackageExtractManifestOperation op = new TracePackageExtractManifestOperation(getFilePathValue()); + + try { + getContainer().run(true, true, new IRunnableWithProgress() { + + @Override + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + monitor.beginTask(Messages.ImportTracePackageWizardPage_ReadingPackage, 10); + op.run(monitor); + monitor.done(); + } + + }); + + IStatus status = op.getStatus(); + if (status.getSeverity() == IStatus.ERROR) { + handleErrorStatus(status); + } + } catch (InvocationTargetException e1) { + handleError(Messages.TracePackageExtractManifestOperation_ErrorReadingManifest, e1); + } catch (InterruptedException e1) { + // Canceled + } + + TracePackageElement resultElement = op.getResultElement(); + if (resultElement == null) { + return null; + } + + for (TracePackageElement e : resultElement.getChildren()) { + if (e instanceof TracePackageFilesElement) { + e.setEnabled(false); + } + } + + return new TracePackageElement[] { resultElement }; + } + + @Override + protected void createFilePathGroup(Composite parent, String label, int fileDialogStyle) { + super.createFilePathGroup(parent, label, fileDialogStyle); + + Combo filePathCombo = getFilePathCombo(); + filePathCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + updateWithFilePathSelection(); + } + }); + + // User can type-in path and press return to validate + filePathCombo.addTraverseListener(new TraverseListener() { + @Override + public void keyTraversed(TraverseEvent e) { + if (e.detail == SWT.TRAVERSE_RETURN) { + e.doit = false; + updateWithFilePathSelection(); + } + } + }); + } + + @Override + protected void updateWithFilePathSelection() { + if (!isFilePathValid()) { + setErrorMessage(Messages.ImportTracePackageWizardPage_ErrorFileNotFound); + getElementViewer().setInput(null); + return; + } + setErrorMessage(null); + + getContainer().getShell().getDisplay().asyncExec(new Runnable() { + @Override + public void run() { + CheckboxTreeViewer elementViewer = getElementViewer(); + Object elementViewerInput = createElementViewerInput(); + elementViewer.setInput(elementViewerInput); + if (elementViewerInput != null) { + elementViewer.expandToLevel(2); + setAllChecked(elementViewer, false, true); + fValidatedFilePath = getFilePathValue(); + } + + updatePageCompletion(); + } + }); + } + + private boolean isFilePathValid() { + return new File(getFilePathValue()).exists(); + } + + /** + * Finish the wizard page + * + * @return true on success + */ + public boolean finish() { + if (!checkForOverwrite()) { + return false; + } + + saveWidgetValues(); + + TracePackageElement[] input = (TracePackageElement[]) getElementViewer().getInput(); + TracePackageTraceElement traceElement = (TracePackageTraceElement) input[0]; + final TracePackageImportOperation importOperation = new TracePackageImportOperation(fValidatedFilePath, traceElement, fTmfTraceFolder); + + try { + getContainer().run(true, true, new IRunnableWithProgress() { + @Override + public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { + importOperation.run(monitor); + } + }); + + IStatus status = importOperation.getStatus(); + if (status.getSeverity() == IStatus.ERROR) { + handleErrorStatus(status); + } + + } catch (InvocationTargetException e) { + handleError(Messages.ImportTracePackageWizardPage_ErrorOperation, e); + } catch (InterruptedException e) { + } + + return importOperation.getStatus().getSeverity() == IStatus.OK; + } + + private boolean checkForOverwrite() { + TracePackageTraceElement traceElement = (TracePackageTraceElement) ((TracePackageElement[]) getElementViewer().getInput())[0]; + String traceName = traceElement.getText(); + + List traces = fTmfTraceFolder.getTraces(); + for (TmfTraceElement t : traces) { + if (t.getName().equals(traceName)) { + return MessageDialog.openQuestion(getContainer().getShell(), null, Messages.ImportTracePackageWizardPage_AlreadyExists); + } + } + + return true; + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/Messages.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/Messages.java new file mode 100644 index 0000000000..051423a5dd --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/Messages.java @@ -0,0 +1,234 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.importexport; + +import org.eclipse.osgi.util.NLS; + +/** + * Messages for the trace package export wizard + * + * @author Marc-Andre Laperle + */ +public class Messages extends NLS { + private static final String BUNDLE_NAME = "org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.importexport.messages"; //$NON-NLS-1$ + + /** + * The message under the select trace wizard page title + */ + public static String ExportTracePackageSelectTraceWizardPage_ChooseTrace; + + /** + * The description of the project selection list + */ + public static String ExportTracePackageSelectTraceWizardPage_ProjectSelection; + + /** + * The description of the trace selection list + */ + public static String ExportTracePackageSelectTraceWizardPage_TraceSelection; + + /** + * Dialog text when target file already exists + */ + public static String ExportTracePackageWizardPage_AlreadyExitst; + + /** + * The approximate size label + */ + public static String ExportTracePackageWizardPage_ApproximateSizeLbl; + + /** + * The message under the wizard page title + */ + public static String ExportTracePackageWizardPage_ChooseContent; + + /** + * Text for the compress contents checkbox + */ + public static String ExportTracePackageWizardPage_CompressContents; + + /** + * Text for the first column (content) + */ + public static String ExportTracePackageWizardPage_ContentColumnName; + + /** + * Text for the options group + */ + public static String ExportTracePackageWizardPage_Options; + + /** + * Text for the tar format option + */ + public static String ExportTracePackageWizardPage_SaveInTarFormat; + + /** + * Text for the zip format option + */ + public static String ExportTracePackageWizardPage_SaveInZipFormat; + + /** + * Byte units + */ + public static String ExportTracePackageWizardPage_SizeByte; + + /** + * Text for the second column (size) + */ + public static String ExportTracePackageWizardPage_SizeColumnName; + + /** + * Gigabyte units + */ + public static String ExportTracePackageWizardPage_SizeGigabyte; + + /** + * Kilobyte units + */ + public static String ExportTracePackageWizardPage_SizeKilobyte; + + /** + * Megabyte units + */ + public static String ExportTracePackageWizardPage_SizeMegabyte; + + /** + * Terabyte units + */ + public static String ExportTracePackageWizardPage_SizeTerabyte; + + /** + * Title for the wizard page + */ + public static String ExportTracePackageWizardPage_Title; + + /** + * Label for the file path + */ + public static String ExportTracePackageWizardPage_ToArchive; + + /** + * Dialog text when a trace with the same name already exists + */ + public static String ImportTracePackageWizardPage_AlreadyExists; + + /** + * Title for the import page + */ + public static String ImportTracePackageWizardPage_Title; + + /** + * Text for the source archive label + */ + public static String ImportTracePackageWizardPage_FromArchive; + + /** + * Text for the reading package job + */ + public static String ImportTracePackageWizardPage_ReadingPackage; + + /** + * Message when file is not found + */ + public static String ImportTracePackageWizardPage_ErrorFileNotFound; + + /** + * Message when trace type could not be set + */ + public static String ImportTracePackageWizardPage_ErrorSettingTraceType; + + /** + * Message when the trace could not be found after importing the files + */ + public static String ImportTracePackageWizardPage_ErrorFindingImportedTrace; + + /** + * The message displayed under the title + */ + public static String ImportTracePackageWizardPage_Message; + + /** + * Generic error message for the import operation + */ + public static String ImportTracePackageWizardPage_ErrorOperation; + + /** + * Project text label + */ + public static String ImportTracePackageWizardPage_Project; + + /** + * The select project button text + */ + public static String ImportTracePackageWizardPage_SelectProjectButton; + + /** + * The select project dialog title + */ + public static String ImportTracePackageWizardPage_SelectProjectDialogTitle; + + /** + * Text for the generating package job + */ + public static String TracePackageExportOperation_GeneratingPackage; + + /** + * Text when error occurs creating a bookmark + */ + public static String TracePackageImportOperation_ErrorCreatingBookmark; + + /** + * Text when error occurs creating a bookmark file + */ + public static String TracePackageImportOperation_ErrorCreatingBookmarkFile; + + /** + * Text for the importing package job + */ + public static String TracePackageImportOperation_ImportingPackage; + + /** + * Text when error occurs when the manifest is not found in the archive + */ + public static String TracePackageExtractManifestOperation_ErrorManifestNotFound; + + /** + * Text when error occurs when the manifest is not valid + */ + public static String TracePackageExtractManifestOperation_ErrorManifestNotValid; + + /** + * Generic error message when reading the manifest + */ + public static String TracePackageExtractManifestOperation_ErrorReadingManifest; + + /** + * Error message when the file is an invalid format + */ + public static String TracePackageExtractManifestOperation_InvalidFormat; + + /** + * Error when the schema file cannot be found to validate the export + * manifest + */ + public static String TracePackageExtractManifestOperation_SchemaFileNotFound; + + static { + // initialize resource bundle + NLS.initializeMessages(BUNDLE_NAME, Messages.class); + } + + private Messages() { + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageExportOperation.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageExportOperation.java new file mode 100644 index 0000000000..c53b56dd50 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageExportOperation.java @@ -0,0 +1,279 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.importexport; + +import java.io.ByteArrayInputStream; +import java.io.StringWriter; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; +import java.util.List; + +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.jface.operation.ModalContext; +import org.eclipse.linuxtools.internal.tmf.ui.Activator; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.AbstractTracePackageOperation; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.ITracePackageConstants; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder; +import org.eclipse.ui.internal.wizards.datatransfer.ArchiveFileExportOperation; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + +/** + * An operation that exports a trace package to an archive + * + * @author Marc-Andre Laperle + */ +@SuppressWarnings("restriction") +public class TracePackageExportOperation extends AbstractTracePackageOperation { + + private static final String TRACE_EXPORT_TEMP_FOLDER = ".traceExport"; //$NON-NLS-1$ + + private final TracePackageTraceElement[] fTraceExportElements; + private final boolean fUseCompression; + private final boolean fUseTar; + private final List fResources; + private IFolder fExportFolder; + + /** + * Constructs a new export operation + * + * @param traceExportElements + * the trace elements to be exported + * @param useCompression + * whether or not to use compression + * @param useTar + * use tar format or zip + * @param fileName + * the output file name + */ + public TracePackageExportOperation(TracePackageTraceElement[] traceExportElements, boolean useCompression, boolean useTar, String fileName) { + super(fileName); + fTraceExportElements = traceExportElements; + fUseCompression = useCompression; + fUseTar = useTar; + fResources = new ArrayList(); + } + + /** + * Run the operation. The status (result) of the operation can be obtained + * with {@link #getStatus} + * + * @param progressMonitor + * the progress monitor to use to display progress and receive + * requests for cancellation + */ + @Override + public void run(IProgressMonitor progressMonitor) { + + try { + int totalWork = getNbCheckedElements(fTraceExportElements) * 2; + progressMonitor.beginTask(Messages.TracePackageExportOperation_GeneratingPackage, totalWork); + + fExportFolder = createExportFolder(progressMonitor); + + Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument(); + Element createElement = doc.createElement(ITracePackageConstants.TMF_EXPORT_ELEMENT); + Node tmfNode = doc.appendChild(createElement); + + for (TracePackageTraceElement tracePackageElement : fTraceExportElements) { + exportTrace(progressMonitor, tmfNode, tracePackageElement); + } + + Transformer transformer = TransformerFactory.newInstance().newTransformer(); + transformer.setOutputProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$ + transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); //$NON-NLS-1$ //$NON-NLS-2$ + DOMSource source = new DOMSource(doc); + StringWriter buffer = new StringWriter(); + StreamResult result = new StreamResult(buffer); + transformer.transform(source, result); + String content = buffer.getBuffer().toString(); + + ModalContext.checkCanceled(progressMonitor); + + exportManifest(content); + + setStatus(exportToArchive(progressMonitor, totalWork)); + + fExportFolder.delete(true, new SubProgressMonitor(progressMonitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); + + progressMonitor.done(); + + } catch (Exception e) { + if (e instanceof InterruptedException) { + setStatus(Status.CANCEL_STATUS); + } else { + setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorOperation, e)); + } + } + } + + private IFolder createExportFolder(IProgressMonitor monitor) throws CoreException { + IFolder folder = fTraceExportElements[0].getTraceElement().getProject().getResource().getFolder(TRACE_EXPORT_TEMP_FOLDER); + if (folder.exists()) { + folder.delete(true, null); + } + folder.create(IResource.FORCE | IResource.HIDDEN, true, new SubProgressMonitor(monitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); + return folder; + } + + private void exportTrace(IProgressMonitor monitor, Node tmfNode, TracePackageTraceElement tracePackageElement) throws InterruptedException, CoreException { + TmfTraceElement traceElement = tracePackageElement.getTraceElement(); + Element traceXmlElement = tmfNode.getOwnerDocument().createElement(ITracePackageConstants.TRACE_ELEMENT); + traceXmlElement.setAttribute(ITracePackageConstants.TRACE_NAME_ATTRIB, traceElement.getResource().getName()); + traceXmlElement.setAttribute(ITracePackageConstants.TRACE_TYPE_ATTRIB, traceElement.getTraceType()); + Node traceNode = tmfNode.appendChild(traceXmlElement); + + for (TracePackageElement element : tracePackageElement.getChildren()) { + ModalContext.checkCanceled(monitor); + if (!element.isChecked()) { + continue; + } + + if (element instanceof TracePackageSupplFilesElement) { + exportSupplementaryFiles(monitor, traceNode, traceElement, (TracePackageSupplFilesElement) element); + } else if (element instanceof TracePackageBookmarkElement) { + exportBookmarks(monitor, traceNode, (TracePackageBookmarkElement) element); + } else if (element instanceof TracePackageFilesElement) { + exportTraceFiles(monitor, traceNode, (TracePackageFilesElement) element); + } + + monitor.worked(1); + } + } + + private void exportSupplementaryFiles(IProgressMonitor monitor, Node traceNode, TmfTraceElement traceElement, TracePackageSupplFilesElement element) throws InterruptedException, CoreException { + Document doc = traceNode.getOwnerDocument(); + if (element.getChildren().length > 0) { + IFolder suppFilesFolder = fExportFolder.getFolder(TmfCommonConstants.TRACE_SUPPLEMENATARY_FOLDER_NAME); + if (!suppFilesFolder.exists()) { + suppFilesFolder.create(IResource.FORCE, true, new SubProgressMonitor(monitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); + } + IFolder traceSuppFilesFolder = suppFilesFolder.getFolder(traceElement.getResource().getName()); + traceSuppFilesFolder.create(IResource.FORCE, true, new SubProgressMonitor(monitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); + + for (TracePackageElement child : element.getChildren()) { + TracePackageSupplFileElement supplFile = (TracePackageSupplFileElement) child; + ModalContext.checkCanceled(monitor); + IResource res = supplFile.getResource(); + res.refreshLocal(0, new SubProgressMonitor(monitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); + createExportResource(traceSuppFilesFolder, res); + Element suppFileElement = doc.createElement(ITracePackageConstants.SUPPLEMENTARY_FILE_ELEMENT); + suppFileElement.setAttribute(ITracePackageConstants.SUPPLEMENTARY_FILE_NAME_ATTRIB, res.getName()); + traceNode.appendChild(suppFileElement); + } + + fResources.add(suppFilesFolder); + } + } + + private void exportTraceFiles(IProgressMonitor monitor, Node traceNode, TracePackageFilesElement element) throws CoreException { + Document doc = traceNode.getOwnerDocument(); + IResource resource = ((TracePackageTraceElement) element.getParent()).getTraceElement().getResource(); + IFolder folder = fExportFolder.getFolder(TmfTraceFolder.TRACE_FOLDER_NAME); + if (!folder.exists()) { + folder.create(IResource.FORCE, true, new SubProgressMonitor(monitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); + } + + createExportResource(folder, resource); + Element fileElement = doc.createElement(ITracePackageConstants.TRACE_FILE_ELEMENT); + fileElement.setAttribute(ITracePackageConstants.TRACE_FILE_NAME_ATTRIB, resource.getName()); + traceNode.appendChild(fileElement); + fResources.add(folder); + } + + /** + * Creates a linked resource in the specified folder + * + * @param exportFolder the folder that will contain the linked resource + * @param res the resource to export + * @throws CoreException when createLink fails + */ + private static void createExportResource(IFolder exportFolder, IResource res) throws CoreException { + // Note: The resources cannot be HIDDEN or else they are ignored by ArchiveFileExportOperation + if (res instanceof IFolder) { + IFolder folder = exportFolder.getFolder(res.getName()); + folder.createLink(res.getLocationURI(), IResource.NONE, null); + } else if (res instanceof IFile) { + IFile file = exportFolder.getFile(res.getName()); + file.createLink(res.getLocationURI(), IResource.NONE, null); + } + } + + private static void exportBookmarks(IProgressMonitor monitor, Node traceNode, TracePackageBookmarkElement element) throws CoreException, InterruptedException { + Document doc = traceNode.getOwnerDocument(); + IFile bookmarksFile = ((TracePackageTraceElement) element.getParent()).getTraceElement().getBookmarksFile(); + if (bookmarksFile != null && bookmarksFile.exists()) { + IMarker[] findMarkers = bookmarksFile.findMarkers(IMarker.BOOKMARK, false, IResource.DEPTH_ZERO); + if (findMarkers.length > 0) { + Element bookmarksXmlElement = doc.createElement(ITracePackageConstants.BOOKMARKS_ELEMENT); + Node bookmarksNode = traceNode.appendChild(bookmarksXmlElement); + + for (IMarker marker : findMarkers) { + ModalContext.checkCanceled(monitor); + + Element singleBookmarkXmlElement = doc.createElement(ITracePackageConstants.BOOKMARK_ELEMENT); + for (String key : marker.getAttributes().keySet()) { + singleBookmarkXmlElement.setAttribute(key, marker.getAttribute(key).toString()); + } + + bookmarksNode.appendChild(singleBookmarkXmlElement); + } + } + } + } + + private void exportManifest(String content) throws CoreException { + IFile file = fExportFolder.getFile(ITracePackageConstants.MANIFEST_FILENAME); + ByteArrayInputStream inputStream = new ByteArrayInputStream(content.getBytes()); + if (file.exists()) { + file.setContents(inputStream, IResource.FORCE, null); + } else { + file.create(inputStream, IResource.FORCE | IResource.HIDDEN, null); + } + fResources.add(file); + } + + private IStatus exportToArchive(IProgressMonitor monitor, int totalWork) throws InvocationTargetException, InterruptedException { + ArchiveFileExportOperation op = new ArchiveFileExportOperation(fResources, getFileName()); + op.setCreateLeadupStructure(false); + op.setUseCompression(fUseCompression); + op.setUseTarFormat(fUseTar); + op.run(new SubProgressMonitor(monitor, totalWork / 2, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); + + return op.getStatus(); + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageExtractManifestOperation.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageExtractManifestOperation.java new file mode 100644 index 0000000000..7cff208d55 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageExtractManifestOperation.java @@ -0,0 +1,243 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.importexport; + +import java.io.IOException; +import java.io.InputStream; +import java.net.URL; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.SchemaFactory; +import javax.xml.validation.Validator; + +import org.eclipse.core.runtime.FileLocator; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.operation.ModalContext; +import org.eclipse.linuxtools.internal.tmf.ui.Activator; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.AbstractTracePackageOperation; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.ITracePackageConstants; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +/** + * An operation that extracts information from the manifest located in an + * archive + * + * @author Marc-Andre Laperle + */ +public class TracePackageExtractManifestOperation extends AbstractTracePackageOperation { + + private static final String SCHEMA_FOLDER_NAME = "schema"; //$NON-NLS-1$ + private static final String EXPORT_MANIFEST_SCHEMA_FILE_NAME = "export-manifest.xsd"; //$NON-NLS-1$ + + // Result of reading the manifest + private TracePackageElement fResultElement; + + /** + * Constructs a new import operation for reading the manifest + * + * @param fileName + * the output file name + */ + public TracePackageExtractManifestOperation(String fileName) { + super(fileName); + } + + /** + * Run extract the manifest operation. The status (result) of the operation + * can be obtained with {@link #getStatus} + * + * @param progressMonitor + * the progress monitor to use to display progress and receive + * requests for cancellation + */ + @Override + public void run(IProgressMonitor progressMonitor) { + TracePackageElement element = null; + try { + progressMonitor.worked(1); + ArchiveFile archiveFile = getSpecifiedArchiveFile(); + progressMonitor.worked(1); + if (archiveFile == null) { + setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TracePackageExtractManifestOperation_InvalidFormat)); + return; + } + + Enumeration entries = archiveFile.entries(); + + boolean found = false; + while (entries.hasMoreElements()) { + ModalContext.checkCanceled(progressMonitor); + + ArchiveEntry entry = (ArchiveEntry) entries.nextElement(); + IPath p = new Path(entry.getName()); + //Remove project name + p = p.removeFirstSegments(1); + + if (entry.getName().endsWith(ITracePackageConstants.MANIFEST_FILENAME)) { + found = true; + InputStream inputStream = archiveFile.getInputStream(entry); + validateManifest(inputStream); + + inputStream = archiveFile.getInputStream(entry); + element = loadElementsFromManifest(inputStream); + break; + } + + progressMonitor.worked(1); + } + + if (found) { + setStatus(Status.OK_STATUS); + } + else { + setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.TracePackageExtractManifestOperation_ErrorManifestNotFound, ITracePackageConstants.MANIFEST_FILENAME))); + } + + fResultElement = element; + + } catch (InterruptedException e) { + setStatus(Status.CANCEL_STATUS); + } catch (Exception e) { + setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TracePackageExtractManifestOperation_ErrorReadingManifest, e)); + } + } + + /** + * Get the resulting element from extracting the manifest from the archive + * + * @return the resulting element + */ + public TracePackageElement getResultElement() { + return fResultElement; + } + + private static void validateManifest(InputStream xml) throws IOException + { + URL schemaFileUrl = FileLocator.find(Activator.getDefault().getBundle(), new Path(SCHEMA_FOLDER_NAME).append(EXPORT_MANIFEST_SCHEMA_FILE_NAME), null); + if (schemaFileUrl == null) { + throw new IOException(MessageFormat.format(Messages.TracePackageExtractManifestOperation_SchemaFileNotFound, EXPORT_MANIFEST_SCHEMA_FILE_NAME)); + } + + try { + SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); + Schema schema = factory.newSchema(new StreamSource(schemaFileUrl.openStream())); + Validator validator = schema.newValidator(); + validator.validate(new StreamSource(xml)); + } catch (SAXException e) { + throw new IOException(Messages.TracePackageExtractManifestOperation_ErrorManifestNotValid, e); + } catch (IOException e) { + throw new IOException(Messages.TracePackageExtractManifestOperation_ErrorManifestNotValid, e); + } + } + + private static TracePackageElement loadElementsFromManifest(InputStream inputStream) throws IOException, SAXException, ParserConfigurationException { + TracePackageElement element = null; + Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(inputStream); + + NodeList traceElements = doc.getDocumentElement().getElementsByTagName(ITracePackageConstants.TRACE_ELEMENT); + for (int i = 0; i < traceElements.getLength(); ++i) { + Node traceNode = traceElements.item(i); + if (traceNode.getNodeType() == Node.ELEMENT_NODE) { + Element traceElement = (Element) traceNode; + String traceName = traceElement.getAttribute(ITracePackageConstants.TRACE_NAME_ATTRIB); + String traceType = traceElement.getAttribute(ITracePackageConstants.TRACE_TYPE_ATTRIB); + element = new TracePackageTraceElement(null, traceName, traceType); + + List children = new ArrayList(); + NodeList fileElements = traceElement.getElementsByTagName(ITracePackageConstants.TRACE_FILE_ELEMENT); + for (int j = 0; j < fileElements.getLength(); ++j) { + Node fileNode = fileElements.item(j); + if (fileNode.getNodeType() == Node.ELEMENT_NODE) { + Element fileElement = (Element) fileNode; + String fileName = fileElement.getAttribute(ITracePackageConstants.TRACE_FILE_NAME_ATTRIB); + children.add(new TracePackageFilesElement(element, fileName)); + } + } + + TracePackageSupplFilesElement supplFilesElement = new TracePackageSupplFilesElement(element); + + // Supplementary files + List suppFiles = new ArrayList(); + NodeList suppFilesElements = traceElement.getElementsByTagName(ITracePackageConstants.SUPPLEMENTARY_FILE_ELEMENT); + for (int j = 0; j < suppFilesElements.getLength(); ++j) { + Node suppFileNode = suppFilesElements.item(j); + if (suppFileNode.getNodeType() == Node.ELEMENT_NODE) { + Element suppFileElement = (Element) suppFileNode; + String fileName = suppFileElement.getAttribute(ITracePackageConstants.SUPPLEMENTARY_FILE_NAME_ATTRIB); + TracePackageSupplFileElement supplFile = new TracePackageSupplFileElement(fileName, supplFilesElement); + suppFiles.add(supplFile); + } + } + + if (!suppFiles.isEmpty()) { + supplFilesElement.setChildren(suppFiles.toArray(new TracePackageElement[] {})); + children.add(supplFilesElement); + } + + // bookmarks + List> bookmarkAttribs = new ArrayList>(); + NodeList bookmarksElements = traceElement.getElementsByTagName(ITracePackageConstants.BOOKMARKS_ELEMENT); + for (int j = 0; j < bookmarksElements.getLength(); ++j) { + Node bookmarksNode = bookmarksElements.item(j); + if (bookmarksNode.getNodeType() == Node.ELEMENT_NODE) { + NodeList bookmarkElements = traceElement.getElementsByTagName(ITracePackageConstants.BOOKMARK_ELEMENT); + for (int k = 0; k < bookmarkElements.getLength(); ++k) { + Node bookmarkNode = bookmarkElements.item(k); + if (bookmarkNode.getNodeType() == Node.ELEMENT_NODE) { + Element bookmarkElement = (Element) bookmarkNode; + NamedNodeMap attributesMap = bookmarkElement.getAttributes(); + Map attribs = new HashMap(); + for (int l = 0; l < attributesMap.getLength(); ++l) { + Node item = attributesMap.item(l); + attribs.put(item.getNodeName(), item.getNodeValue()); + } + bookmarkAttribs.add(attribs); + } + } + } + } + if (!bookmarkAttribs.isEmpty()) { + children.add(new TracePackageBookmarkElement(element, bookmarkAttribs)); + } + + element.setChildren(children.toArray(new TracePackageElement[] {})); + } + } + return element; + } +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageImportOperation.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageImportOperation.java new file mode 100644 index 0000000000..2717e70a49 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/TracePackageImportOperation.java @@ -0,0 +1,432 @@ +/******************************************************************************* + * Copyright (c) 2013 Ericsson + * + * 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: + * Marc-Andre Laperle - Initial API and implementation + *******************************************************************************/ + +package org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.importexport; + +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.InvocationTargetException; +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.Enumeration; +import java.util.List; +import java.util.Map; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.IResource; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.SubProgressMonitor; +import org.eclipse.jface.operation.ModalContext; +import org.eclipse.linuxtools.internal.tmf.ui.Activator; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.AbstractTracePackageOperation; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement; +import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement; +import org.eclipse.linuxtools.tmf.core.TmfCommonConstants; +import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfNavigatorContentProvider; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder; +import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceType; +import org.eclipse.linuxtools.tmf.ui.project.model.TraceTypeHelper; +import org.eclipse.ui.dialogs.IOverwriteQuery; +import org.eclipse.ui.ide.IDE; +import org.eclipse.ui.internal.wizards.datatransfer.TarException; +import org.eclipse.ui.wizards.datatransfer.IImportStructureProvider; +import org.eclipse.ui.wizards.datatransfer.ImportOperation; + +/** + * An operation that imports a trace package from an archive + * + * @author Marc-Andre Laperle + */ +@SuppressWarnings("restriction") +public class TracePackageImportOperation extends AbstractTracePackageOperation implements IOverwriteQuery { + + private final TracePackageTraceElement fImportTraceElement; + private final TmfTraceFolder fTmfTraceFolder; + + // Result of reading the manifest + private TracePackageElement fResultElement; + + /** + * Constructs a new import operation + * + * @param importTraceElement + * the trace element to be imported + * @param fileName + * the output file name + * @param tmfTraceFolder + * the destination folder + */ + public TracePackageImportOperation(String fileName, TracePackageTraceElement importTraceElement, TmfTraceFolder tmfTraceFolder) { + super(fileName); + fImportTraceElement = importTraceElement; + fTmfTraceFolder = tmfTraceFolder; + } + + private class ImportProvider implements IImportStructureProvider { + + private Exception fException; + + @Override + public List getChildren(Object element) { + return null; + } + + @Override + public InputStream getContents(Object element) { + InputStream inputStream = null; + // We can add throws + try { + inputStream = ((ArchiveProviderElement) element).getContents(); + } catch (IOException e) { + fException = e; + } catch (TarException e) { + fException = e; + } + return inputStream; + } + + @Override + public String getFullPath(Object element) { + return ((ArchiveProviderElement) element).getFullPath(); + } + + @Override + public String getLabel(Object element) { + return ((ArchiveProviderElement) element).getLabel(); + } + + @Override + public boolean isFolder(Object element) { + return ((ArchiveProviderElement) element).isFolder(); + } + + public Exception getException() { + return fException; + } + } + + private class ArchiveProviderElement { + + private final String fPath; + private final String fLabel; + + private ArchiveFile fArchiveFile; + private ArchiveEntry fEntry; + + public ArchiveProviderElement(String destinationPath, String label, ArchiveFile archiveFile, ArchiveEntry entry) { + fPath = destinationPath; + fLabel = label; + this.fArchiveFile = archiveFile; + this.fEntry = entry; + } + + public InputStream getContents() throws TarException, IOException { + return fArchiveFile.getInputStream(fEntry); + } + + public String getFullPath() { + return fPath; + } + + public String getLabel() { + return fLabel; + } + + public boolean isFolder() { + return false; + } + } + + /** + * Run the operation. The status (result) of the operation can be obtained + * with {@link #getStatus} + * + * @param progressMonitor + * the progress monitor to use to display progress and receive + * requests for cancellation + */ + @Override + public void run(IProgressMonitor progressMonitor) { + int totalWork = getNbCheckedElements(new TracePackageElement[] { fImportTraceElement }) * 2; + progressMonitor.beginTask(Messages.TracePackageImportOperation_ImportingPackage, totalWork); + doRun(progressMonitor); + progressMonitor.done(); + } + + private void doRun(IProgressMonitor progressMonitor) { + try { + setStatus(deleteExistingTrace(progressMonitor)); + if (getStatus().getSeverity() != IStatus.OK) { + return; + } + + TracePackageElement[] children = fImportTraceElement.getChildren(); + for (TracePackageElement element : children) { + ModalContext.checkCanceled(progressMonitor); + + if (element instanceof TracePackageFilesElement) { + TracePackageFilesElement traceFilesElement = (TracePackageFilesElement) element; + setStatus(importTraceFiles(progressMonitor, traceFilesElement)); + + } else if (element instanceof TracePackageSupplFilesElement) { + TracePackageSupplFilesElement suppFilesElement = (TracePackageSupplFilesElement) element; + setStatus(importSupplFiles(progressMonitor, suppFilesElement)); + } + + if (getStatus().getSeverity() != IStatus.OK) { + return; + } + } + + String traceName = fImportTraceElement.getText(); + IResource traceRes = fTmfTraceFolder.getResource().findMember(traceName); + if (traceRes == null || !traceRes.exists()) { + setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.ImportTracePackageWizardPage_ErrorFindingImportedTrace, traceName))); + return; + } + + TraceTypeHelper traceType = TmfTraceType.getInstance().getTraceType(fImportTraceElement.getTraceType()); + if (traceType == null) { + setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.ImportTracePackageWizardPage_ErrorSettingTraceType, fImportTraceElement.getTraceType(), traceName))); + return; + } + + try { + TmfTraceType.setTraceType(traceRes.getFullPath(), traceType); + } catch (CoreException e) { + setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.ImportTracePackageWizardPage_ErrorSettingTraceType, fImportTraceElement.getTraceType(), traceName), e)); + } + + importBookmarks(traceRes, progressMonitor); + + } catch (InterruptedException e) { + setStatus(Status.CANCEL_STATUS); + } + } + + private IStatus deleteExistingTrace(IProgressMonitor progressMonitor) { + List traces = fTmfTraceFolder.getTraces(); + TmfTraceElement existingTrace = null; + + for (TmfTraceElement t : traces) { + if (t.getName().equals(fImportTraceElement.getText())) { + existingTrace = t; + break; + } + } + + if (existingTrace != null) { + try { + existingTrace.delete(new SubProgressMonitor(progressMonitor, 1, SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); + } catch (CoreException e) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorOperation, e); + } + } + + return Status.OK_STATUS; + } + + private void importBookmarks(IResource traceRes, IProgressMonitor monitor) { + for (TracePackageElement o : fImportTraceElement.getChildren()) { + if (o instanceof TracePackageBookmarkElement && o.isChecked()) { + + // Get element + IFile bookmarksFile = null; + List traces = fTmfTraceFolder.getTraces(); + for (TmfTraceElement t : traces) { + if (t.getName().equals(traceRes.getName())) { + try { + bookmarksFile = t.createBookmarksFile(); + + // Make sure that if a bookmark is double-clicked first + // before opening the trace, it opens the right editor + + // Get the editor id from the extension point + String traceEditorId = t.getEditorId(); + final String editorId = (traceEditorId != null) ? traceEditorId : TmfEventsEditor.ID; + IDE.setDefaultEditor(bookmarksFile, editorId); + + } catch (CoreException e) { + Activator.getDefault().logError(MessageFormat.format(Messages.TracePackageImportOperation_ErrorCreatingBookmarkFile, traceRes.getName()), e); + } + break; + } + } + + if (bookmarksFile == null) { + break; + } + + TracePackageBookmarkElement bookmarkElement = (TracePackageBookmarkElement) o; + + List> bookmarks = bookmarkElement.getBookmarks(); + for (Map attrs : bookmarks) { + IMarker createMarker = null; + try { + createMarker = bookmarksFile.createMarker(IMarker.BOOKMARK); + } catch (CoreException e) { + Activator.getDefault().logError(MessageFormat.format(Messages.TracePackageImportOperation_ErrorCreatingBookmark, traceRes.getName()), e); + } + if (createMarker != null && createMarker.exists()) { + try { + for (String key : attrs.keySet()) { + String value = attrs.get(key); + if (key.equals(IMarker.LOCATION)) { + createMarker.setAttribute(IMarker.LOCATION, Integer.valueOf(value).intValue()); + } else { + createMarker.setAttribute(key, value); + } + } + } catch (CoreException e) { + Activator.getDefault().logError(MessageFormat.format(Messages.TracePackageImportOperation_ErrorCreatingBookmark, traceRes.getName()), e); + } + } + } + } + } + + monitor.worked(1); + } + + private static boolean fileNameMatches(String fileName, String entryName) { + boolean fileMatch = entryName.equalsIgnoreCase(fileName); + boolean folderMatch = entryName.startsWith(fileName + "/"); //$NON-NLS-1$ + return fileMatch || folderMatch; + } + + private IStatus importTraceFiles(IProgressMonitor monitor, TracePackageFilesElement traceFilesElement) { + List fileNames = new ArrayList(); + IPath prefix = new Path(TmfTraceFolder.TRACE_FOLDER_NAME); + fileNames.add(traceFilesElement.getFileName()); + IPath containerPath = fTmfTraceFolder.getPath(); + IStatus status = importFiles(getSpecifiedArchiveFile(), fileNames, prefix, containerPath, monitor); + if (status.isOK()) { + new TmfNavigatorContentProvider().getChildren(fTmfTraceFolder); + } + return status; + } + + private IStatus importSupplFiles(IProgressMonitor monitor, TracePackageSupplFilesElement suppFilesElement) { + List fileNames = new ArrayList(); + for (TracePackageElement child : suppFilesElement.getChildren()) { + TracePackageSupplFileElement supplFile = (TracePackageSupplFileElement) child; + fileNames.add(supplFile.getText()); + } + + if (!fileNames.isEmpty()) { + List traces = fTmfTraceFolder.getTraces(); + TmfTraceElement traceElement = null; + for (TmfTraceElement t : traces) { + if (t.getName().equals(fImportTraceElement.getText())) { + traceElement = t; + break; + } + } + + if (traceElement != null) { + ArchiveFile archiveFile = getSpecifiedArchiveFile(); + traceElement.refreshSupplementaryFolder(); + String traceName = traceElement.getResource().getName(); + // Project/.tracing/tracename + IPath destinationContainerPath = traceElement.getTraceSupplementaryFolder(traceName).getFullPath(); + // .tracing/tracename + IPath pathInArchive = new Path(TmfCommonConstants.TRACE_SUPPLEMENATARY_FOLDER_NAME).append(traceName); + return importFiles(archiveFile, fileNames, pathInArchive, destinationContainerPath, monitor); + } + } + + return Status.OK_STATUS; + } + + private IStatus importFiles(ArchiveFile archiveFile, List fileNames, IPath pathInArchive, IPath destinationContainerPath, IProgressMonitor monitor) { + List objects = new ArrayList(); + Enumeration entries = archiveFile.entries(); + while (entries.hasMoreElements()) { + ArchiveEntry entry = (ArchiveEntry) entries.nextElement(); + String entryName = entry.getName(); + IPath fullArchivePath = new Path(entryName); + if (fullArchivePath.hasTrailingSeparator()) { + // We only care about file entries as the folders will get created by the ImportOperation + continue; + } + + for (String fileName : fileNames) { + // Check if this archive entry matches the searched file name at this archive location + IPath searchedArchivePath = pathInArchive.append(fileName); + if (fileNameMatches(searchedArchivePath.toString(), entryName)) { + // Traces/kernel/metadata + // kernel/metadata, the ImportOperation will take care of creating the kernel folder + IPath destinationPath = fullArchivePath.removeFirstSegments(pathInArchive.segmentCount()); + // metadata + String resourceLabel = fullArchivePath.lastSegment(); + + ArchiveProviderElement pe = new ArchiveProviderElement(destinationPath.toString(), resourceLabel, archiveFile, entry); + objects.add(pe); + break; + } + } + } + + ImportProvider provider = new ImportProvider(); + + ImportOperation operation = new ImportOperation(destinationContainerPath, + null, provider, this, + objects); + operation.setCreateContainerStructure(true); + operation.setOverwriteResources(true); + + try { + operation.run(new SubProgressMonitor(monitor, fileNames.size(), SubProgressMonitor.PREPEND_MAIN_LABEL_TO_SUBTASK)); + archiveFile.close(); + } catch (InvocationTargetException e) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorOperation, e); + } catch (InterruptedException e) { + return Status.CANCEL_STATUS; + } catch (IOException e) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorOperation, e); + } + + if (provider.getException() != null) { + return new Status(IStatus.ERROR, Activator.PLUGIN_ID, org.eclipse.linuxtools.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorOperation, provider.getException()); + } + + return operation.getStatus(); + } + + @Override + public String queryOverwrite(String pathString) { + // We always overwrite once we reach this point + return null; + } + + /** + * Get the resulting element from extracting the manifest from the archive + * + * @return the resulting element + */ + public TracePackageElement getResultElement() { + return fResultElement; + } + +} diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/messages.properties b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/messages.properties new file mode 100644 index 0000000000..055afc0167 --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/importexport/messages.properties @@ -0,0 +1,52 @@ +############################################################################### +# Copyright (c) 2013 Ericsson +# +# 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: +# Marc-Andre Laperle - Initial API and implementation +############################################################################### + +ExportTracePackageSelectTraceWizardPage_ChooseTrace=Choose a trace to export +ExportTracePackageSelectTraceWizardPage_ProjectSelection=Project +ExportTracePackageSelectTraceWizardPage_TraceSelection=Trace +ExportTracePackageWizardPage_AlreadyExitst = Target file already exists. Would you like to overwrite it? +ExportTracePackageWizardPage_ApproximateSizeLbl=Approximate uncompressed size: {0} +ExportTracePackageWizardPage_ChooseContent=Choose the content to export +ExportTracePackageWizardPage_CompressContents=Co&mpress the contents of the file +ExportTracePackageWizardPage_ContentColumnName=Content +ExportTracePackageWizardPage_Options=Options +ExportTracePackageWizardPage_SaveInTarFormat=Sa&ve in tar format +ExportTracePackageWizardPage_SaveInZipFormat=Save in &zip format +ExportTracePackageWizardPage_SizeByte=B +ExportTracePackageWizardPage_SizeColumnName=Size +ExportTracePackageWizardPage_SizeGigabyte=GB +ExportTracePackageWizardPage_SizeKilobyte=KB +ExportTracePackageWizardPage_SizeMegabyte=MB +ExportTracePackageWizardPage_SizeTerabyte=TB +ExportTracePackageWizardPage_Title=Export trace package +ExportTracePackageWizardPage_ToArchive=To &archive file: +ImportTracePackageWizardPage_AlreadyExists=A trace with the same name already exists. Would you like to overwrite it? +ImportTracePackageWizardPage_ErrorFileNotFound=File does not exist +ImportTracePackageWizardPage_ErrorOperation=Error occurred during import trace operation +ImportTracePackageWizardPage_ErrorSettingTraceType=Error setting the type {0} for the trace {1} +ImportTracePackageWizardPage_ErrorFindingImportedTrace=Could not find the imported trace {0} in the workspace +ImportTracePackageWizardPage_FromArchive=From &archive file: +ImportTracePackageWizardPage_Message=Choose the content to import +ImportTracePackageWizardPage_Project=Into project: +ImportTracePackageWizardPage_ReadingPackage=Reading package +ImportTracePackageWizardPage_SelectProjectButton=Select +ImportTracePackageWizardPage_SelectProjectDialogTitle=Select project +ImportTracePackageWizardPage_Title=Import trace package +TracePackageExportOperation_GeneratingPackage=Generating package +TracePackageExtractManifestOperation_ErrorManifestNotFound=The required manifest file {0} could not be found. +TracePackageExtractManifestOperation_ErrorManifestNotValid=The manifest file is not valid. +TracePackageExtractManifestOperation_ErrorReadingManifest=An error occurred when reading the manifest +TracePackageExtractManifestOperation_InvalidFormat=The selected file is not a supported file format +TracePackageExtractManifestOperation_SchemaFileNotFound=The schema file {0} could not be found. +TracePackageImportOperation_ErrorCreatingBookmark=Error creating bookmark for the trace {0} +TracePackageImportOperation_ErrorCreatingBookmarkFile=Error creating bookmark file for the trace {0} +TracePackageImportOperation_ImportingPackage=Importing package diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/messages.properties b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/messages.properties new file mode 100644 index 0000000000..47ea91587e --- /dev/null +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/tracepkg/messages.properties @@ -0,0 +1,22 @@ +############################################################################### +# Copyright (c) 2013 Ericsson +# +# 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: +# Marc-Andre Laperle - Initial API and implementation +############################################################################### + +TracePackage_Bookmarks=Bookmarks +TracePackage_Browse=B&rowse... +TracePackage_DeselectAll=Deselect All +TracePackage_ErrorOperation=Error occurred during trace package operation +TracePackage_ErrorMultipleProblems=Multiple problems. Click Details for more information. +TracePackage_FileDialogTitle=Choose Archive File +TracePackage_InternalErrorTitle=Internal error +TracePackage_SelectAll=Select All +TracePackage_SupplementaryFiles=Supplementary files +TracePackage_TraceElement=Trace \ No newline at end of file diff --git a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java index 6fea774ca1..60f09c338c 100644 --- a/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java +++ b/org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/tmf/ui/project/model/TmfTraceElement.java @@ -22,6 +22,8 @@ import java.io.ByteArrayInputStream; import java.io.InputStream; import java.util.Arrays; import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; import java.util.Map; import org.eclipse.core.resources.IFile; @@ -29,6 +31,8 @@ import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.Platform; import org.eclipse.linuxtools.internal.tmf.ui.Activator; import org.eclipse.linuxtools.internal.tmf.ui.parsers.custom.CustomTxtEvent; @@ -577,6 +581,46 @@ public class TmfTraceElement extends TmfWithFolderElement implements IActionFilt } } + /** + * Delete the trace resource, remove it from experiments and delete its + * supplementary files + * + * @param progressMonitor + * a progress monitor, or null if progress reporting is not + * desired + * + * @throws CoreException + * thrown when IResource.delete fails + * @since 2.2 + */ + public void delete(IProgressMonitor progressMonitor) throws CoreException { + closeEditors(); + + IPath path = fResource.getLocation(); + if (path != null && (getParent() instanceof TmfTraceFolder)) { + TmfExperimentFolder experimentFolder = getProject().getExperimentsFolder(); + + // Propagate the removal to traces + for (ITmfProjectModelElement experiment : experimentFolder.getChildren()) { + List toRemove = new LinkedList(); + for (ITmfProjectModelElement child : experiment.getChildren()) { + if (child.getName().equals(getName())) { + toRemove.add(child); + } + } + for (ITmfProjectModelElement child : toRemove) { + ((TmfExperimentElement) experiment).removeTrace((TmfTraceElement) child); + } + } + + // Delete supplementary files + deleteSupplementaryFolder(); + } + + // Finally, delete the trace + fResource.delete(true, progressMonitor); + } + /** * Get the instantiated trace associated with this element. * -- 2.34.1