Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
   *
   * Copyright 2012 Oracle and/or its affiliates. All rights reserved.
   *
   * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
   * Other names may be trademarks of their respective owners.
   *
   * The contents of this file are subject to the terms of either the GNU
  * General Public License Version 2 only ("GPL") or the Common
  * Development and Distribution License("CDDL") (collectively, the
  * "License"). You may not use this file except in compliance with the
  * License. You can obtain a copy of the License at
  * http://www.netbeans.org/cddl-gplv2.html
  * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
  * specific language governing permissions and limitations under the
  * License.  When distributing the software, include this License Header
  * Notice in each file and include the License file at
  * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
  * particular file as subject to the "Classpath" exception as provided
  * by Oracle in the GPL Version 2 section of the License file that
  * accompanied this code. If applicable, add the following below the
  * License Header, with the fields enclosed by brackets [] replaced by
  * your own identifying information:
  * "Portions Copyrighted [year] [name of copyright owner]"
  *
  * If you wish your version of this file to be governed by only the CDDL
  * or only the GPL Version 2, indicate your decision by adding
  * "[Contributor] elects to include this software in this distribution
  * under the [CDDL or GPL Version 2] license." If you do not indicate a
  * single choice of license, a recipient has the option to distribute
  * your version of this file under either the CDDL, the GPL Version 2 or
  * to extend the choice of license to its licensees as provided above.
  * However, if you add GPL Version 2 code and therefore, elected the GPL
  * Version 2 license, then the option applies only if the new code is
  * made subject to such option by the copyright holder.
  *
  * Contributor(s):
  *
  * Portions Copyrighted 2012 Sun Microsystems, Inc.
  */
 package org.netbeans.modules.web.inspect.ui;
 
CSS Styles view.

Author(s):
Jan Stola
 
 public abstract class CssStylesPanelProviderImpl extends JPanel implements CssStylesPanelProvider {
    
Label shown when no styles information is available.
 
     private JLabel noStylesLabel;
    
The latest "related" file, i.e. file provided through the context lookup.
 
     private FileObject lastRelatedFileObject;
    
Page model whose styles view we are showing currently.
 
     private PageModel currentPageModel;
    
Panel shown when no page model is available but when we have some "related" file.
 
     private JPanel runFilePanel;
    
Run button in runFilePanel.
 
     private JButton runButton;
    
Wrapper for the lookup of the current view.
 
     private MatchedRulesLookup lookup;
    
    
Creates a new MatchedRulesTC.
 
     public CssStylesPanelProviderImpl() {
          = new MatchedRulesLookup();
        setLayout(new BorderLayout());
        initNoStylesLabel();
        initRunFilePanel();
        PageInspectorImpl.getDefault().addPropertyChangeListener(createInspectorListener());
        update();
    }
    
        return ;
    }

    
Initializes the "no Styles" label.
    private void initNoStylesLabel() {
         = new JLabel();
        .setText(NbBundle.getMessage(CssStylesPanelProviderImpl.class"CssStylesPanelProviderImpl.noStylesLabel")); // NOI18N
        .setEnabled(false);
        .setOpaque(true);
    }

    
