public void testEditJUnitConfiguration() throws ConfigurationException {
    if (PlatformTestUtil.COVERAGE_ENABLED_BUILD) return;

    PsiClass testA = findTestA(getModule2());
    JUnitConfiguration configuration = createConfiguration(testA);
    JUnitConfigurable editor = new JUnitConfigurable(myProject);
    try {
      Configurable configurable = new RunConfigurationConfigurableAdapter(editor, configuration);
      configurable.reset();
      final EditorTextFieldWithBrowseButton component =
          ((LabeledComponent<EditorTextFieldWithBrowseButton>)
                  editor.getTestLocation(JUnitConfigurationModel.CLASS))
              .getComponent();
      assertEquals(testA.getQualifiedName(), component.getText());
      PsiClass otherTest = findClass(getModule2(), "test2.Test2");
      component.setText(otherTest.getQualifiedName());
      configurable.apply();
      assertEquals(otherTest.getName(), configuration.getName());
      String specialName = "My name";
      configuration.setName(specialName);
      configuration.setNameChangedByUser(true);
      configurable.reset();
      component.setText(testA.getQualifiedName());
      configurable.apply();
      assertEquals(specialName, configuration.getName());
    } finally {
      Disposer.dispose(editor);
    }
  }
Ejemplo n.º 2
0
  @Override
  public void disposeUIResources() {
    if (!myUiInitialized) return;
    final PropertiesComponent propertiesComponent = PropertiesComponent.getInstance(myProject);
    propertiesComponent.setValue("project.structure.last.edited", myUiState.lastEditedConfigurable);
    propertiesComponent.setValue(
        "project.structure.proportion", String.valueOf(myUiState.proportion));
    propertiesComponent.setValue(
        "project.structure.side.proportion", String.valueOf(myUiState.sideProportion));

    myWasUiDisposed = true;

    myUiState.proportion = mySplitter.getProportion();
    saveSideProportion();
    myContext.getDaemonAnalyzer().stop();
    for (Configurable each : myName2Config) {
      each.disposeUIResources();
    }
    myContext.clear();
    myName2Config.clear();

    myModuleConfigurator.getFacetsConfigurator().clearMaps();

    Disposer.dispose(myErrorsComponent);

    myUiInitialized = false;
  }
Ejemplo n.º 3
0
  private void createEditors(@Nullable Module module) {
    if (module == null) return;

    ModuleConfigurationState state = createModuleConfigurationState();
    for (ModuleConfigurationEditorProvider provider : collectProviders(module)) {
      ModuleConfigurationEditor[] editors = provider.createEditors(state);
      if (editors.length > 0
          && provider instanceof ModuleConfigurationEditorProviderEx
          && ((ModuleConfigurationEditorProviderEx) provider).isCompleteEditorSet()) {
        myEditors.clear();
        ContainerUtil.addAll(myEditors, editors);
        break;
      } else {
        ContainerUtil.addAll(myEditors, editors);
      }
    }

    for (Configurable moduleConfigurable : ServiceKt.getComponents(module, Configurable.class)) {
      reportDeprecatedModuleEditor(moduleConfigurable.getClass());
      myEditors.add(new ModuleConfigurableWrapper(moduleConfigurable));
    }
    for (ModuleConfigurableEP extension : module.getExtensions(MODULE_CONFIGURABLES)) {
      if (extension.canCreateConfigurable()) {
        Configurable configurable = extension.createConfigurable();
        if (configurable != null) {
          reportDeprecatedModuleEditor(configurable.getClass());
          myEditors.add(new ModuleConfigurableWrapper(configurable));
        }
      }
    }
  }
Ejemplo n.º 4
0
  @Override
  public boolean isModified() {
    for (Configurable each : myName2Config) {
      if (each.isModified()) return true;
    }

    return false;
  }
 @NotNull
 protected Action[] createActions() {
   for (Configurable conf : myEnvToConfMap.values()) {
     if (conf.getHelpTopic() != null) {
       return new Action[] {getOKAction(), getCancelAction(), getHelpAction()};
     }
   }
   return super.createActions();
 }
Ejemplo n.º 6
0
 protected void createConfigurableTabs() {
   for (Configurable configurable : getConfigurables()) {
     myTabbedPane.addTab(
         configurable.getDisplayName(),
         configurable.getIcon(),
         configurable.createComponent(),
         null);
   }
 }
