How to add a simple tab in Intellij Idea plugin - intellij-idea

I am creating a simple class diagram plugin for Intellij Idea. I'm struggling now with creating a simple tab in IDE. This tab I will fill up with a prepared JPanel and nothing else.
I have already done the same in NetBeans and I would like to find something with similar behavior as TopComponent in NetBeans provides, but anything working would be cool.

So here is the answer:
create implementation of com.intellij.openapi.fileEditor.FileEditor. This is your actual tab
create implementation of com.intellij.openapi.fileEditor.FileEditorProvider
accept() defines type of files which your editor opens
create() should returns the proper instance of your editor
register your FileEditoProvider in plugin.xml
Editor:
public class YourEditor implements FileEditor {
private VirtualFile file;
public YourEditor(VirtualFile file) {
this.file = file;
}
#Override
public #NotNull JComponent getComponent() {
JPanel tabContent = new JPanel();
tabContent.add(new JButton("foo"));
return tabContent;
}
#Override
public #Nullable JComponent getPreferredFocusedComponent() {
return null;
}
#Override
public #Nls(capitalization = Nls.Capitalization.Title)
#NotNull String getName() {
return "name";
}
#Override
public void setState(#NotNull FileEditorState fileEditorState) {
}
#Override
public boolean isModified() {
return false;
}
#Override
public boolean isValid() {
return true;
}
#Override
public void addPropertyChangeListener(#NotNull PropertyChangeListener propertyChangeListener) {
}
#Override
public void removePropertyChangeListener(#NotNull PropertyChangeListener propertyChangeListener) {
}
#Override
public #Nullable FileEditorLocation getCurrentLocation() {
return null;
}
#Override
public void dispose() {
Disposer.dispose(this);
}
#Override
public <T> #Nullable T getUserData(#NotNull Key<T> key) {
return null;
}
#Override
public <T> void putUserData(#NotNull Key<T> key, #Nullable T t) {
}
#Override
public #Nullable VirtualFile getFile() {
return this.file;
}
}
Provider:
public class YourEditorProvider implements FileEditorProvider, DumbAware {
private static String EDITOR_TYPE_ID = "DiagramView";
#Override
public boolean accept(#NotNull Project project, #NotNull VirtualFile virtualFile) {
return true; //will accept all kind of files, must be specified
}
#Override
public #NotNull
FileEditor createEditor(#NotNull Project project, #NotNull VirtualFile virtualFile) {
return new YourEditor(virtualFile);
}
#Override
public #NotNull
#NonNls
String getEditorTypeId() {
return EDITOR_TYPE_ID;
}
#Override
public #NotNull
FileEditorPolicy getPolicy() {
return FileEditorPolicy.HIDE_DEFAULT_EDITOR;
}
}
and finally put FileEditorProvider extension in pluxin.xml:
<extensions defaultExtensionNs="com.intellij">
<fileEditorProvider implementation="classDiagramPainter.DiagramViewProvider"/>
</extensions>

Related

Access Activity from ViewManager in React Native

How are you? I have a some issues in my project.
Here is my code.
public class ViewManager extends ViewGroupManager<FrameLayout> {
public static final String REACT_CLASS = "RNNativeFlip";
public final int COMMAND_CREATE = 1;
private ReactApplicationContext context;
public ViewManager(ReactApplicationContext context) {
this.context = context;
}
#NonNull
#Override
public String getName() {
return REACT_CLASS;
}
#Override
protected FrameLayout createViewInstance(ThemedReactContext reactContext) {
return new FrameLayout(reactContext);
}
#Nullable
#Override
public Map<String, Integer> getCommandsMap() {
return MapBuilder.of("create", COMMAND_CREATE);
}
#Override
public void receiveCommand(
#NonNull FrameLayout root,
int commandId,
#Nullable ReadableArray args
) {
super.receiveCommand(root, commandId, args);
int reactNativeViewId = args.getInt(0);
int commandIdInt = commandId;
switch (commandIdInt) {
case COMMAND_CREATE:
createFragment(root, reactNativeViewId);
break;
default: {}
}
}
public void createFragment(FrameLayout root, int reactNativeViewId) {
final MainFragment myFragment = new MainFragment();
FragmentActivity activity;
activity = (FragmentActivity) this.context.getCurrentActivity();
activity.getSupportFragmentManager()
.beginTransaction()
.replace(reactNativeViewId, myFragment, String.valueOf(reactNativeViewId))
.commit();
}
}
No longer possible to access Activity from getCurrentActivity()
I know one method to use ReactContextBaseJavaModule but I don't know how to use this in ViewManger.
Please help me. Thank you

