use of org.eclipse.che.ide.extension.machine.client.perspective.widgets.recipe.entry.RecipeWidget in project che by eclipse.
the class NameGenerator method generateCopy.
/**
* @return recipe name which consists of string 'Copy of ' and existing name with a current date. If there is an existing name,
* add a number suffix like "Copy2 of", "Copy3 of", etc.
*/
@NotNull
public static String generateCopy(@NotNull String name, @NotNull Set<RecipeWidget> recipeWidgets) {
List<String> existingNames = new ArrayList<>();
for (RecipeWidget recipe : recipeWidgets) {
existingNames.add(recipe.getDescriptor().getName());
}
name = removeCopyPrefix(name);
name = name.replace("+", "");
String copyName = "Copy of ".concat(name);
boolean alreadyExists = existingNames.contains(copyName);
int index = 2;
while (alreadyExists) {
copyName = "Copy".concat(String.valueOf(index)).concat(" of ").concat(name);
alreadyExists = existingNames.contains(copyName);
index++;
}
return copyName;
}
use of org.eclipse.che.ide.extension.machine.client.perspective.widgets.recipe.entry.RecipeWidget in project che by eclipse.
the class RecipePartPresenter method addRecipe.
/**
* Adds new recipe to list.
*
* @param recipeDescriptor
* a descriptor of new recipe
*/
@NotNull
private RecipeWidget addRecipe(@NotNull RecipeDescriptor recipeDescriptor) {
RecipeWidget recipe = new RecipeWidget(recipeDescriptor, resources);
recipe.setDelegate(this);
view.addRecipe(recipe);
recipesContainerPresenter.addRecipePanel(recipe);
recipes.put(recipe, recipeDescriptor);
return recipe;
}
use of org.eclipse.che.ide.extension.machine.client.perspective.widgets.recipe.entry.RecipeWidget in project che by eclipse.
the class RecipePartPresenter method selectRecipe.
/** {@inheritDoc} */
@Override
public void selectRecipe() {
LinkedList<RecipeWidget> list = new LinkedList<>(recipes.keySet());
if (list.isEmpty() || (selectedRecipe != null && selectedRecipe.equals(list.getFirst()))) {
return;
}
for (RecipeWidget recipe : recipes.keySet()) {
recipe.unSelect();
}
selectedRecipe = list.getFirst();
selectedRecipe.select();
}
use of org.eclipse.che.ide.extension.machine.client.perspective.widgets.recipe.entry.RecipeWidget in project che by eclipse.
the class NameGeneratorTest method generateCustomRecipeName3.
@Test
public void generateCustomRecipeName3() throws Exception {
String newName = "RECIPE-11";
RecipeWidget environment3 = mock(RecipeWidget.class);
RecipeWidget environment4 = mock(RecipeWidget.class);
RecipeWidget environment5 = mock(RecipeWidget.class);
RecipeWidget environment6 = mock(RecipeWidget.class);
RecipeWidget environment7 = mock(RecipeWidget.class);
RecipeWidget environment8 = mock(RecipeWidget.class);
RecipeWidget environment9 = mock(RecipeWidget.class);
RecipeWidget environment10 = mock(RecipeWidget.class);
RecipeDescriptor recipeDescriptor3 = mock(RecipeDescriptor.class);
RecipeDescriptor recipeDescriptor4 = mock(RecipeDescriptor.class);
RecipeDescriptor recipeDescriptor5 = mock(RecipeDescriptor.class);
RecipeDescriptor recipeDescriptor6 = mock(RecipeDescriptor.class);
RecipeDescriptor recipeDescriptor7 = mock(RecipeDescriptor.class);
RecipeDescriptor recipeDescriptor8 = mock(RecipeDescriptor.class);
RecipeDescriptor recipeDescriptor9 = mock(RecipeDescriptor.class);
RecipeDescriptor recipeDescriptor10 = mock(RecipeDescriptor.class);
when(recipe1.getDescriptor()).thenReturn(recipeDescriptor1);
when(recipe2.getDescriptor()).thenReturn(recipeDescriptor2);
when(environment3.getDescriptor()).thenReturn(recipeDescriptor3);
when(environment4.getDescriptor()).thenReturn(recipeDescriptor4);
when(environment5.getDescriptor()).thenReturn(recipeDescriptor5);
when(environment6.getDescriptor()).thenReturn(recipeDescriptor6);
when(environment7.getDescriptor()).thenReturn(recipeDescriptor7);
when(environment8.getDescriptor()).thenReturn(recipeDescriptor8);
when(environment9.getDescriptor()).thenReturn(recipeDescriptor9);
when(environment10.getDescriptor()).thenReturn(recipeDescriptor10);
when(recipeDescriptor1.getName()).thenReturn("RECIPE-1");
when(recipeDescriptor2.getName()).thenReturn("RECIPE-2");
when(recipeDescriptor3.getName()).thenReturn("RECIPE-3");
when(recipeDescriptor4.getName()).thenReturn("RECIPE-4");
when(recipeDescriptor5.getName()).thenReturn("RECIPE-5");
when(recipeDescriptor6.getName()).thenReturn("RECIPE-6");
when(recipeDescriptor7.getName()).thenReturn("RECIPE-7");
when(recipeDescriptor8.getName()).thenReturn("RECIPE-8");
when(recipeDescriptor9.getName()).thenReturn("RECIPE-9");
when(recipeDescriptor10.getName()).thenReturn("RECIPE-10");
HashSet<RecipeWidget> recipes = new HashSet<>(Arrays.asList(recipe1, recipe2, environment3, environment4, environment5, environment6, environment7, environment8, environment9, environment10));
String generated = NameGenerator.generateCustomRecipeName(recipes);
assertEquals(newName, generated);
}
use of org.eclipse.che.ide.extension.machine.client.perspective.widgets.recipe.entry.RecipeWidget in project che by eclipse.
the class RecipePartPresenter method onRecipeClicked.
/** {@inheritDoc} */
@Override
public void onRecipeClicked(@NotNull RecipeWidget recipeWidget) {
if (selectedRecipe != null && selectedRecipe.equals(recipeWidget)) {
return;
}
for (RecipeWidget recipe : recipes.keySet()) {
recipe.unSelect();
}
selectedRecipe = recipeWidget;
selectedRecipe.select();
recipesContainerPresenter.showEditorPanel(selectedRecipe);
RecipeEditorPanel recipePanel = recipesContainerPresenter.getEditorPanel(selectedRecipe);
recipePanel.setDelegate(this);
}
Aggregations