Ejemplo n.º 7
0
 public boolean isModified() {
   if (!Comparing.equal(mySelectedCompiler, myCompilerConfiguration.getDefaultCompiler())) {
     return true;
   }
   for (Configurable configurable : myConfigurables) {
     if (configurable.isModified()) {
       return true;
     }
   }
   return false;
 }
  private void saveCurrentConfigurable() {
    final Configurable current = myEditor.getContext().getCurrentConfigurable();
    if (current == null) return;

    final PropertiesComponent props = PropertiesComponent.getInstance(myProject);

    if (current instanceof SearchableConfigurable) {
      props.setValue(LAST_SELECTED_CONFIGURABLE, ((SearchableConfigurable) current).getId());
    } else {
      props.setValue(LAST_SELECTED_CONFIGURABLE, current.getClass().getName());
    }
  }
 protected void doOKAction() {
   for (Configurable configurable : myEnvToConfMap.values()) {
     try {
       configurable.apply();
     } catch (CancelledConfigurationException e) {
       return;
     } catch (ConfigurationException e) {
       Messages.showErrorDialog(
           myProject,
           VcsBundle.message("messge.text.cannot.save.settings", e.getLocalizedMessage()),
           getRealTitle());
       return;
     }
   }
   super.doOKAction();
 }
 @Nls
 @Override
 public String getDisplayName() {
   if (myEp.displayName == null && myEp.key == null) {
     boolean loaded = myConfigurable != null;
     Configurable configurable = cast(Configurable.class, this);
     if (configurable != null) {
       String name = configurable.getDisplayName();
       if (!loaded && LOG.isDebugEnabled()) {
         LOG.debug("XML does not provide displayName for " + configurable.getClass());
       }
       return name;
     }
   }
   return myEp.getDisplayName();
 }
Ejemplo n.º 11
0
  private void addConfigurable(Configurable configurable, boolean addToSidePanel) {
    myName2Config.add(configurable);

    if (addToSidePanel) {
      mySidePanel.addPlace(
          createPlaceFor(configurable), new Presentation(configurable.getDisplayName()));
    }
  }
Ejemplo n.º 12
0
 private void editColorsAndFonts() {
   final String toConfigure = getSelectedType().getSeverity(null).myName;
   doOKAction();
   myOptionsList.clearSelection();
   final DataContext dataContext = DataManager.getInstance().getDataContext(myPanel);
   final OptionsEditor optionsEditor = OptionsEditor.KEY.getData(dataContext);
   if (optionsEditor != null) {
     final ColorAndFontOptions colorAndFontOptions =
         optionsEditor.findConfigurable(ColorAndFontOptions.class);
     assert colorAndFontOptions != null;
     final SearchableConfigurable javaPage =
         colorAndFontOptions.findSubConfigurable(InspectionColorSettingsPage.class);
     LOG.assertTrue(javaPage != null);
     optionsEditor
         .clearSearchAndSelect(javaPage)
         .doWhenDone(
             new Runnable() {
               @Override
               public void run() {
                 final Runnable runnable = javaPage.enableSearch(toConfigure);
                 if (runnable != null) {
                   SwingUtilities.invokeLater(runnable);
                 }
               }
             });
   } else {
     ColorAndFontOptions colorAndFontOptions = new ColorAndFontOptions();
     final Configurable[] configurables = colorAndFontOptions.buildConfigurables();
     try {
       final SearchableConfigurable javaPage =
           colorAndFontOptions.findSubConfigurable(InspectionColorSettingsPage.class);
       LOG.assertTrue(javaPage != null);
       ShowSettingsUtil.getInstance()
           .editConfigurable(CommonDataKeys.PROJECT.getData(dataContext), javaPage);
     } finally {
       for (Configurable configurable : configurables) {
         configurable.disposeUIResources();
       }
       colorAndFontOptions.disposeUIResources();
     }
   }
 }