RxAndroid network calls makes the app lagging on back navigation

my android application keeps lagging on back navigation after i implemented the network calls.For network calls I'm using rxandroid/retrofit. I've tried to fix it using both single & observable. Both makes the app lagging the same way.This is my code while using observable. Lagging occurs while loading data to recyclerviews. So I have added the adapter class also.
#Override
public void onResume() {
super.onResume();
getMenuByShopAndCategoryId(categoryRequest.getId(), Utility.getShop(getActivity()));
}
private void getMenuByShopAndCategoryId(int categoryId, int shopId){
Repository.getInstance()
.getMenuByShopAndCategoryId(categoryId,shopId)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(new Observer<Response<MenuResponse>>() {
#Override
public void onSubscribe(Disposable d) {
disposable.add(d);
}
#Override
public void onNext(Response<MenuResponse> menuResponse) {
//other calculations
}
}
#Override
public void onError(Throwable e) {
//error handling
}
#Override
public void onComplete() {
}
});
}
#Override
public void onDestroy() {
disposable.dispose();
super.onDestroy();
}
public Observable<Response<MenuResponse>> getMenuByShopAndCategoryId(#NonNull int category_id, #NonNull int shop_id) {
return apiService.getMenuByShopAndCategoryId(category_id,shop_id);
}
public class MenuItemsAdapter extends RecyclerView.Adapter<MenuItemsAdapter.ViewHolder> {
private Context context;
private ArrayList<MenuResponse.MenuRequest> menuItemArrayList;
private ListRowMenuItemsBinding binding;
private MenuItemsAdapterHandler menuItemsAdapterHandler;
public MenuItemsAdapter(Context context, ArrayList<MenuResponse.MenuRequest> menuItemArrayList) {
this.context = context;
this.menuItemArrayList = menuItemArrayList;
}
#NonNull
#Override
public MenuItemsAdapter.ViewHolder onCreateViewHolder(#NonNull ViewGroup viewGroup, int i) {
binding = DataBindingUtil.inflate(LayoutInflater.from(context), R.layout.list_row_menu_items, viewGroup, false);
menuItemsAdapterHandler = new MenuItemsAdapterHandler(context);
binding.setHandler(menuItemsAdapterHandler);
configureLabels();
return new ViewHolder(binding);
}
#Override
public void onBindViewHolder(#NonNull MenuItemsAdapter.ViewHolder viewHolder, int i) {
viewHolder.binding.lblItemName.setText(menuItemArrayList.get(i).getMenuName());
viewHolder.binding.lblPrice.setText("MVR " + String.format("%.2f", Double.valueOf(menuItemArrayList.get(i).getSubTotal())));
if (menuItemArrayList.get(i).getAvailability().equals(Constants.AVAILABLE)){
binding.lblAvailability.set(context, HuqTypogrphyStyle.CAPS_BUTTON_GREEN);
viewHolder.binding.lblAvailability.setText("AVAILABLE");
} else {
binding.lblAvailability.set(context, HuqTypogrphyStyle.CAPS_BUTTON_RED);
viewHolder.binding.lblAvailability.setText("NOT AVAILABLE");
}
viewHolder.binding.setMenuItem(menuItemArrayList.get(i));
viewHolder.binding.executePendingBindings();
}
#Override
public int getItemCount() {
return menuItemArrayList.size();
}
#Override
public int getItemViewType(int position) {
return position;
}
public class ViewHolder extends RecyclerView.ViewHolder {
ListRowMenuItemsBinding binding;
public ViewHolder(#NonNull ListRowMenuItemsBinding listRowMenuItemsBinding) {
super(listRowMenuItemsBinding.getRoot());
this.binding = listRowMenuItemsBinding;
}
}
private void configureLabels() {
binding.lblItemName.set(context, HuqTypogrphyStyle.H2_HEADING);
binding.lblPrice.set(context, HuqTypogrphyStyle.BODY_GRAY);
binding.lblAvailability.set(context, HuqTypogrphyStyle.BODY_GRAY);
}
}
Try moving the api call from on Resume to onCreate.

paging library not showing anything in recyclerview

