consulo.module.extension.MutableModuleExtension Java Examples

The following examples show how to use consulo.module.extension.MutableModuleExtension. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ExtensionEditor.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
private void updateSecondComponent(@Nullable MutableModuleExtension extension) {
  JComponent oldComponent;
  if (extension == null || !extension.isEnabled()) {
    oldComponent = mySplitter.replaceSecondComponent(null);
  }
  else {
    oldComponent = mySplitter.replaceSecondComponent(createConfigurationPanel(extension));
  }

  if (oldComponent != null) {
    Disposable disposable = myExtensionDisposables.remove(oldComponent);
    if (disposable != null) {
      Disposer.dispose(disposable);
    }
  }
}
 
Example #2
Source File: SdkComboBox.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@SuppressWarnings("unchecked")
public <T extends MutableModuleExtension<?>> void insertModuleItems(@Nonnull T moduleExtension,
                                                                    @Nonnull NullableFunction<T, MutableModuleInheritableNamedPointer<Sdk>> sdkPointerFunction) {

  for (Module module : ModuleManager.getInstance(moduleExtension.getModule().getProject()).getModules()) {
    // dont add self module
    if (module == moduleExtension.getModule()) {
      continue;
    }

    ModuleExtension extension = ModuleUtilCore.getExtension(module, moduleExtension.getId());
    if (extension == null) {
      continue;
    }
    MutableModuleInheritableNamedPointer<Sdk> sdkPointer = sdkPointerFunction.fun((T)extension);
    if (sdkPointer != null) {
      // recursive depend
      if (sdkPointer.getModule() == moduleExtension.getModule()) {
        continue;
      }
      addItem(new ModuleExtensionSdkComboBoxItem(extension, sdkPointer));
    }
  }
}
 
Example #3
Source File: BundleBox.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@SuppressWarnings("unchecked")
public <T extends MutableModuleExtension<?>> void addModuleExtensionItems(@Nonnull T moduleExtension, @Nonnull Function<T, MutableModuleInheritableNamedPointer<Sdk>> sdkPointerFunction) {
  MutableListModel<BundleBoxItem> listModel = (MutableListModel<BundleBoxItem>)myOriginalComboBox.getListModel();

  for (Module module : ModuleManager.getInstance(moduleExtension.getModule().getProject()).getModules()) {
    // dont add self module
    if (module == moduleExtension.getModule()) {
      continue;
    }

    ModuleExtension extension = ModuleUtilCore.getExtension(module, moduleExtension.getId());
    if (extension == null) {
      continue;
    }
    MutableModuleInheritableNamedPointer<Sdk> sdkPointer = sdkPointerFunction.apply((T)extension);
    if (sdkPointer != null) {
      // recursive depend
      if (sdkPointer.getModule() == moduleExtension.getModule()) {
        continue;
      }

      listModel.add(new ModuleExtensionBundleBoxItem(extension, sdkPointer));
    }
  }
}
 
Example #4
Source File: ExtensionEditor.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
@RequiredUIAccess
@SuppressWarnings("deprecation")
private JComponent createConfigurationPanel(final @Nonnull MutableModuleExtension extension) {
  myConfigurablePanelExtension = extension;
  @RequiredUIAccess Runnable updateOnCheck = () -> extensionChanged(extension);

  Disposable uiDisposable = Disposable.newDisposable("module extension: " + extension.getId());

  JComponent result = null;

  if (extension instanceof SwingMutableModuleExtension) {
    result = ((SwingMutableModuleExtension)extension).createConfigurablePanel(uiDisposable, updateOnCheck);
  }
  else {
    Component component = extension.createConfigurationComponent(uiDisposable, updateOnCheck);

    if (component != null) {
      if (component instanceof Layout) {
        component.removeBorders();

        component.addBorders(BorderStyle.EMPTY, null, 5);
      }

      result = (JComponent)TargetAWT.to(component);
    }
  }

  if (result != null) {
    myExtensionDisposables.put(result, uiDisposable);
  }

  return result;
}
 
Example #5
Source File: ExtensionListenerByLayerListenerInvoker.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Inject
public ExtensionListenerByLayerListenerInvoker(@Nonnull Project project) {
  project.getMessageBus().connect().subscribe(ProjectTopics.MODULE_LAYERS, new ModuleRootLayerListener.Adapter() {
    @Override
    public void currentLayerChanged(@Nonnull final Module module,
                                    @Nonnull final String oldName,
                                    @Nonnull final ModuleRootLayer oldLayer,
                                    @Nonnull final String newName,
                                    @Nonnull final ModuleRootLayer newLayer) {

      final List<Couple<ModuleExtension>> list = new ArrayList<Couple<ModuleExtension>>();
      for (ModuleExtensionProviderEP providerEP : ModuleExtensionProviders.getProviders()) {
        MutableModuleExtension oldExtension = oldLayer.getExtensionWithoutCheck(providerEP.getKey());
        MutableModuleExtension newExtension = newLayer.getExtensionWithoutCheck(providerEP.getKey());

        if(oldExtension == null || newExtension == null) {
          continue;
        }

        if(oldExtension.isModified(newExtension)) {
          list.add(Couple.<ModuleExtension>of(oldExtension, newExtension));
        }
      }

      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          ModuleExtensionChangeListener moduleExtensionChangeListener = project.getMessageBus().syncPublisher(ModuleExtension.CHANGE_TOPIC);

          for (Couple<ModuleExtension> couple : list) {
            moduleExtensionChangeListener.beforeExtensionChanged(couple.getFirst(), couple.getSecond());
          }
        }
      }, ModalityState.NON_MODAL);
    }
  });
}
 
