Skip to content

Commit

Permalink
FORGE-2250: Support getNote()
Browse files Browse the repository at this point in the history
  • Loading branch information
gastaldi committed Jun 8, 2015
1 parent 51a938d commit fc55ba4
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public void actionPerformed(ActionEvent e)
});

container.add(checkbox, "skip");
addNoteLabel(container, checkbox).setText(input.getNote());
}

@Override
Expand All @@ -69,6 +70,7 @@ public void updateState()
{
reloadValue();
}
updateNote(checkbox, input.getNote());
}

private void reloadValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void documentChanged(DocumentEvent event)
});

container.add(component);
addNoteLabel(container, component).setText(input.getNote());
}

@Override
Expand All @@ -87,6 +88,7 @@ public void updateState()
{
inputField.setVariants(getCompletions());
}
updateNote(component, input.getNote());
}

private void reloadValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public void itemStateChanged(ItemEvent e)
}
}
});
addNoteLabel(container, combo).setText(input.getNote());

}

@Override
Expand All @@ -74,6 +76,7 @@ public void updateState()
{
reloadValue();
}
updateNote(combo, input.getNote());
}

private void reloadValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,29 @@
*/
package org.jboss.forge.plugin.idea.ui.component;

import java.awt.Container;
import java.awt.*;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

import com.intellij.ui.components.JBLabel;
import com.intellij.util.ui.UIUtil;
import org.jboss.forge.addon.convert.ConverterFactory;
import org.jboss.forge.addon.ui.output.UIMessage;
import org.jboss.forge.furnace.util.Strings;
import org.jboss.forge.plugin.idea.service.ForgeService;
import org.jboss.forge.plugin.idea.ui.listeners.ValueChangeListener;

import javax.swing.*;

/**
* Represents Forge input component.
*
* @author Adam Wyłuda
*/
public abstract class ForgeComponent
{
private static final String NOTE_CLIENT_PROPERTY_KEY = "forge.note";

protected ValueChangeListener valueChangeListener;

protected ConverterFactory converterFactory = ForgeService.getInstance().getConverterFactory();
Expand Down Expand Up @@ -56,4 +65,29 @@ public void setValueChangeListener(ValueChangeListener valueChangeListener)
}

public abstract void updateState();

protected JLabel addNoteLabel(Container parent, JComponent component) {
final JBLabel noteLabel = new JBLabel(UIUtil.ComponentStyle.SMALL);
// Hide empty labels
noteLabel.addPropertyChangeListener("text", new PropertyChangeListener()
{
@Override
public void propertyChange(PropertyChangeEvent evt)
{
noteLabel.setVisible(!Strings.isNullOrEmpty(noteLabel.getText()));
}
});
noteLabel.setAnchor(component);
parent.add(noteLabel,"skip 1,hidemode 2");
component.putClientProperty(NOTE_CLIENT_PROPERTY_KEY, noteLabel);
return noteLabel;
}

protected void updateNote(JComponent component, String note) {
JLabel noteLabel = (JLabel) component.getClientProperty(NOTE_CLIENT_PROPERTY_KEY);
if (noteLabel != null) {
noteLabel.setText(note);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public void changedUpdate(DocumentEvent e)
});

container.add(component);
addNoteLabel(container, component).setText(input.getNote());
}

@Override
Expand All @@ -87,6 +88,7 @@ public void updateState()
{
reloadValue();
}
updateNote(component, input.getNote());
}

private void reloadValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public void buildUI(Container container)
{
radioContainer = new JPanel(new MigLayout("left"));
container.add(radioContainer);
addNoteLabel(container, radioContainer).setText(input.getNote());
}

@Override
Expand All @@ -62,6 +63,7 @@ else if (!getValue().equals(getInputValue()))
{
reloadValue();
}
updateNote(radioContainer, input.getNote());
}

private void reloadChoices()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void stateChanged(ChangeEvent e)
selectedItem, valueChangeListener));
}
});
addNoteLabel(container, spinner).setText(input.getNote());
}

@Override
Expand All @@ -73,6 +74,7 @@ public void updateState()
{
reloadValue();
}
updateNote(spinner, input.getNote());
}

private void reloadValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public void documentChanged(DocumentEvent event)
});

container.add(component);
addNoteLabel(container, component).setText(input.getNote());
}

@Override
Expand Down Expand Up @@ -101,6 +102,7 @@ public void updateState()
{
component.setVariants(getCompletions());
}
updateNote(component, input.getNote());
}

private void reloadValue()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public void checkBoxSelectionChanged(int index, boolean value)
});

container.add(panel, "span 2,growx");
addNoteLabel(container, checkBoxList).setText(input.getNote());
}

@Override
Expand All @@ -85,6 +86,7 @@ public void updateState()
{
reloadValues();
}
updateNote(checkBoxList, input.getNote());
}

private void reloadValues()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public void buildUI(Container container)

panel = new ListPanel(label, initialValue);
container.add(panel, "span 2,growx");
addNoteLabel(container, panel).setText(input.getNote());

}

@Override
Expand All @@ -73,6 +75,7 @@ public void updateState()
{
reloadValues();
}
updateNote(panel, input.getNote());
}

protected abstract String editSelectedItem(String item);
Expand Down

0 comments on commit fc55ba4

Please sign in to comment.