public static synchronized JContextTree getContextTree() {
    if (tree == null) {
      final JContextTree tree = new JContextTree();

      // search available popup menu items
      Lookup lk = Lookups.forPath("/Puzzle/ContextTree/Actions");
      for (TreePopupItem item : lk.lookupAll(TreePopupItem.class)) {
        tree.controls().add(item);
      }

      final List<PropertyPane> configPanes = new ArrayList<PropertyPane>();

      JPropertyTree propertyTree = new JPropertyTree();

      DefaultMutableTreeNode root = new DefaultMutableTreeNode();

      // search available property panels
      lk = Lookups.forPath("/Puzzle/ContextTree/PropertyPanels");
      for (PropertyPane p : lk.lookupAll(PropertyPane.class)) {
        root.add(new DefaultMutableTreeNode(p));
      }

      // search filter panels
      DefaultMutableTreeNode filterNodes =
          new DefaultMutableTreeNode(CoreResource.getString("filter"));
      lk = Lookups.forPath("/Puzzle/ContextTree/FilterPanels");
      for (PropertyPane p : lk.lookupAll(PropertyPane.class)) {
        filterNodes.add(new DefaultMutableTreeNode(p));
      }
      root.add(filterNodes);

      // search style panels
      DefaultMutableTreeNode styleNodes =
          new DefaultMutableTreeNode(CoreResource.getString("symbology"));
      lk = Lookups.forPath("/Puzzle/ContextTree/StylePanels");
      for (PropertyPane p : lk.lookupAll(PropertyPane.class)) {
        styleNodes.add(new DefaultMutableTreeNode(p));
      }
      root.add(styleNodes);

      if (!tree.controls().isEmpty()) {
        tree.controls().add(new SeparatorItem());
      }

      LayerPropertyItem property = new LayerPropertyItem(root);
      tree.controls().add(property);

      tree.revalidate();
      tree.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
      ContextTreeTopComponent.tree = tree;
    }
    return tree;
  }
 @Override
 public void doDelete(final Lookup lookup) {
   Collection<? extends Node> nodes = lookup.lookupAll(Node.class);
   FileObject[] fobs = new FileObject[nodes.size()];
   int i = 0;
   for (Node node : nodes) {
     DataObject dob = (DataObject) node.getCookie(DataObject.class);
     if (dob != null) {
       fobs[i++] = dob.getPrimaryFile();
     }
   }
   UI.openRefactoringUI(new SafeDeleteUI(fobs));
 }
  @Override
  public Action createContextAwareInstance(Lookup actionContext) {
    if (!ProfilingPointsManager.getDefault().isProfilingSessionInProgress()) {
      Collection<? extends CodeProfilingPoint.Annotation> anns =
          actionContext.lookupAll(CodeProfilingPoint.Annotation.class);
      if (anns.size() == 1) {
        CodeProfilingPoint pp = anns.iterator().next().profilingPoint();

        action.setProfilingPoint(pp);
        action.setBooleanState(pp.isEnabled());
        return action;
      }
    }
    return this;
  }
  private Lookup getDefaultLookup() {
    // The Lookup is not created in the constructor, so that we do not need
    // to share "this" in the constructor.
    Lookup result = defaultLookupRef.get();
    if (result == null) {
      GradleAuxiliaryConfiguration auxConfig = new GradleAuxiliaryConfiguration(this);

      Lookup newLookup =
          Lookups.fixed(
              new Object[] {
                this,
                state, // allow outside code to mark the project as needing saving
                NbGradleSingleProjectConfigProvider.create(this),
                new GradleProjectInformation(this),
                new GradleProjectLogicalViewProvider(this),
                new GradleActionProvider(this),
                new GradleSharabilityQuery(this),
                new GradleSourceEncodingQuery(this),
                new GradleCustomizer(this),
                new OpenHook(),
                auxConfig,
                new GradleAuxiliaryProperties(auxConfig),
                new GradleTemplateAttrProvider(this),
                new DefaultGradleCommandExecutor(this),
                ProjectPropertiesApi.buildPlatform(getProperties().getPlatform()),
                ProjectPropertiesApi.scriptPlatform(getProperties().getScriptPlatform()),
                ProjectPropertiesApi.sourceEncoding(getProperties().getSourceEncoding()),
                ProjectPropertiesApi.sourceLevel(getProperties().getSourceLevel()),
                new ProjectInfoManager(),

                // FileOwnerQueryImplementation cannot be added to the project's
                // lookup, since NetBeans will ignore it. It must be added
                // using the ServiceProviders annotation. Our implementation is
                // GradleFileOwnerQuery and is added using the annotation.
              });

      if (defaultLookupRef.compareAndSet(null, newLookup)) {
        for (ProjectInitListener listener : newLookup.lookupAll(ProjectInitListener.class)) {
          listener.onInitProject();
        }

        loadProject(true, true);
      }
      result = defaultLookupRef.get();
    }
    return result;
  }
  private Map<Category, JPanel> lookupCategoriesPanels(
      final Properties properties, final List<Category> categories) {
    final Map<Category, JPanel> result = new HashMap<Category, JPanel>();

    final Map<PropertiesPanelProvider, Category> categoriesMap =
        new TreeMap<PropertiesPanelProvider, Category>(
            new Comparator<PropertiesPanelProvider>() {

              @Override
              public int compare(
                  final PropertiesPanelProvider panel1, final PropertiesPanelProvider panel2) {
                final int priority1 = panel1.getPriority();
                final int priority2 = panel2.getPriority();

                if (priority1 == priority2) {
                  return panel1.getDisplayName().compareTo(panel2.getDisplayName());
                }

                return priority2 - priority1;
              }
            });

    final Lookup lkp = Lookup.getDefault();
    for (final PropertiesPanelProvider propPanelProvider :
        lkp.lookupAll(PropertiesPanelProvider.class)) {
      final Category category =
          Category.create(propPanelProvider.getName(), propPanelProvider.getDisplayName(), null);

      final String moduleName = propPanelProvider.getName();
      final AbstractPropertiesPanel panel =
          propPanelProvider.getPanel(new ModuleProperties(moduleName, properties));
      panel.load();

      result.put(category, panel);
      categoriesMap.put(propPanelProvider, category);
    }

    categories.addAll(categoriesMap.values());

    return result;
  }
 public final @Override Action createContextAwareInstance(Lookup actionContext) {
   Collection<? extends Project> projects = actionContext.lookupAll(Project.class);
   if (projects.size() != 1) {
     return this;
   }
   Project prj = projects.iterator().next().getLookup().lookup(Project.class);
   if (prj == null) {
     return this;
   }
   J2eeModuleProvider prov = prj.getLookup().lookup(J2eeModuleProvider.class);
   if (prov == null) {
     return this;
   }
   NbMavenProject mProj = prj.getLookup().lookup(NbMavenProject.class);
   if (mProj == null) {
     return this;
   }
   if (!prov.hasVerifierSupport()) {
     return this;
   }
   return new VerifyAction(prj, mProj, prov);
 }
  /** Initialization method. Creates appropriate labels in the panel. */
  public void initialize() {
    // This is needed since the checkBox is gets disabled on a
    // repeated invocation of SafeDelete follwing removal of references
    // to the element
    searchInComments.setEnabled(true);

    if (initialized) {
      return;
    }

    final String labelText;

    Lookup lkp = refactoring.getRefactoringSource();
    NonRecursiveFolder folder = lkp.lookup(NonRecursiveFolder.class);
    Collection<? extends FileObject> files = lkp.lookupAll(FileObject.class);
    final Collection<? extends ElementDef> defs = lkp.lookupAll(ElementDef.class);
    if (folder != null) {
      String pkgName = folder.getFolder().getNameExt().replace('/', '.');
      labelText = NbBundle.getMessage(SafeDeletePanel.class, "LBL_SafeDelPkg", pkgName);
    } else if (files.size() > 1 && files.size() == defs.size()) {
      // delete multiple files
      if (regulardelete) {
        labelText =
            NbBundle.getMessage(SafeDeletePanel.class, "LBL_SafeDel_RegularDelete", defs.size());
      } else {
        labelText = NbBundle.getMessage(SafeDeletePanel.class, "LBL_SafeDel_Classes", defs.size());
      }
    } else if (defs.size() > 1) {
      labelText = NbBundle.getMessage(SafeDeletePanel.class, "LBL_SafeDel_Classes", defs.size());
    } else if (defs.size() == 1) {
      ElementDef edef = defs.iterator().next();
      if (regulardelete) {
        labelText =
            NbBundle.getMessage(
                SafeDeletePanel.class, "LBL_SafeDel_RegularDeleteElement", edef.getName());
      } else {
        labelText =
            NbBundle.getMessage(SafeDeletePanel.class, "LBL_SafeDel_Element", edef.getName());
      }
    } else {
      FileObject fileObject = files.iterator().next();
      boolean isSingleFolderSelected =
          (files != null && files.size() == 1 && fileObject.isFolder());
      if (isSingleFolderSelected && !regulardelete) {
        String folderName = fileObject.getName();
        labelText = NbBundle.getMessage(SafeDeletePanel.class, "LBL_SafeDelFolder", folderName);
      } else {
        labelText = ""; // NOI18N
      }
    }

    SwingUtilities.invokeLater(
        new Runnable() {

          public void run() {
            if (regulardelete) {
              safeDelete = new JCheckBox();
              Mnemonics.setLocalizedText(
                  safeDelete, NbBundle.getMessage(SafeDeletePanel.class, "LBL_SafeDelCheckBox"));
              safeDelete
                  .getAccessibleContext()
                  .setAccessibleDescription(
                      NbBundle.getMessage(
                          SafeDeletePanel.class,
                          "SafeDeletePanel.safeDelete.AccessibleContext.accessibleDescription")); // NOI18N
              safeDelete.setMargin(new java.awt.Insets(2, 14, 2, 2));
              searchInComments.setEnabled(false);
              safeDelete.addItemListener(
                  new ItemListener() {

                    public void itemStateChanged(ItemEvent evt) {
                      searchInComments.setEnabled(safeDelete.isSelected());
                      parent.stateChanged(null);
                    }
                  });

              checkBoxes.add(safeDelete, BorderLayout.CENTER);
            }
            label.setText(labelText);
            validate();
          }
        });
    initialized = true;
  }