Skip to main content

Posts

Showing posts from 2017

Arrays.asList() throws java.lang.UnsupportedOperationException

Arrays.asList() throws java.lang.UnsupportedOperationException You might get the UnsupportedException when you tries to use the add() method in the List. If your code looks something similar to this : String[] data = new String[] {"hari","krushna"}; List<String> asList = Arrays.asList(data); asList.add("test"); Then you will see the following exception : java.lang.UnsupportedOperationException at java.util.AbstractList.add(Unknown Source) at java.util.AbstractList.add(Unknown Source) at ArrayConvert.trial(ArrayConvert.java:14) at ArrayConvert.main(ArrayConvert.java:8) Solution of the above problem is :  you need to create an ArrayList or LinkedList and add the objects to the newly created Array/LinkedList: String[] data = new String[] {"","",""}; List<String> asList = Arrays.asList(data); List<String> newList = new LinkedList<>(asList); newList.add("test"); Rea

Command Parameter RCP (Eclipse RCP)

Command Parameter RCP (Eclipse RCP) Open MANIFEST.MF file and right click on the Command and select "commandParameter" from "New". After creating "commandParameter", enter the details, like "id", "name" and make optional as "false". After adding the parameter in the command, in View (or Editor) at the time of calling the command set the parameter. Refer the following code to set the parameter at the time of execution. Code in View (or Editor): 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 ICommandService commandService = ( ICommandService ) getSite (). getService ( ICommandService . class ); IHandlerService handlerService = ( IHandlerService ) getSite (). getService ( IHandlerService . class ); // Enter the ID of the Command as the argument to getCommand() method in next line. Command sysoComm = commandService . getCommand ( "Re

Execute Command from View/Editor in Eclipse RCP

Execute Command from View/Editor in Eclipse RCP All Commands will be registered to IHandlerService. If we get the IHandlerService instance then we can call the desired command and then execute it. // Get the Instance of IHandlerService from View // Alternate way of getting site object is this also: // PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActivePart().getSite() // But we prefer  following so we get the appropriate IWorkbenchPartSite object. IHandlerService service = (IHandlerService) getSite().getService(IHandlerService.class);  try { service.executeCommand("ResumeParser.commands.sampleCommand", null);  } catch (ExecutionException e1) {  e1.printStackTrace();  } catch (NotDefinedException e1) {  e1.printStackTrace();  } catch (NotEnabledException e1) {  e1.printStackTrace();  } catch (NotHandledException e1) {  e1.printStackTrace();  }

Fie Dialog and Folder Dialog in Eclipse RCP

Fie Dialog and Folder Dialog in Eclipse RCP File Dialog in Eclipse: - This will only allow you to select the files in the Dialog Box FileDialog fileDialog = new FileDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); // Following line is Optional if you want to, enable filter for specific files. //fileDialog.setFilterExtensions(new String[] {"*.txt","*.csv"}); String filePath = fileDialog.open(); System.out.println(filePath); Folder Dialog in Eclipse: - This will allow you to select the folder in the Dialog box. DirectoryDialog directoryDialog = new DirectoryDialog(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); // Optional - if you want to open specific path //directoryDialog.setFilterPath("/home/hv185014/junk/"); String directoryPath = directoryDialog.open(); System.out.println(directoryPath);

Builder Design Pattern - Java

Builder Design Pattern - Java When the construction of the class contains a large number of argument then this Design Pattern is preferred. Builder Pattern, as the name suggest, it helps to reduce the complexity in Building Java Object. public class Person { private String firstname; private String lastname; private String address; private int age; private String city; private String state; public Person(String firstname, String lastname, String address, int age, String city, String state) { super(); this.firstname = firstname; this.lastname = lastname; this.address = address; this.age = age; this.city = city; this.state = state; } } In the above example, you can see, that the construction of the Person class has 6 arguments and few of them can be optional. So we can create a new PersonBuilder class which will help to create the Object of the Person class. public class PersonBuilder { private String firstname;