2 * Copyright 2000-2009 JetBrains s.r.o.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org
.jetbrains
.idea
.maven
.utils
;
18 import com
.intellij
.openapi
.progress
.EmptyProgressIndicator
;
19 import com
.intellij
.openapi
.progress
.ProcessCanceledException
;
20 import com
.intellij
.openapi
.progress
.ProgressIndicator
;
21 import com
.intellij
.openapi
.util
.Condition
;
23 import java
.util
.ArrayList
;
24 import java
.util
.List
;
26 public class MavenProgressIndicator
{
27 private ProgressIndicator myIndicator
;
28 private List
<Condition
<MavenProgressIndicator
>> myCancelConditions
= new ArrayList
<Condition
<MavenProgressIndicator
>>();
30 public MavenProgressIndicator() {
31 this(new EmptyProgressIndicator());
34 public MavenProgressIndicator(ProgressIndicator i
) {
38 public synchronized void setIndicator(ProgressIndicator i
) {
39 i
.setText(myIndicator
.getText());
40 i
.setText2(myIndicator
.getText2());
41 i
.setFraction(myIndicator
.getFraction());
42 if (i
.isCanceled()) i
.cancel();
46 public synchronized ProgressIndicator
getIndicator() {
50 public synchronized void setText(String text
) {
51 myIndicator
.setText(text
);
54 public synchronized void setText2(String text
) {
55 myIndicator
.setText2(text
);
58 public synchronized void setFraction(double fraction
) {
59 myIndicator
.setFraction(fraction
);
62 public synchronized void cancel() {
66 public synchronized void addCancelCondition(Condition
<MavenProgressIndicator
> condition
) {
67 myCancelConditions
.add(condition
);
70 public synchronized void removeCancelCondition(Condition
<MavenProgressIndicator
> condition
) {
71 myCancelConditions
.remove(condition
);
74 public synchronized boolean isCanceled() {
75 if (myIndicator
.isCanceled()) return true;
76 for (Condition
<MavenProgressIndicator
> each
: myCancelConditions
) {
77 if (each
.value(this)) return true;
82 public void checkCanceled() throws MavenProcessCanceledException
{
83 if (isCanceled()) throw new MavenProcessCanceledException();
86 public void checkCanceledNative() {
87 if (isCanceled()) throw new ProcessCanceledException();