/* 
 * Copyright 2014 markiewb.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package de.markiewb.netbeans.plugin.git.showbranch;

import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import org.netbeans.libs.git.GitBranch;
import org.openide.filesystems.FileObject;
import org.openide.modules.ModuleInstall;
import org.openide.util.RequestProcessor;
import org.openide.windows.TopComponent;
import org.openide.windows.WindowManager;

public class Installer extends ModuleInstall implements PropertyChangeListener {

    RequestProcessor requestProcessor = new RequestProcessor(Installer.class);

    @Override
    public void restored() {
        final PropertyChangeListener listenerA = this;
        WindowManager.getDefault().invokeWhenUIReady(new Runnable() {
            @Override
            public void run() {
                // code to be invoked when system UI is ready
                TopComponent.getRegistry().addPropertyChangeListener(listenerA);
            }
        });
    }

    @Override
    public void uninstalled() {
        TopComponent.getRegistry().removePropertyChangeListener(this);
    }

    @Override
    public void propertyChange(PropertyChangeEvent evt) {
        //run inside EDT, because we are using WindowManager inside
        final FileObject path = new PathUtils().getPath();
        //run the lenghty GIT processing outside EDT
        requestProcessor.execute(new Runnable() {
            @Override
            public void run() {
                final GitBranch activeBranch = GitUtils.getActiveBranch(path);
                if (null != activeBranch) {
                    BranchStatusLineElement.jLabel.setText(activeBranch.getName());
                } else {
                    BranchStatusLineElement.jLabel.setText("");
                }
            }
        });

    }

}

@@ -1290,83 +1290,15 @@
 ady(
-new Runnable() %7B%0A            @Override%0A            public void run() %7B%0A    
+() -%3E %0A
     
@@ -1351,20 +1351,16 @@
 s ready%0A
-    
         
@@ -1430,33 +1430,8 @@
 erA)
-;%0A            %7D%0A        %7D
 );%0A 
@@ -1849,76 +1849,13 @@
 ute(
-new Runnable() %7B%0A            @Override%0A            public void run()
+() -%3E
  %7B%0A 
@@ -1861,28 +1861,24 @@
             
-  
-  
 final GitBra
@@ -1940,20 +1940,16 @@
         
-    
 if (null
@@ -1976,36 +1976,32 @@
                 
- 
-   
 BranchStatusLine
@@ -2045,23 +2045,24 @@
 etName()
-);%0A    
+ +%22 %22);%0A
         
@@ -2074,20 +2074,16 @@
  else %7B%0A
-    
         
@@ -2138,26 +2138,8 @@
 %22);%0A
-                %7D%0A
     

add single whitespace at the end of branch name (cosmetic)