-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement File, Directory, Java Class, Package component builders
- Loading branch information
1 parent
68c365e
commit f683ffd
Showing
10 changed files
with
367 additions
and
90 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
...in/java/org/jboss/forge/plugin/idea/ui/component/AbstractFileChooserComponentBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright 2014 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.jboss.forge.plugin.idea.ui.component; | ||
|
||
import com.intellij.openapi.ui.TextFieldWithBrowseButton; | ||
import org.jboss.forge.addon.convert.Converter; | ||
import org.jboss.forge.addon.convert.ConverterFactory; | ||
import org.jboss.forge.addon.ui.input.InputComponent; | ||
import org.jboss.forge.addon.ui.input.UIInput; | ||
import org.jboss.forge.addon.ui.util.InputComponents; | ||
import org.jboss.forge.plugin.idea.service.ServiceHelper; | ||
|
||
import javax.swing.*; | ||
import javax.swing.event.DocumentEvent; | ||
import javax.swing.event.DocumentListener; | ||
import java.awt.*; | ||
|
||
/** | ||
* @author Adam Wyłuda | ||
*/ | ||
public abstract class AbstractFileChooserComponentBuilder extends ComponentBuilder | ||
{ | ||
@Override | ||
public ForgeComponent build(final InputComponent<?, Object> input) | ||
{ | ||
return new LabeledComponent(input, new ForgeComponent() | ||
{ | ||
@Override | ||
public void buildUI(Container container) | ||
{ | ||
|
||
final TextFieldWithBrowseButton fileField = createTextField(); | ||
|
||
// Set Default Value | ||
final ConverterFactory converterFactory = ServiceHelper.getForgeService() | ||
.getConverterFactory(); | ||
Converter<Object, String> converter = converterFactory.getConverter( | ||
input.getValueType(), String.class); | ||
String value = converter.convert(InputComponents.getValueFor(input)); | ||
fileField.setText(value == null ? "" : value); | ||
|
||
final JTextField textField = fileField.getTextField(); | ||
textField.getDocument().addDocumentListener(new DocumentListener() | ||
{ | ||
@Override | ||
public void removeUpdate(DocumentEvent e) | ||
{ | ||
InputComponents.setValueFor(converterFactory, input, | ||
textField.getText()); | ||
valueChangeListener.run(); | ||
} | ||
|
||
@Override | ||
public void insertUpdate(DocumentEvent e) | ||
{ | ||
InputComponents.setValueFor(converterFactory, input, | ||
textField.getText()); | ||
valueChangeListener.run(); | ||
} | ||
|
||
@Override | ||
public void changedUpdate(DocumentEvent e) | ||
{ | ||
InputComponents.setValueFor(converterFactory, input, | ||
textField.getText()); | ||
valueChangeListener.run(); | ||
} | ||
}); | ||
|
||
container.add(fileField); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
protected Class<?>[] getSupportedInputComponentTypes() | ||
{ | ||
return new Class<?>[]{UIInput.class}; | ||
} | ||
|
||
protected abstract TextFieldWithBrowseButton createTextField(); | ||
} |
73 changes: 73 additions & 0 deletions
73
...in/java/org/jboss/forge/plugin/idea/ui/component/AbstractJavaChooserComponentBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Copyright 2014 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.jboss.forge.plugin.idea.ui.component; | ||
|
||
import com.intellij.openapi.editor.event.DocumentEvent; | ||
import com.intellij.openapi.editor.event.DocumentListener; | ||
import com.intellij.ui.EditorTextFieldWithBrowseButton; | ||
import org.jboss.forge.addon.convert.Converter; | ||
import org.jboss.forge.addon.convert.ConverterFactory; | ||
import org.jboss.forge.addon.ui.input.InputComponent; | ||
import org.jboss.forge.addon.ui.input.UIInput; | ||
import org.jboss.forge.addon.ui.util.InputComponents; | ||
import org.jboss.forge.plugin.idea.service.ServiceHelper; | ||
|
||
import java.awt.*; | ||
|
||
/** | ||
* @author Adam Wyłuda | ||
*/ | ||
public abstract class AbstractJavaChooserComponentBuilder extends ComponentBuilder | ||
{ | ||
@Override | ||
public ForgeComponent build(final InputComponent<?, Object> input) | ||
{ | ||
return new LabeledComponent(input, new ForgeComponent() | ||
{ | ||
@Override | ||
public void buildUI(Container container) | ||
{ | ||
final EditorTextFieldWithBrowseButton fileField = createEditorField(); | ||
|
||
// Set Default Value | ||
final ConverterFactory converterFactory = ServiceHelper.getForgeService() | ||
.getConverterFactory(); | ||
Converter<Object, String> converter = converterFactory.getConverter( | ||
input.getValueType(), String.class); | ||
String value = converter.convert(InputComponents.getValueFor(input)); | ||
fileField.setText(value == null ? "" : value); | ||
fileField.setButtonEnabled(true); | ||
|
||
fileField.getChildComponent().addDocumentListener(new DocumentListener() | ||
{ | ||
@Override | ||
public void beforeDocumentChange(DocumentEvent event) | ||
{ | ||
} | ||
|
||
@Override | ||
public void documentChanged(DocumentEvent event) | ||
{ | ||
InputComponents.setValueFor(converterFactory, input, | ||
fileField.getText()); | ||
valueChangeListener.run(); | ||
} | ||
}); | ||
|
||
container.add(fileField); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
protected Class<?>[] getSupportedInputComponentTypes() | ||
{ | ||
return new Class<?>[]{UIInput.class}; | ||
} | ||
|
||
protected abstract EditorTextFieldWithBrowseButton createEditorField(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
src/main/java/org/jboss/forge/plugin/idea/ui/component/DirectoryChooserComponentBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2014 Red Hat, Inc. and/or its affiliates. | ||
* | ||
* Licensed under the Eclipse Public License version 1.0, available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.jboss.forge.plugin.idea.ui.component; | ||
|
||
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory; | ||
import com.intellij.openapi.ui.TextFieldWithBrowseButton; | ||
import org.jboss.forge.addon.ui.hints.InputType; | ||
import org.jboss.forge.plugin.idea.util.IDEUtil; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* @author Adam Wyłuda | ||
*/ | ||
public class DirectoryChooserComponentBuilder extends AbstractFileChooserComponentBuilder | ||
{ | ||
@Override | ||
protected TextFieldWithBrowseButton createTextField() | ||
{ | ||
TextFieldWithBrowseButton textField = new TextFieldWithBrowseButton(); | ||
textField.addBrowseFolderListener("Select a directory", null, IDEUtil.projectFromContext(context), | ||
FileChooserDescriptorFactory.createSingleLocalFileDescriptor()); | ||
return textField; | ||
} | ||
|
||
@Override | ||
protected Class<?> getProducedType() | ||
{ | ||
return File.class; | ||
} | ||
|
||
@Override | ||
protected String getSupportedInputType() | ||
{ | ||
return InputType.DIRECTORY_PICKER; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.