1 | /*
|
---|
2 | * Copyright 2005 Paul Hinds
|
---|
3 | *
|
---|
4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
---|
5 | * you may not use this file except in compliance with the License.
|
---|
6 | * You may obtain a copy of the License at
|
---|
7 | *
|
---|
8 | * http://www.apache.org/licenses/LICENSE-2.0
|
---|
9 | *
|
---|
10 | * Unless required by applicable law or agreed to in writing, software
|
---|
11 | * distributed under the License is distributed on an "AS IS" BASIS,
|
---|
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
---|
13 | * See the License for the specific language governing permissions and
|
---|
14 | * limitations under the License.
|
---|
15 | */
|
---|
16 | package org.tp23.antinstaller.renderer.swing;
|
---|
17 |
|
---|
18 | import javax.swing.JFrame;
|
---|
19 | import javax.swing.JLabel;
|
---|
20 | import javax.swing.SwingUtilities;
|
---|
21 |
|
---|
22 | import org.apache.tools.ant.BuildEvent;
|
---|
23 | import org.tp23.antinstaller.InstallerContext;
|
---|
24 | import org.tp23.antinstaller.runtime.SwingRunner;
|
---|
25 |
|
---|
26 | public class SwingInstallerContext{
|
---|
27 |
|
---|
28 | private static JFrame masterFrame;
|
---|
29 | private JLabel feedBackPanel;
|
---|
30 | private ProgressPanel progressPanel;
|
---|
31 | private InstallerContext ctx;
|
---|
32 |
|
---|
33 | public SwingInstallerContext(InstallerContext ctx,
|
---|
34 | JFrame masterFrame) {
|
---|
35 | this.ctx = ctx;
|
---|
36 | SwingInstallerContext.masterFrame = masterFrame;
|
---|
37 | }
|
---|
38 |
|
---|
39 | public JFrame getMasterFrame() {
|
---|
40 | return masterFrame;
|
---|
41 | }
|
---|
42 | public SwingRunner getSwingRunner() {
|
---|
43 | return (SwingRunner)ctx.getRunner();
|
---|
44 | }
|
---|
45 |
|
---|
46 | public void setFeedBackLabel(JLabel feedBackPanel) {
|
---|
47 | this.feedBackPanel = feedBackPanel;
|
---|
48 | }
|
---|
49 | /**
|
---|
50 | * The progress panel is optional so not calling this method
|
---|
51 | * should not cause errors or NPEs
|
---|
52 | * @param progressPanel
|
---|
53 | */
|
---|
54 | public void setProgressPanel(ProgressPanel progressPanel) {
|
---|
55 | this.progressPanel = progressPanel;
|
---|
56 | }
|
---|
57 |
|
---|
58 | public void buildStarted(BuildEvent buildEvent) {
|
---|
59 | provideAntFeedBack(buildEvent.getMessage());
|
---|
60 | try {
|
---|
61 | SwingUtilities.invokeAndWait(new Runnable(){
|
---|
62 | public void run(){
|
---|
63 | if(SwingInstallerContext.this.progressPanel != null){
|
---|
64 | SwingInstallerContext.this.progressPanel.prepareCalledTargets();
|
---|
65 | }
|
---|
66 | }
|
---|
67 | });
|
---|
68 | } catch (Exception e) { //Interrupted or InvocationTarget
|
---|
69 | SwingInstallerContext.this.ctx.log(e);
|
---|
70 | }
|
---|
71 | }
|
---|
72 |
|
---|
73 | public void buildFinished(BuildEvent buildEvent) {
|
---|
74 | if(this.progressPanel != null){
|
---|
75 | try {
|
---|
76 | SwingUtilities.invokeLater(new Runnable(){
|
---|
77 | public void run(){
|
---|
78 | SwingInstallerContext.this.progressPanel.buildFinished();
|
---|
79 | }
|
---|
80 | });
|
---|
81 | } catch (Exception e) { //Interrupted or InvocationTarget
|
---|
82 | SwingInstallerContext.this.ctx.log(e);
|
---|
83 | }
|
---|
84 | }
|
---|
85 | }
|
---|
86 |
|
---|
87 | public void targetStarted(BuildEvent buildEvent) {
|
---|
88 | TargetStarted targetStarted = new TargetStarted();
|
---|
89 | targetStarted.buildEvent = buildEvent;
|
---|
90 | try {
|
---|
91 | if(this.progressPanel != null){
|
---|
92 | //Invoke and wait used since strict ordering od started and finished is requried
|
---|
93 | SwingUtilities.invokeAndWait(targetStarted);
|
---|
94 | }
|
---|
95 | } catch (Exception e) { //Interrupted or InvocationTarget
|
---|
96 | SwingInstallerContext.this.ctx.log(e);
|
---|
97 | }
|
---|
98 | }
|
---|
99 |
|
---|
100 | public void targetFinished(BuildEvent buildEvent) {
|
---|
101 | try {
|
---|
102 | //Invoke and wait used since strict ordering od started and finished is requried
|
---|
103 | SwingUtilities.invokeAndWait(new Runnable(){
|
---|
104 | public void run(){
|
---|
105 | if(SwingInstallerContext.this.progressPanel != null){
|
---|
106 | SwingInstallerContext.this.progressPanel.targetFinished();
|
---|
107 | }
|
---|
108 | }
|
---|
109 | });
|
---|
110 | } catch (Exception e) { //Interrupted or InvocationTarget
|
---|
111 | SwingInstallerContext.this.ctx.log(e);
|
---|
112 | }
|
---|
113 | }
|
---|
114 |
|
---|
115 | public void provideAntFeedBack(String message){
|
---|
116 | // We should never have Ant running without a ProgressPane
|
---|
117 | // but do an if null here in case future FilterChains are different
|
---|
118 | ProvideAntFeedBack provideAntFeedBack = new ProvideAntFeedBack();
|
---|
119 | provideAntFeedBack.message = message;
|
---|
120 | try {
|
---|
121 | if(feedBackPanel != null){
|
---|
122 | SwingUtilities.invokeLater(provideAntFeedBack);
|
---|
123 | }
|
---|
124 | } catch (Exception e) { //Interrupted or InvocationTarget
|
---|
125 | SwingInstallerContext.this.ctx.log(e);
|
---|
126 | }
|
---|
127 | }
|
---|
128 |
|
---|
129 |
|
---|
130 | /**
|
---|
131 | * @return Returns the ctx.
|
---|
132 | */
|
---|
133 | public InstallerContext getInstallerContext() {
|
---|
134 | return ctx;
|
---|
135 | }
|
---|
136 |
|
---|
137 | private class TargetStarted implements Runnable{
|
---|
138 | private BuildEvent buildEvent;
|
---|
139 | public void run(){
|
---|
140 | SwingInstallerContext.this.progressPanel.targetStarted(buildEvent);
|
---|
141 | }
|
---|
142 | }
|
---|
143 | private class ProvideAntFeedBack implements Runnable{
|
---|
144 | private String message;
|
---|
145 | public void run(){
|
---|
146 | SwingInstallerContext.this.feedBackPanel.setText(message);
|
---|
147 | }
|
---|
148 | }
|
---|
149 | }
|
---|