Ejemplo n.º 13
0
  @Override
  public void reset() {
    // need this to ensure VFS operations will not block because of storage flushing
    // and other maintenance IO tasks run in background
    HeavyProcessLatch.INSTANCE.processStarted();

    try {
      myWasUiDisposed = false;

      myContext.reset();

      myProjectJdksModel.reset(myProject);

      Configurable toSelect = null;
      for (Configurable each : myName2Config) {
        if (myUiState.lastEditedConfigurable != null
            && myUiState.lastEditedConfigurable.equals(each.getDisplayName())) {
          toSelect = each;
        }
        if (each instanceof MasterDetailsComponent) {
          ((MasterDetailsComponent) each).setHistory(myHistory);
        }
        each.reset();
      }

      myHistory.clear();

      if (toSelect == null && myName2Config.size() > 0) {
        toSelect = myName2Config.iterator().next();
      }

      removeSelected();

      navigateTo(toSelect != null ? createPlaceFor(toSelect) : null, false);

      if (myUiState.proportion > 0) {
        mySplitter.setProportion(myUiState.proportion);
      }
    } finally {
      HeavyProcessLatch.INSTANCE.processFinished();
    }
  }
 static void warn(Configurable configurable, String action, long time) {
   if (ApplicationManager.getApplication().isDispatchThread()) {
     time = System.currentTimeMillis() - time;
     int threshold = Registry.intValue("ide.settings.configurable.loading.threshold", 0);
     if (0 < threshold && threshold < time) {
       String name = configurable.getDisplayName();
       String id = ConfigurableVisitor.ByID.getID(configurable);
       LOG.warn(String.valueOf(time) + " ms to " + action + " '" + name + "' id=" + id);
     }
   }
 }
 public static void reset(Configurable configurable) {
   if (configurable != null) {
     long time = System.currentTimeMillis();
     try {
       configurable.reset();
     } catch (Exception unexpected) {
       LOG.error("cannot reset configurable", unexpected);
     } finally {
       warn(configurable, "reset", time);
     }
   }
 }
Ejemplo n.º 16
0
  @Override
  public void apply() throws ConfigurationException {
    for (Configurable each : myName2Config) {
      if (each instanceof BaseStructureConfigurable && each.isModified()) {
        ((BaseStructureConfigurable) each).checkCanApply();
      }
    }
    for (Configurable each : myName2Config) {
      if (each.isModified()) {
        each.apply();
      }
    }

    myContext.getDaemonAnalyzer().clearCaches();
    SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            BuildManager.getInstance().scheduleAutoMake();
          }
        });
  }
Ejemplo n.º 17
0
  public JavaCompilersTab(
      final Project project,
      Collection<BackendCompiler> compilers,
      BackendCompiler defaultCompiler) {
    myDefaultCompiler = defaultCompiler;
    myCompilerConfiguration =
        (CompilerConfigurationImpl) CompilerConfiguration.getInstance(project);
    myConfigurables = new ArrayList<Configurable>(compilers.size());

    myCardLayout = new CardLayout();
    myContentPanel.setLayout(myCardLayout);

    for (BackendCompiler compiler : compilers) {
      Configurable configurable = compiler.createConfigurable();
      myConfigurables.add(configurable);

      myContentPanel.add(configurable.createComponent(), compiler.getId());
    }
    myCompiler.setModel(new DefaultComboBoxModel(new Vector(compilers)));
    myCompiler.setRenderer(
        new DefaultListCellRenderer() {
          public Component getListCellRendererComponent(
              JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
            JLabel component =
                (JLabel)
                    super.getListCellRendererComponent(
                        list, value, index, isSelected, cellHasFocus);
            component.setText(((BackendCompiler) value).getPresentableName());
            return component;
          }
        });
    myCompiler.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            BackendCompiler compiler = (BackendCompiler) myCompiler.getSelectedItem();
            if (compiler == null) return;
            selectCompiler(compiler);
          }
        });
  }
  public void testModulesSelector() throws ConfigurationException {
    if (PlatformTestUtil.COVERAGE_ENABLED_BUILD) return;

    Module module1 = getModule1();
    Module module2 = getModule2();
    JUnitConfigurable editor = new JUnitConfigurable(myProject);
    try {
      JUnitConfiguration configuration = createConfiguration(findTestA(module2));
      editor.getComponent(); // To get all the watchers installed.
      Configurable configurable = new RunConfigurationConfigurableAdapter(editor, configuration);
      JComboBox comboBox = editor.getModulesComponent();
      configurable.reset();
      assertFalse(configurable.isModified());
      assertEquals(module2.getName(), ((Module) comboBox.getSelectedItem()).getName());
      assertEquals(
          ModuleManager.getInstance(myProject).getModules().length + 1,
          comboBox.getModel().getSize()); // no module
      comboBox.setSelectedItem(module1);
      assertTrue(configurable.isModified());
      configurable.apply();
      assertFalse(configurable.isModified());
      assertEquals(
          Collections.singleton(module1), ContainerUtilRt.newHashSet(configuration.getModules()));
    } finally {
      Disposer.dispose(editor);
    }
  }
 @Override
 protected void dispose(Configurable configurable) {
   if (configurable != null) {
     long time = System.currentTimeMillis();
     try {
       configurable.disposeUIResources();
     } catch (Exception unexpected) {
       LOG.error("cannot dispose configurable", unexpected);
     } finally {
       warn(configurable, "dispose", time);
     }
   }
 }
  public void testCreatingApplicationConfiguration() throws ConfigurationException {
    if (PlatformTestUtil.COVERAGE_ENABLED_BUILD) return;

    ApplicationConfiguration configuration =
        new ApplicationConfiguration(null, myProject, ApplicationConfigurationType.getInstance());
    ApplicationConfigurable editor = new ApplicationConfigurable(myProject);
    try {
      editor.getComponent(); // To get all the watchers installed.
      Configurable configurable = new RunConfigurationConfigurableAdapter(editor, configuration);
      configurable.reset();
      CommonJavaParametersPanel javaParameters = editor.getCommonProgramParameters();
      javaParameters.setProgramParameters("prg");
      javaParameters.setVMParameters("vm");
      javaParameters.setWorkingDirectory("dir");
      assertTrue(configurable.isModified());
      configurable.apply();
      assertEquals("prg", configuration.getProgramParameters());
      assertEquals("vm", configuration.getVMParameters());
      assertEquals("dir", configuration.getWorkingDirectory());
    } finally {
      Disposer.dispose(editor);
    }
  }
