/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2014-2014 AS3Boyan
* Copyright 2014-2014 Elias Ku
*
* 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 com.intellij.plugins.haxe.runner.debugger.hxcpp.ui;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.options.ConfigurationException;
import com.intellij.openapi.options.SettingsEditor;
import com.intellij.openapi.project.Project;
import com.intellij.plugins.haxe.ide.module.HaxeModuleType;
import com.intellij.plugins.haxe.runner.debugger.hxcpp.HXCPPRemoteDebugConfiguration;
import com.intellij.ui.ListCellRendererWrapper;
import org.jetbrains.annotations.NotNull;
import javax.swing.*;
/**
* @author: Fedor.Korotkov
*/
public class HXCPPRunConfigurationEditorForm extends SettingsEditor<HXCPPRemoteDebugConfiguration> {
private JComboBox myComboModules;
private JPanel component;
private JTextArea myCreatesDebugServerThatTextArea;
private final Project project;
public HXCPPRunConfigurationEditorForm(Project project) {
this.project = project;
}
@Override
protected void resetEditorFrom(HXCPPRemoteDebugConfiguration configuration) {
myComboModules.removeAllItems();
final Module[] modules = ModuleManager.getInstance(configuration.getProject()).getModules();
for (final Module module : modules) {
if (ModuleType.get(module) == HaxeModuleType.getInstance()) {
myComboModules.addItem(module);
}
}
myComboModules.setSelectedItem(configuration.getConfigurationModule().getModule());
myComboModules.setRenderer(new ListCellRendererWrapper() {
@Override
public void customize(JList list, Object value, int index, boolean selected, boolean hasFocus) {
if (value instanceof Module) {
final Module module = (Module)value;
setText(module.getName());
}
}
});
}
@Override
protected void applyEditorTo(HXCPPRemoteDebugConfiguration configuration) throws ConfigurationException {
configuration.setModule(getSelectedModule());
}
private Module getSelectedModule() {
return (Module)myComboModules.getSelectedItem();
}
@NotNull
@Override
protected JComponent createEditor() {
return component;
}
@Override
protected void disposeEditor() {
component.setVisible(false);
}
}