Possible to get the Custom colors of a model ?

Started by rchevallier, October 12, 2022, 16:12:48 PM

Previous topic - Next topic

rchevallier

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

Phil Beauvoir

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.
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

Phil Beauvoir

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);
}
If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

rchevallier

#3
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

Phil Beauvoir

#4
// 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);
}

If you value and use Archi, please consider making a donation!
Ask your ArchiMate related questions to the ArchiMate Community's Discussion Board.

rchevallier


rchevallier

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