Ejemplo n.º 21
0
 public void reset() {
   for (Configurable configurable : myConfigurables) {
     configurable.reset();
   }
   selectCompiler(myCompilerConfiguration.getDefaultCompiler());
 }
 public void apply() throws ConfigurationException {
   myConfigurable.apply();
 }
Ejemplo n.º 23
0
 public void apply() throws ConfigurationException {
   for (Configurable configurable : myConfigurables) {
     configurable.apply();
   }
   myCompilerConfiguration.setDefaultCompiler(mySelectedCompiler);
 }
 private void addComponent(AbstractVcs vcs, Configurable configurable, String constraint) {
   myEnvToConfMap.put(vcs, configurable);
   myMainPanel.add(configurable.createComponent(), constraint);
   configurable.reset();
 }
 public boolean isModified() {
   return myConfigurable.isModified();
 }
Ejemplo n.º 26
0
 @Override
 @Nullable
 @NonNls
 public String getHelpTopic() {
   return mySelectedConfigurable != null ? mySelectedConfigurable.getHelpTopic() : "";
 }
 public void reset() {
   myConfigurable.reset();
 }
Ejemplo n.º 28
0
  @Override
  public ActionCallback navigateTo(@Nullable final Place place, final boolean requestFocus) {
    final Configurable toSelect = (Configurable) place.getPath(CATEGORY);

    JComponent detailsContent = myDetails.getTargetComponent();

    if (mySelectedConfigurable != toSelect) {
      if (mySelectedConfigurable instanceof BaseStructureConfigurable) {
        ((BaseStructureConfigurable) mySelectedConfigurable).onStructureUnselected();
      }
      saveSideProportion();
      removeSelected();

      if (toSelect != null) {
        detailsContent = toSelect.createComponent();
        myDetails.setContent(detailsContent);
      }

      mySelectedConfigurable = toSelect;
      if (mySelectedConfigurable != null) {
        myUiState.lastEditedConfigurable = mySelectedConfigurable.getDisplayName();
      }

      if (toSelect instanceof MasterDetailsComponent) {
        final MasterDetailsComponent masterDetails = (MasterDetailsComponent) toSelect;
        if (myUiState.sideProportion > 0) {
          masterDetails.getSplitter().setProportion(myUiState.sideProportion);
        }
        masterDetails.setHistory(myHistory);
      }

      if (toSelect instanceof DetailsComponent.Facade) {
        ((DetailsComponent.Facade) toSelect)
            .getDetailsComponent()
            .setBannerMinHeight(myToolbarComponent.getPreferredSize().height);
      }

      if (toSelect instanceof BaseStructureConfigurable) {
        ((BaseStructureConfigurable) toSelect).onStructureSelected();
      }
    }

    if (detailsContent != null) {
      JComponent toFocus = IdeFocusTraversalPolicy.getPreferredFocusedComponent(detailsContent);
      if (toFocus == null) {
        toFocus = detailsContent;
      }
      if (requestFocus) {
        myToFocus = toFocus;
        UIUtil.requestFocus(toFocus);
      }
    }

    final ActionCallback result = new ActionCallback();
    Place.goFurther(toSelect, place, requestFocus).notifyWhenDone(result);

    myDetails.revalidate();
    myDetails.repaint();

    if (toSelect != null) {
      mySidePanel.select(createPlaceFor(toSelect));
    }

    if (!myHistory.isNavigatingNow() && mySelectedConfigurable != null) {
      myHistory.pushQueryPlace();
    }

    return result;
  }
 public JComponent createComponent() {
   return myConfigurable.createComponent();
 }
 public void disposeUIResources() {
   myConfigurable.disposeUIResources();
 }