i'm trying to load bunch of list from room database, with paging library, but somehow that i don't really understand, the list never shown up
i add a repository class between dao and viewmodel, not sure if its the problem but, i configure Paged.list and pagedlistbuilder in there
i've also try to put some breakpoint in pagedListAdapter, but it never called
DAO
#Query("SELECT * FROM DictIndonesia")
public abstract DataSource.Factory<Integer, DictIndonesia> getAllPaged();
REPOSITORY
public class DictRepository {
PagedList.Config pagedListConfid;
.....
public DictRepository(Application application) {
db = DictIndoDatabase.getINSTANCE(application);
indDao = db.dictIdDao();
.....
pagedListConfid = (new PagedList.Config.Builder()
.setEnablePlaceholders(true)
.setPrefetchDistance(10)
.setPageSize(20).build());
}
......
public LiveData<PagedList<DictIndonesia>> getAllWordPaged() {
return new LivePagedListBuilder<>(
indDao.getAllPaged(), pagedListConfid).build();
}
viewmodel
public LiveData<PagedList<DictIndonesia>> getAllWordPaged() {
return dictRepository.getAllWordPaged();
}
ADAPTER
public class WordIndAdapterPaged extends PagedListAdapter<DictIndonesia,WordIndAdapterPaged.WordHolder> {
public WordIndAdapterPaged() {
super(diffcallBack);
}
#NonNull
#Override
public WordHolder onCreateViewHolder(#NonNull ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler, parent, false);
return new WordHolder(itemView);
}
#Override
public void onBindViewHolder(#NonNull WordHolder holder, int position) {
holder.bindTo(getItem(position));
}
private static final DiffUtil.ItemCallback<DictIndonesia> diffcallBack = new DiffUtil.ItemCallback<DictIndonesia>() {
#Override
public boolean areItemsTheSame(#NonNull DictIndonesia oldItem, #NonNull DictIndonesia newItem) {
return oldItem.getIdIndo() == newItem.getIdIndo();
}
#Override
public boolean areContentsTheSame(DictIndonesia oldItem, #NonNull DictIndonesia newItem) {
return oldItem == newItem;
}
};
public class WordHolder extends RecyclerView.ViewHolder {
...............
WordHolder(View view) {
super(view);
...............
}
void bindTo(DictIndonesia dictIndonesia) {
word.setText(Html.fromHtml(dictIndonesia.getWord()));
meaning.setText(Html.fromHtml(dictIndonesia.getMeaning()));
}
}
Fragment
public class Fdashboard extends Fragment {
#BindView(R.id.rv_global)
RecyclerView rvGlobal;
private Unbinder unbinder;
WordIndAdapterPaged wordIndAdapterPaged;
private WordViewModel wordViewModel;
public Fdashboard() { }
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_fdashboard, container, false);
unbinder = ButterKnife.bind(this, v);
wordViewModel = ViewModelProviders.of(getActivity()).get(WordViewModel.class);
wordIndAdapterPaged = new WordIndAdapterPaged();
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getActivity());
rvGlobal.setLayoutManager(layoutManager);
rvGlobal.setAdapter(wordIndAdapterPaged);
wordViewModel.getAllWordPaged().observe(this, dictIndonesias -> {
wordIndAdapterPaged.submitList(dictIndonesias); //i think the problem maybe around here
});
return v;
}

No converter found capable of converting from type [java.lang.String] to type [org.springframework.data.solr.core.geo.Point]

