Hi all,
Is there a way to access from jarchi (thru Java objects) the custom colors defined in the application. The idea is when using the SWT ColorDialog in a jArchi script, to display it with the same custom color palette.
Thanks
Sorry, not really. jArchi doesn't access Archi's preferences store. There may be a way to do it through loading the Java Eclipse classes of Archi's main bundle, but I haven't checked whether that's possible.
I figured out how to get the user defined colors of elements in Archi's preferences. If a user color is not set, the value is an empty string:
// Get the Archi bundle
const ArchiPlugin = Java.type("com.archimatetool.editor.ArchiPlugin");
// Get Archi's Preferences
const Preferences = ArchiPlugin.PREFERENCES;
// Get ArchimateModelUtils
const ArchimateModelUtils = Java.type("com.archimatetool.model.util.ArchimateModelUtils");
// For each element class get the user defined color (empty string if not set)
for(const element of ArchimateModelUtils.getAllArchimateClasses()) {
const elementName = element.getName();
const hexColorValue = Preferences.getString("defaultFillColour_" + elementName);
console.log(elementName + ": " + hexColorValue);
}
Thanks
It seems I was not clear enough for my demand: I was looking at the user custom color of the standard color chooser. Sorry about that
Ex: in Windows as attachment
My understanding they are saved by archi
// Get the Archi bundle
const ArchiPlugin = Java.type("com.archimatetool.editor.ArchiPlugin");
// Get Archi's Preferences
const Preferences = ArchiPlugin.PREFERENCES;
const colorPaletteSize = 16; // 16 on Windows
for (let index = 0; index < colorPaletteSize; index++) {
const hexColorValue = Preferences.getString("colorChooser_" + index);
console.log(hexColorValue);
}
Thanks. Have a nice weekend
Just thinking, it seems the code I need to write already exists in Java in archimateTool.
const CustomColorDialog = Java.type("com.archimatetool.editor.ui.components.CustomColorDialog");
const dlg = new CustomColorDialog(shell);
const color = dlg.open();
I understand the class is not part of the public interface of Archi, and so may change without notice, but it will avoid reimplementing the exact same code in JavaScript