Initializes the "Run File" panel.
    private void initRunFilePanel() {
         = new JPanel();
        JLabel label = new JLabel(NbBundle.getMessage(CssStylesPanelProviderImpl.class"CssStylesPanelProviderImpl.runFileLabel")); // NOI18N
         = new JButton();
            @Override
            public void actionPerformed(ActionEvent e) {
                if ( != null) {
                    ActionProvider provider = actionProviderForFileObject();
                    if (provider != null) {
                        Lookup context = Lookups.singleton();
                        if (provider.isActionEnabled(.context)) {
                            provider.invokeAction(.context);
                        }
                    }
                }
            }
        });
        GroupLayout layout = new GroupLayout();
        .setLayout(layout);
        layout.setVerticalGroup(layout.createSequentialGroup()
            .addComponent(label)
            .addComponent()
        layout.setHorizontalGroup(layout.createSequentialGroup()
            .addContainerGap()
            .addGroup(layout.createParallelGroup()
                .addComponent(label)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0,0,.)
                    .addComponent()
                    .addGap(0,0,.)))
            .addContainerGap());
    }
    private void update() {
        PageModel pageModel = PageInspectorImpl.getDefault().getPage();
        update(pageModel);
    }
    void update(FileObject fob) {
         = fob;
        update();
    }
    private void update(final PageModel pageModel) {
        if (EventQueue.isDispatchThread()) {
            if (pageModel == null) {
                boolean noStylesLabelShown = .getParent() != null;
                boolean runFilePanelShown = .getParent() != null;
                if (( == null) ? !noStylesLabelShown : !runFilePanelShown) {
                    removeAll();
                    if ( == null) {
                        add(.);
                    } else {
                        add(.);
                    }
                }
                if ( != null) {
                    String text = NbBundle.getMessage(
                            CssStylesPanelProviderImpl.class,
                            "CssStylesPanelProviderImpl.runFileButton"// NOI18N
                            .getNameExt());
                    .setText(text);
                    boolean enabled = false;
                    ActionProvider provider = actionProviderForFileObject();
                    if (provider != null) {
                        Lookup context = Lookups.singleton();
                        enabled = provider.isActionEnabled(.context);
                    }
                    .setEnabled(enabled);
                }
            } else if (pageModel != ) {
                removeAll();
                PageModel.CSSStylesView stylesView = pageModel.getCSSStylesView();
                add(stylesView.getView(), .);
            }
             = pageModel;
            .setView( != null ? .getCSSStylesView() : null);
            revalidate();
            repaint();
        } else {
            EventQueue.invokeLater(new Runnable() {
                @Override
                public void run() {
                    update(pageModel);
                }
            });
        }
    }
    
    void activateView() {
        if( != null) {
            .getCSSStylesView().activated();
        }
    }
    
    void deactivateView() {
        if( != null) {
            .getCSSStylesView().deactivated();
        }
    }
    
    
Creates a page inspector listener.

Returns:
page inspector listener.
        return new PropertyChangeListener() {
            @Override
            public void propertyChange(PropertyChangeEvent evt) {
                String propName = evt.getPropertyName();
                if (..equals(propName)) {
                    update();
                }
            }
        };
    }

    
Returns an action provider for the specified FileObject.

Returns:
ActionProvider for the specified FileObject.
    private static ActionProvider actionProviderForFileObject(FileObject fileObject) {
        ActionProvider provider = null;
        Project project = FileOwnerQuery.getOwner(fileObject);
        if (project != null) {
            Lookup lkp = project.getLookup();
            provider = lkp.lookup(ActionProvider.class);
        }
        return provider;
    }
        "CTL_CssStylesProviderImpl.selection.view.title=Selection"
    })
    @ServiceProvider(service = CssStylesPanelProvider.class, position=1000)
    public static class SelectionView extends CssStylesPanelProviderImpl {
        private static String SELECTION_PANEL_ID = "selection"//NOI18N
        private static Collection<StringMIME_TYPES = new HashSet(Arrays.asList(new String[]{"text/html""text/xhtml"}));
        @Override
        public String getPanelID() {
            return ;
        }
        @Override
        public String getPanelDisplayName() {
            return Bundle.CTL_CssStylesProviderImpl_selection_view_title();
        }
        @Override
        public JComponent getContent(Lookup lookup) {
            final Lookup.Result<FileObjectresult = lookup.lookupResult(FileObject.class);
            result.addLookupListener(new LookupListener() {
                @Override
                public void resultChanged(LookupEvent ev) {
                    Collection<? extends FileObjectfobs = result.allInstances();
                    FileObject fob = null;
                    if (!fobs.isEmpty()) {
                        fob = fobs.iterator().next();
                    }
                    update(fob);
                }
            });
            return this;
        }
        @Override
        public Lookup getLookup() {
            return getMatchedRulesLookup();
        }
        @Override
        public void activated() {
            activateView();
        }
        @Override
        public void deactivated() {
            deactivateView();
        }
        @Override
        public boolean providesContentFor(FileObject file) {
            if(!.contains(file.getMIMEType())) {
                return false;
            }
            ActionProvider provider = actionProviderForFileObject(file);
            if (provider == null) {
                return false;
            }
            Lookup context = Lookups.singleton(file);
            return provider.isActionEnabled(.context);
        }
    }
    
    
Wrapper for the lookup of the current view.
    static class MatchedRulesLookup extends ProxyLookup {

        
Sets the current view.

Parameters:
view current view.
        void setView(PageModel.CSSStylesView view) {
            if (view == null) {
                setLookups();
            } else {
                setLookups(view.getLookup());
            }
        }
    }