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.
17 package com
.intellij
.util
.xml
.ui
;
19 import com
.intellij
.ui
.UserActivityListener
;
20 import com
.intellij
.util
.Alarm
;
21 import com
.intellij
.openapi
.Disposable
;
22 import com
.intellij
.openapi
.components
.ServiceManager
;
23 import com
.intellij
.openapi
.project
.Project
;
24 import com
.intellij
.openapi
.progress
.ProgressManager
;
25 import com
.intellij
.openapi
.progress
.ProgressIndicator
;
28 * User: Sergey.Vasiliev
30 public class CommitablePanelUserActivityListener
implements UserActivityListener
, Disposable
{
31 private final Committable myPanel
;
32 private final Project myProject
;
33 private final Alarm myAlarm
= new Alarm();
34 private boolean myApplying
;
36 public CommitablePanelUserActivityListener(Project project
) {
40 public CommitablePanelUserActivityListener(final Committable panel
, Project project
) {
45 final public void stateChanged() {
46 if (myApplying
) return;
49 myAlarm
.addRequest(new Runnable() {
63 private static void cancel() {
64 final ProgressIndicator indicator
= ProgressManager
.getInstance().getProgressIndicator();
65 if (indicator
!= null) {
70 protected void applyChanges() {
71 if (myPanel
!= null) {
76 protected final void commit(final Committable panel
) {
77 ServiceManager
.getService(getProject(), CommittableUtil
.class).commit(panel
);
80 protected final Project
getProject() {
84 public final boolean isWaiting() {
85 return myAlarm
.getActiveRequestCount() > 0;
88 public final void cancelAllRequests() {
89 myAlarm
.cancelAllRequests();
92 public void dispose() {