Example #6
Source File: ModuleExtensionSdkBoxBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static <T extends MutableModuleExtension<?>> ModuleExtensionSdkBoxBuilder<T> create(@Nonnull T extension, @Nullable Runnable updater) {
  return new ModuleExtensionSdkBoxBuilder<>(extension).laterUpdater(updater);
}
 
Example #7
Source File: ModuleExtensionBundleBoxBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public static <T extends MutableModuleExtension<?>> ModuleExtensionBundleBoxBuilder<T> create(@Nonnull T extension, @Nonnull Disposable uiDisposable, @Nullable Runnable updater) {
  return new ModuleExtensionBundleBoxBuilder<>(extension).laterUpdater(updater).uiDisposable(uiDisposable);
}
 
Example #8
Source File: ExtensionEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
protected JComponent createComponentImpl() {
  JPanel rootPane = new JPanel(new BorderLayout());

  mySplitter = new OnePixelSplitter();

  myTree = new CheckboxTreeNoPolicy(new ExtensionTreeCellRenderer(), new ExtensionCheckedTreeNode(null, myState, this)) {
    @Override
    protected void adjustParentsAndChildren(CheckedTreeNode node, boolean checked) {
      if (!checked) {
        changeNodeState(node, false);
        checkOrUncheckChildren(node, false);
      }
      else {
        // we need collect parents, and enable it in right order
        // A
        // - B
        // -- C
        // when we enable C, ill be calls like A -> B -> C
        List<CheckedTreeNode> parents = new ArrayList<>();
        TreeNode parent = node.getParent();
        while (parent != null) {
          if (parent instanceof CheckedTreeNode) {
            parents.add((CheckedTreeNode)parent);
          }
          parent = parent.getParent();
        }

        Collections.reverse(parents);
        for (CheckedTreeNode checkedTreeNode : parents) {
          checkNode(checkedTreeNode, true);
        }
        changeNodeState(node, true);
      }
      repaint();
    }
  };

  myTree.setRootVisible(false);
  myTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
  myTree.addTreeSelectionListener(new TreeSelectionListener() {
    @Override
    @RequiredUIAccess
    public void valueChanged(final TreeSelectionEvent e) {
      final List<MutableModuleExtension> selected = TreeUtil.collectSelectedObjectsOfType(myTree, MutableModuleExtension.class);
      updateSecondComponent(ContainerUtil.<MutableModuleExtension>getFirstItem(selected));
    }
  });
  TreeUtil.expandAll(myTree);

  mySplitter.setFirstComponent(myTree);

  rootPane.add(new JBScrollPane(mySplitter), BorderLayout.CENTER);

  return rootPane;
}
 
Example #9
Source File: ExtensionEditor.java    From consulo with Apache License 2.0 4 votes vote down vote up
@RequiredUIAccess
public void extensionChanged(MutableModuleExtension extension) {
  final JComponent secondComponent = myConfigurablePanelExtension != extension ? null : mySplitter.getSecondComponent();
  if (secondComponent == null && extension.isEnabled() || secondComponent != null && !extension.isEnabled()) {
    updateSecondComponent(!extension.isEnabled() ? null : extension);
  }

  if (extension instanceof ModuleExtensionWithSdk) {
    // we using module layer, dont use modifiable model - it ill proxy, and methods 'addModuleExtensionSdkEntry' && 'removeOrderEntry'
    // ill call this method again
    ModifiableModuleRootLayer moduleRootLayer = extension.getModuleRootLayer();

    final ModuleExtensionWithSdkOrderEntry sdkOrderEntry = moduleRootLayer.findModuleExtensionSdkEntry(extension);
    if (!extension.isEnabled() && sdkOrderEntry != null) {
      moduleRootLayer.removeOrderEntry(sdkOrderEntry);
    }

    if (extension.isEnabled()) {
      final ModuleExtensionWithSdk sdkExtension = (ModuleExtensionWithSdk)extension;
      if (!sdkExtension.getInheritableSdk().isNull()) {
        if (sdkOrderEntry == null) {
          moduleRootLayer.addModuleExtensionSdkEntry(sdkExtension);
        }
        else {
          final ModuleExtensionWithSdk<?> moduleExtension = sdkOrderEntry.getModuleExtension();
          if (moduleExtension != null && !Comparing.equal(sdkExtension.getInheritableSdk(), moduleExtension.getInheritableSdk())) {
            moduleRootLayer.addModuleExtensionSdkEntry(sdkExtension);
          }
        }
      }
      else if (sdkOrderEntry != null) {
        moduleRootLayer.removeOrderEntry(sdkOrderEntry);
      }
    }
  }

  for (PsiPackageSupportProvider supportProvider : PsiPackageSupportProvider.EP_NAME.getExtensionList()) {
    final Module module = extension.getModule();
    if (supportProvider.isSupported(extension)) {
      PsiPackageManager.getInstance(module.getProject()).dropCache(extension.getClass());
    }
  }

  myClasspathEditor.moduleStateChanged();
  myContentEntriesEditor.moduleStateChanged();
  myOutputEditor.moduleStateChanged();
}