I am trying to use spring-data-solr in order to access to my Solr instance through my Spring boot application. I have the following bean class:
#SolrDocument(solrCoreName = "associations")
public class Association implements PlusimpleEntityI {
#Id
#Indexed
private String id;
#Indexed
private String name;
#Indexed
private Point location;
#Indexed
private String description;
#Indexed
private Set<String> tags;
#Indexed
private Set<String> topics;
#Indexed
private Set<String> professionals;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Point getLocation() {
return location;
}
public void setLocation(Point location) {
this.location = location;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public Set<String> getTags() {
return tags;
}
public void setTags(Set<String> tags) {
this.tags = tags;
}
public Set<String> getTopics() {
return topics;
}
public void setTopics(Set<String> topics) {
this.topics = topics;
}
public Set<String> getProfessionals() {
return professionals;
}
public void setProfessionals(Set<String> professionals) {
this.professionals = professionals;
}
}
I have implemented the following repository in order to access to the related information:
public interface AssociationsRepository extends SolrCrudRepository<Association, String> {
}
I have created a configuration class which looks like the following one:
#Configuration
#EnableSolrRepositories(basePackages = {"com.package.repositories"}, multicoreSupport = true)
public class SolrRepositoryConfig {
#Value("${solr.url}")
private String solrHost;
#Bean
public SolrConverter solrConverter() {
MappingSolrConverter solrConverter = new MappingSolrConverter(new SimpleSolrMappingContext());
solrConverter.setCustomConversions(new CustomConversions(null));
return solrConverter;
}
#Bean
public SolrClientFactory solrClientFactory () throws Exception {
return new MulticoreSolrClientFactory(solrClient());
}
#Bean
public SolrClient solrClient() throws Exception {
return new HttpSolrClient.Builder(solrHost).build();
}
#Bean
public SolrOperations associationsTemplate() throws Exception {
SolrTemplate solrTemplate = new SolrTemplate(solrClient());
solrTemplate.setSolrConverter(solrConverter());
return solrTemplate;
}
}
Unfortunately, when I try to read an association from my Solr instance I got the following error:
org.springframework.core.convert.ConverterNotFoundException: No converter found capable of converting from type [java.lang.String] to type [org.springframework.data.solr.core.geo.Point]
I don't understand why it is not able to find a converter if I have explicitly defined it in the solrTemplate() method.
This is my POM definition:
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>2.1.4.RELEASE</version>
</dependency>
Thank you for your help.
EDIT:
I've also tried with different BUILD-RELEASEs but they are highly unstable and I've found a lot of errors using them.
Alessandro, as you can see directly in the GeoConverters class on GitHub, the implemented converters are only for:
org.springframework.data.geo.Point
and not for:
org.springframework.data.solr.core.geo.Point
Simply use this class and you don't even need a custom converter for this. Spring Data for Solr will perform the conversion for you.
I'm using a slightly patched version of the 3.0.0 M4, but I'm pretty sure this solution should apply seamlessly also to your case.

Issue in editing in Tableviewer

I created a table-viewer with two columns in it.first column name is "Fristname" and second column name "lastname". I added editor support to both the columns but i able to do edit/select only in the first column. In my second column not able to do editing/selecting. Don't know why some one please help me? Following is the code snippet.
public class ViewPart1 extends ViewPart {
public ViewPart1() {
// TODO Auto-generated constructor stub
}
private ResourceManager resourceManager = new LocalResourceManager(
JFaceResources.getResources());
#Override
public void createPartControl(Composite parent) {
// re-use an existing image
final Image image = FieldDecorationRegistry.getDefault()
.getFieldDecoration(FieldDecorationRegistry.DEC_INFORMATION)
.getImage();
TableViewer tblView = new TableViewer(parent);
final Table table = tblView.getTable();
table.setHeaderVisible(true);
table.setLinesVisible(true);
TableViewerColumn fn = new TableViewerColumn(tblView, SWT.BORDER, 0);
fn.getColumn().setWidth(150);
fn.getColumn().setText("Firstname");
fn.setLabelProvider(new ColumnLabelProvider() {
#Override
public String getText(Object element) {
Person p = (Person) element;
return p.getFirstName();
}
#Override
public Image getImage(Object element) {
return image;
}
});
// fn.setEditingSupport(new EditColumn(tblView));
fn = new TableViewerColumn(tblView, SWT.BORDER, 1);
fn.getColumn().setWidth(150);
fn.getColumn().setText("Last name");
fn.setLabelProvider(new ColumnLabelProvider() {
#Override
public String getText(Object element) {
Person p = (Person) element;
return p.getLastNAme();
}
#Override
public Image getImage(Object element) {
return image;
}
});
// fn.setEditingSupport(new EditColumn(tblView));
tblView.setContentProvider(new QContentProvider());
ArrayList<Person> list = new ArrayList<Person>();
list.add(new Person("a", "b"));
list.add(new Person("C", "D"));
tblView.setInput(list);
tblView.refresh();
}
#Override
public void setFocus() {
// TODO Auto-generated method stub
}
}
Below EditColumn class Code
public class EditColumn extends EditingSupport {
private final TableViewer viewer;
private final CellEditor editor;
public EditColumn(TableViewer viewer) {
super(viewer);
this.viewer = viewer;
this.editor = new TextCellEditor(viewer.getTable());
}
#Override
protected boolean canEdit(Object element) {
System.out.println("can edit");
return true;
}
#Override
protected CellEditor getCellEditor(Object element) {
return editor;
}
#Override
protected Object getValue(Object element) {
// TODO Auto-generated method stub
return ((Person) element).getFirstName();
}
#Override
protected void setValue(Object element, Object value) {
((Person) element).setFirstName(String.valueOf(value));
viewer.update(element, null);
}
}
Your EditColumn class is always using the getFirstName and setFirstName methods of Person so although you can edit the last name column you are not using the correct values.
You need to use different EditingSupport classes for each column.